Skip to main content
xAIResponses runs Grok models on xAI’s Responses API with two credential modes: an API key (XAI_API_KEY), or a SuperGrok subscription sign-in through xAI’s device-code flow. This page covers the sign-in path.
SuperGrok sign-in works only on xAIResponses. The xAI chat class is unchanged and takes an API key only.
See all xAI models here.
  • We recommend setting id="grok-4.3" explicitly. The class default grok-4-1-fast-non-reasoning-latest is an alias xAI has retired and redirects to Grok 4.3.

Installation

SuperGrok sign-in needs openai>=1.106.0 — the first release whose client accepts a callable API key — and the agno[openai] extra pins it. It also needs the cryptography package, which is in no Agno extra: tokens are stored encrypted with Fernet. If cryptography is missing, nothing fails at construction, but the first successful login — and any later token refresh or load — raises ImportError, and the sign-in does not persist across restarts. The agno[sqlite] extra covers sqlalchemy for the examples’ SQLite token store.

Authentication

Set XAI_TOKEN_ENCRYPTION_KEY to a Fernet key. Generate one:
Token encryption is required by default. Without the key, a completed sign-in is kept in process memory but not saved — a restart signs you out, with a warning in the logs. XAITokenManager(encrypt_tokens=False) stores the token unencrypted and needs no key; use it for local development only.

Entitlement

The device-code flow requests the OAuth scopes openid profile email offline_access grok-cli:access api:access from auth.x.ai, then calls the same https://api.x.ai/v1 endpoints an API key would. Whether your SuperGrok subscription includes API access is decided by xAI, not by Agno — check your plan at x.ai. If it does not, the first request fails with a 403 that Agno rewrites as:
followed by xAI’s own error message.

Example

In a terminal, drive the device flow directly: show the URL and code, wait for the browser approval, and run the agent.
The model string "xai-responses:grok-4.3" resolves to the same class. The string form constructs the model with its id only, so attach the session afterwards: agent.model.token_manager = token_manager.

Signing In from Chat

For chatbots and web UIs, where a terminal device flow cannot run, the XAIAuth toolkit wraps the same manager as two agent tools: sign_in_with_supergrok hands back the approval link and code, and check_supergrok_login completes the login on a later turn. The in-flight login is stored in the database, so whichever replica handles the user’s next turn can finish it. AgentOS ships no sign-in route of its own — XAIAuth is the only sign-in path there. An agent cannot sign in to the model it is running on: reaching the sign-in tool takes an inference call, and that call is the one with no credential yet. Put XAIAuth on an agent running a different model:

Token Storage

Where the signed-in token lives, in order of preference:
  • Database — pass db= to XAITokenManager. Auth-token storage is implemented by the Postgres and SQLite adapters, sync and async; the table (agno_auth_tokens by default) is created on demand, with no migration to run. Rows are keyed by provider ("xai"), user id, and service ("supergrok"), and the token data inside the row is encrypted. Any other adapter logs a warning and falls back to the file store.
  • File — with no database, the token lands in xai_token.json relative to the process working directory (override with token_path), written with file mode 0600. The file holds one session: the shared deployment slot.
  • Memory — with encryption required but no key configured, the token stays in process memory only.
A sync run (agent.run) with an async DB adapter cannot await the adapter: it logs a warning and falls back to the file store. Async runs (agent.arun) use the async adapters natively. Access tokens are refreshed automatically shortly before expiry. A refresh that fails with invalid_grant deletes the stored token and raises a ModelAuthenticationError telling the user to sign in again or set XAI_API_KEY.

Multiple Users

Per-user sign-in keys each token to the run’s user_id: a user who signed in through XAIAuth gets their own stored session, and requests for that user are sent with their token. Per-user tokens require a database — the file store holds only the deployment slot, and refuses per-user writes with a warning. Requests for an identified user with no stored session fall back to the deployment slot. Set require_user_token=True on xAIResponses to refuse that fallback: requests for a user who has not signed in then fail with a ModelAuthenticationError instead of silently spending the shared subscription.

Signing Out

sign_out(user_id) on the manager deletes the stored token. It does not call a revocation endpoint — the grant lives on server-side until it expires or is revoked from the xAI account page.

Parameters

XAITokenManager

xAIResponses extends OpenResponses and accepts all of its parameters. For the API-key mode and the xAI chat class, see the xAI overview.