Who the run acts as
The API key decides whether the request body can name the user.
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 asAuthorization: Bearer. MCP connectors set to SSO user sign-in keep their own setting.
Set it up once:
- 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.
- Turn it on for the agent with Update Agent:
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_authis on for the agent. Without it,user_oidc_tokenis 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.
Sign-in link in the stream
Send onlyinput.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.
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
Senduser_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.
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.

