Stop Giving Your AI Agents API Keys

Kim Maida, Keycard, Mason Egger, Temporal52:36 · Nov 2026 · 3,670 views
Thumbnail for Stop Giving Your AI Agents API Keys Watch on YouTube
TL;DR
  1. 1

    Shared API keys hide both the agent's identity and the human identity behind an action, while giving the agent every permission attached to the key.

  2. 2

    OAuth token exchange creates short-lived, narrowly scoped credentials for each tool call and preserves the delegation chain from user to agent to downstream resource.

  3. 3

    Temporal can restart an agent after a worker failure from its recorded state without repeating LLM calls, while Keycard keeps credentials out of the event history.

Summary

Kim Maida demonstrates an expense desk agent that starts with shared API keys and no reliable record of who filed or approved an expense. She replaces that setup with OAuth token exchange. A user signs in and consents to a limited scope, then the agent exchanges the user's subject token for a token limited to one MCP tool call. The MCP server performs another exchange for the ledger API. The resulting audit trail records whether the agent acted as itself or on behalf of a named user. Mason Egger then puts the agent loop inside a Temporal workflow. Tool calls become activities that can retry, and the workflow records enough state to resume after a worker is killed. In his demonstration, the worker restarts without repeating earlier LLM calls or activities. The talk also covers two ways to keep credentials out of Temporal history: just-in-time injection through an interceptor and encryption through a payload encoder.

Key ideas
01:26

Shared API keys erase the identities and limits that agent access needs

Kim Maida begins with the common pattern of giving an agent an API key. The key does not identify the human user or the agent, and the agent receives every permission attached to it. The expense desk demonstration makes the problem concrete. A $75 expense is filed with activity recorded as created using an API key. Another expense is approved, but the system cannot show who approved it because the same kind of credential was used. Kim also rejects the idea that a human must approve every action. People make mistakes, and many agents run without constant human intervention.

01:59

Token exchange narrows delegated access before the agent starts calling tools

Keycard uses token exchange, an open standard that extends OAuth 2. The user first signs in through an authorization server and consents to a subset of their permissions, expressed as scopes. The resulting subject token identifies the user and their allowed access. During execution, policy evaluates the requested resource, the agent identity, the user identity, and the delegation chain. If the request fits policy, Keycard issues a token for the requested resource. Kim says these tokens usually expire within minutes and should never be stored.

03:10

Each hop in the agent loop gets a credential scoped to one tool call

The expense desk runtime sends a prompt to the model, receives a proposed tool call, and dispatches it through an MCP client to the Expense MCP server. The agent authenticates to Keycard with its own client credentials or workload identity, while also presenting the user's subject token when one exists. Keycard issues a token that can be used only at the MCP server and only for that particular call. The MCP server then exchanges that token for a second credential scoped to the ledger API. It discards the token after the call, and the API response travels back through the loop.

26:05

An agent can act as itself without claiming that a user performed the action

The first authenticated version of the expense desk signs in as the agent application. When Kim asks it to file a $75 expense on her behalf, the memo says it was filed on behalf of Kim because that is what she told the agent. The activity record still shows the agent as the actor, because no human user had authenticated. The Keycloak audit log records a client-credentials grant and identifies the agent application as the actor. The downstream ledger exchange preserves that chain, with the Expense MCP server acting on behalf of the agent application.

31:22

User delegation adds approval rules without impersonating the user

After Kim signs in as a human user, the agent can distinguish her identity from its own. A $30 office-supplies expense is filed under Kim's email, then approved by the expense desk agent because the agent can approve expenses under $49.99. A $75 expense remains pending because it exceeds that limit. When Kim asks the agent to approve her own expense, it refuses and says another reviewer must do it. Earlier, when every action used an API key, the system could not prevent a user from approving their own expense. The new records show who filed, approved, or rejected each expense.

38:09

The delegation chain can be followed across the agent and MCP server

Kim traces the two token exchanges in the Keycloak console. On the first hop, the agent application requests access to the Expense MCP resource while acting on behalf of the human user. On the second hop, the Expense MCP server requests access to the ledger API while still acting on behalf of that user. The exchanges share a session association, so the sequence can be followed across resources. This gives the audit log more information than a simple final actor name. It records which application made each request, whose permissions were delegated, and which downstream resource was accessed.

41:26

Temporal models the agent loop as a durable workflow with retryable activities

Mason Egger describes agents as distributed systems with an LLM involved in the loop. In Temporal, the agent loop becomes a workflow, and each tool call becomes an activity. Activities are expected to fail, so they can be retried and the workflow can rebuild its state. Temporal keeps execution state in its service while workers run the code. Mason shows a settlement workflow with activities for debiting a ledger and marking it settled, plus a timer that stands in for human approval time. The workflow code remains ordinary Python with Temporal-specific workflow and activity structure.

46:01

A restarted worker can resume without repeating completed model work

Mason starts a settlement workflow and then kills the worker while it is running. The worker process disappears, but the workflow state remains in Temporal. After the worker restarts, the application resumes from the recorded state. The debit activity is not run again, and the demonstration does not repeat earlier LLM calls. Temporal replays the prior actions and continues with the remaining work. Mason says this also applies when an LLM provider goes down, compute fails, or an AWS region becomes unavailable. The user can receive a continuing execution instead of losing the entire agent loop.

49:28

Credentials can stay out of Temporal history while activities still authenticate

The demonstration's Temporal event history contains activity results and workflow state, but no JWT token material. Mason explains that Keycard provides an interceptor that obtains credentials when an activity executes and injects them at that point, rather than writing them into history. Temporal also supports a payload encoder for encrypting data stored in the service. An encryption sidecar and policy can protect payloads in self-hosted or cloud deployments, with the customer controlling the keys. These approaches address different concerns: the interceptor avoids storing the credentials, while payload encoding protects data that does need to be persisted.

"It rebuilt the entire state of our agent from all of the previous responses. No LLM calls were redone. No previous activities or functions were re-executed."Mason Egger47:51
Who should watch
  • You are giving an agent a shared API key and need an audit trail that distinguishes the agent from the user it acts for.
  • Your agent calls several downstream tools and you need each call to carry limited, short-lived access rather than a reusable credential.
  • Your agent can spend substantial time waiting or making tool calls, and a worker failure would currently force you to rebuild state or repeat model calls.