Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
agent_api_keys
What it is
Part of agents: an agent's own Anthropic or OpenAI API key. An in-memory
agent on an Anthropic or OpenAI model can have one; while it fits, every turn
of the agent runs on it instead of Macro's allowance. See the crate doc in
src/lib.rs.
Start here
src/domain/service.rs: the policy — which agents take a key, the paid-plan check on save and on every turn, andAgentKeysfor the chat runtime.src/domain/models.rs:ModelProvider,ProviderApiKey(prefix rules),KeyedAgent(the agent a caller authorized).src/outbound/pg.rs:agent_api_keys, joined tobotsandagent_configsso a turn sees the agent as configured now.src/outbound/plans.rs:KeyPlansover ai_billing's entitlements.
Scope
- Owns:
agent_api_keys. - Not here: who may change an agent →
crates/bots(BotService); routing a turn's model calls on a key →crates/agent(AgentLoop::with_provider_api_key); deciding a turn runs on one →crates/agent_inmem.
Boundaries
- Depends on:
cursor_api_key(theKmsCiphertextsseam and its CMK),ai_billing(plans). - Used by:
authentication_service(save/remove routes, encrypts),agent_harness_service(decrypt-only, for turns).
Checks
cargo test -p agent_api_keys(SQLX_OFFLINEunset).
Gotchas
- Never cache a decrypted key or a plan answer across turns:
usable_keyis called per turn. - A key counts only while the agent is in-memory, its model's provider is the key's, and its owner's plan includes keys. Otherwise the agent runs on Macro usage and the key stays stored (shown and removable).
- Prefixes are enforced twice:
ProviderApiKey::parseand theagent_api_keys_key_prefixcheck. Change both together. - Bots are soft-deleted, so the
ON DELETE CASCADErarely fires;storedignores deleted agents. - Deleting a key does not revoke it at the provider.
Related
- Rules:
.agents/rules/rust/security.md,.agents/rules/rust/db.md