Authentication
A hosted agent has two access decisions: whether a visitor can open the app, and whether a request can use the runtime.
| Setting | What it controls |
|---|---|
hosted_auth_mode: "user_auth" | Team-only app access. Visitors sign in as members of the agent's organization. This is the default. |
hosted_auth_mode: "public" | Anyone can open the app. Chat, sessions, and stores still require runtime authentication. |
end_user_auth | End-user identity configuration. Hosted runtime support depends on the selected mode; see Identity settings. |
Set these fields in Settings > Auth or with PUT /api/agents/{agent_id}, which requires an admin automation token. They belong to the platform agent record, not amodal.json. Redeploy after changing the runtime identity configuration.
Hosted browser login
For a team-only app served at the agent's own origin, including a custom React app:
- Open the agent URL. The edge redirects an unauthenticated visitor to
/auth/login. - Sign in through the hosted login flow. The edge checks organization membership and sets an HttpOnly
__Host-amodal_sessioncookie. - Make same-origin runtime calls. The edge validates the cookie and adds the bearer header before forwarding the request.
Use window.location.origin as the SDK URL and omit getToken for this flow:
import { AmodalProvider, AmodalChat } from '@amodalai/react';
import '@amodalai/react/style.css';
<AmodalProvider runtimeUrl={window.location.origin}>
<AmodalChat />
</AmodalProvider>;The browser cannot read the HttpOnly cookie. /auth/session returns user identity, not a bearer token.
The edge redirects a page load without a valid session to /auth/login. It answers any other request, such as fetch, XHR, or EventSource, with 401 and this body:
{
"error": {
"code": "LOGIN_REQUIRED",
"message": "Sign in to continue.",
"login_url": "https://<agent-host>/auth/login?return_to=%2Freports"
}
}login_url returns to the page that sent the request, read from its Referer, or to / without one. A request without Sec-Fetch-Mode counts as a page load only when its Accept header includes text/html.
@amodalai/react follows login_url for its own same-origin requests. Code that calls fetch directly can use runtimeFetch from @amodalai/react in place of fetch, or check the response:
if (res.status === 401) {
const body = await res
.clone()
.json()
.catch(() => null);
if (body?.error?.code === 'LOGIN_REQUIRED') location.assign(body.error.login_url);
}API clients
CLI tools, CI jobs, and application servers send Authorization: Bearer <credential>:
| Credential | Purpose | How to create it |
|---|---|---|
| Short-lived runtime token | Expiring, agent-bound access for runtime calls. Can include scope_id and context claims. The platform API does not accept it. Without scope_id or role claims, the runtime treats its holder as an operator. The token names no user, even when a member mints it. | Call POST /api/agents/{agent_id}/tokens from your server, for example with an operator/admin pk_ token. |
ak_ agent API key | Persistent access for a service calling the runtime. A key works only while the person who created it can edit the agent, so removing that person or lowering their role disables their keys. Org admins can see and revoke every agent API key in the organization. | Create a key in the agent's API Keys settings. Keep it on your server. |
pk_ automation token | Platform operations such as configuring and deploying agents. | Create an organization automation token. Exchange it for a runtime token before calling chat. |
The edge accepts agent-bound platform runtime tokens and ak_ keys on team-only agents. You can run API smoke tests without opening the app to the public.
Keep persistent credentials out of browser code. A public app that offers chat needs a backend to authorize runtime access; setting public does not issue anonymous chat tokens.
Embedding in another product
For a multi-tenant product, proxy runtime calls through your backend and keep runtime credentials there. See Embedding & Multi-tenancy for the required checks.
For inbound MCP and A2A, Public with Anonymous identity lets external clients call the operations the owner publishes. Team-only with Anonymous identity requires a team session for the agent. Signed inbound callers use the selected hosted JWKS provider and a server-managed caller grant; their token audience is the canonical /mcp or /a2a URL. Downstream service credentials remain separate. See Hosted MCP and A2A access and the client walkthrough.
Identity settings
The Auth page stores one end-user identity configuration in end_user_auth:
| Type | Fields | Where it applies |
|---|---|---|
none | Optional synthesized user ID. | No end-user identity provider. |
jwks | Application client ID, and optional JWKS URL, issuer, and audience. | Hosted chat runtime and Platform API. The platform supplies the JWKS URL and issuer when they are blank. |
jwt_secret | Shared secret, HS256/HS384/HS512, optional issuer and audience. | Platform API only. The secret is used as saved; env: references are not resolved. |
oidc | Issuer URL and client ID. | Platform API only. Keys come from <issuer>/.well-known/jwks.json, and the client ID is the audience. |
header | Header name. | Platform API only. See below. |
custom | Module path. | Stored only. The Platform API rejects it. |
The OIDC form also shows client secret, callback URL, scopes, session secret, cookie, and TTL fields. They are stored but not used.
Hosted chat
The hosted chat runtime installs the jwks verifier when the client ID, issuer, JWKS URL, and audience are all known. The audience defaults to the client ID. The verifier checks issuer and audience, then checks agent membership. It replaces the platform JWT verifier for that runtime, so platform runtime tokens stop working there; ak_ keys still work.
With the JWKS URL and issuer blank, the platform's WorkOS signs the token and its sub is the member's WorkOS user ID. With any other issuer or JWKS URL, membership is checked by the token's email, the caller is identified as idp:<sub>, a scope_id claim pins idp:<scope_id>, and governed personal connections are unavailable.
With any other type, hosted chat uses the platform JWT verifier. Saving jwt_secret, oidc, header, or custom does not change how hosted chat authenticates.
On a team-only origin, the edge still requires its hosted session, an ak_ key, or an agent-bound platform runtime token. An external JWT does not bypass that gate.
Platform API
The Platform API accepts an end-user JWT only when the token has a sub claim and either an agent_id claim naming the agent or, for oidc, an iss matching the issuer configured on the agent in the request path (/api/agents/{agent_id}/...). A jwks token also needs the agent's audience, and its JWKS URL and issuer fall back to the platform's WorkOS, as on hosted chat. A token the platform signed is never an end-user JWT. When the platform's WorkOS signed the token, the end-user ID is its sub. For any other issuer, including every jwt_secret and oidc token, the end-user ID is idp:<sub>, the same ID hosted chat gives that caller. An end-user JWT can reach only session and secret routes. Session routes return only sessions the user owns. The secret list returns only that user's own secret names, and per-scope secret routes require the scope to equal the end-user ID.
header does not authenticate a request. On a request already authenticated for the agent, the Platform API reads the end-user ID from the configured header, or X-End-User-Id when the name is blank. Use it only behind a proxy that strips client-supplied copies of that header.