Skip to main content
One backend can call one agent for many end users. Each call says who the user is, and each MCP connector the agent uses gets that user’s own credential. This page covers the three ways to give the credential and the API key rules that decide who the run acts as.

Who the run acts as

The API key decides whether the request body can name the user.
Only the organization default key can name any user. Any other key runs as its owner: when input.user names someone else, the call fails with 403 run_user_not_allowed. A key limited to some agents is never the default key, so it always runs as its owner. To run one agent for many users, call it with the organization default key.
An agent with API callers name the end user turned on is the exception. On that agent, a key other than the default key may name an end user of your app in input.user. Send input.user.id as a stable id from your system. Per-user sign-ins are stored under this id, so the same id must come back on the next call for the same person. input.user.email is required when you send input.user.

Give each user’s credential to the MCP connectors

Pick one method per agent.

One token per request

Send one token with the request. xpander exchanges it at your identity provider (OIDC token exchange, RFC 8693) for a token with the MCP audience, and every MCP connector on the agent that uses the pre-auth token (on by default) gets that exchanged token as Authorization: Bearer. MCP connectors set to SSO user sign-in keep their own setting. Set it up once:
  1. In Platform > Organization > Access > Single sign-on, fill the Service app card and turn on Agent pre-authentication with your audiences and token exchange scopes. See Agent pre-authentication.
  2. Turn it on for the agent with Update Agent:
Then send the user’s access token on each call. Put it in Authorization: Bearer next to x-api-key, or in the body as user_oidc_token. Send it in one place. When both are present, they must carry the same token, or the call fails with 400 user_oidc_token_conflict.
  • The token is used only when use_oidc_pre_auth is on for the agent. Without it, user_oidc_token is ignored.
  • xpander exchanges the token at your identity provider; it does not forward the raw token. If the exchange fails, the call fails.
  • xpander does not check that the token belongs to input.user. Send the token of the same person you name.
  • Exchanged tokens are cached for about 50 minutes per token and audience.
Send only input.user with a stable id. When the agent first needs an OAuth MCP connector that this user has not signed in to, the stream sends an auth_event. Its data.type is login_required and data.data.url is the sign-in link. Show the link to the user. After the user signs in, the run goes on, and later calls for the same input.user.id use the stored sign-in with no link.
A run with no input.user.id cannot start a sign-in, and the agent reports that MCP connector as not available. After a sign-in, the stream sends a second auth_event with data.type token_ready.

A token per MCP connector

Send user_tokens: one entry per MCP connector, keyed by its id from GET /v1/agents/{agent_id}/tools (the items with type mcp). The value is a bearer token, or an object of headers to send as they are.
When the agent also has one token per request turned on, the exchanged token takes the place of these entries.

Credentials are not stored with the run

user_tokens and user_oidc_token stay with the live run only. They are removed from stored task history, exports and conversation views, so send them again on each call.

API keys limited to some agents

In Platform > Organization > Access > API keys, a key other than the default key can be limited to named agents. A call with that key to any other agent is refused. Such a key always runs as its owner (see Who the run acts as), so use it for calls that act as one person, not for many end users.