Commands, package names, and image names on this page come from the open-source project that Mibyan Desktop is built on, and can differ from the Mibyan Desktop installer. For the supported Mibyan install and update path, see Install and update.
XAI_API_KEY is required — log in once and Mibyan automatically refreshes your session in the background.
When you sign in with an X account that has Premium+, xAI automatically links the subscription status to your xAI session, so the OAuth flow works the same as it does for direct SuperGrok subscribers.
The transport reuses the codex_responses adapter (xAI exposes a Responses-style endpoint), so reasoning, tool-calling, streaming, and prompt caching work without any adapter changes.
The same OAuth bearer token is also reused by every direct-to-xAI surface in Mibyan — TTS, image generation, video generation, and transcription — so a single login covers all four.
Overview
Prerequisites
- Python 3.9+
- Mibyan installed
- An active SuperGrok subscription on your xAI account, or an X Premium+ subscription on the X account you sign in with (xAI links the subscription automatically)
- A browser available anywhere you can open the printed verification URL
Quick Start
~/.mibyan/auth.json and refreshed automatically before they expire.
Logging In Manually
You can trigger a login without going through the model picker:Remote / headless sessions
On servers, containers, browser-only consoles (Cloud Shell, Codespaces, EC2 Instance Connect), or SSH sessions where Mibyan cannot open a browser locally, Mibyan prints the xAI verification URL and user code. Open the URL in any browser on your laptop or in the cloud console, enter the code if prompted, and Mibyan will keep polling until xAI approves the login. No SSH tunnel or local callback listener is required.How the Login Works
- Mibyan requests a device code from
auth.x.ai. - You open the verification URL, sign in, enter the displayed code if prompted, and approve access.
- Mibyan polls xAI until approval, then saves tokens to
~/.mibyan/auth.json. - From then on, Mibyan refreshes the access token in the background — you stay signed in until you
mibyan auth logout xai-oauthor revoke access from your xAI account settings.
Checking Login Status
◆ Auth Providers section will show the current state of every provider, including xai-oauth.
Switching Models
Configuration Reference
After login,~/.mibyan/config.yaml will contain:
Provider aliases
All of the following resolve toxai-oauth:
Direct-to-xAI Tools (TTS / Image / Video / Transcription / X Search)
Once you’re logged in via OAuth, every direct-to-xAI tool reuses the same bearer token automatically — there is no separate setup unless you’d rather use an API key. To pick a backend for each tool:XAI_API_KEY is set, the picker offers a 3-choice menu: OAuth login, paste API key, or skip.
Video generation is off by defaultThe
video_gen toolset is disabled by default. Enable it in mibyan tools → 🎬 Video Generation (press space) before the agent can call video_generate. Otherwise the agent may fall back to the bundled ComfyUI skill, which is also tagged for video generation.X search auto-enables when xAI credentials are presentThe
x_search toolset auto-enables whenever xAI credentials (a SuperGrok / X Premium+ OAuth token or XAI_API_KEY) are configured. Disable explicitly via mibyan tools → 🐦 X (Twitter) Search (press space) if you don’t want this. The tool routes through xAI’s built-in x_search Responses API — it works with either your SuperGrok / X Premium+ OAuth login or a paid XAI_API_KEY, and prefers OAuth when both are configured (uses your subscription quota instead of API spend). The tool schema is hidden from the model when no xAI credentials are configured, regardless of whether the toolset is enabled.Models
The chat catalog is derived live from the on-disk
models.dev cache; new xAI releases appear automatically once that cache refreshes. grok-4.6 is always pinned to the top of the list.
Environment Variables
To select xAI as the active provider, set
model.provider: xai-oauth in config.yaml (use mibyan setup for the guided flow) or pass --provider xai-oauth for a single invocation.
Troubleshooting
Token expired — not re-logging in automatically
Mibyan refreshes the token before each session and again reactively on a 401. If refresh fails withinvalid_grant (the refresh token was revoked, or the account was rotated), Mibyan surfaces a typed re-auth message instead of crashing.
When the refresh failure is terminal (HTTP 4xx, invalid_grant, revoked grant, etc.), Mibyan marks the refresh token as dead and quarantines it locally — subsequent calls skip the doomed refresh attempt instead of replaying the same 401 over and over. The agent surfaces a single “re-authentication required” message and stays out of the way until you log in again.
Fix: run mibyan auth add xai-oauth again to start a fresh login. The quarantine clears on the next successful exchange.
Authorization timed out
Device-code approval has a finite expiry window (xAI setsexpires_in on the device-code response, typically on the order of tens of minutes). If you do not approve the login in time, Mibyan raises a timeout error.
Fix: re-run mibyan auth add xai-oauth (or mibyan model). The flow starts fresh.
Logging in from a remote server
On SSH or container sessions Mibyan prints the verification URL and user code instead of opening a browser. Open that URL in a browser on your laptop or in a cloud console — no SSH port forward is needed for xAI Grok OAuth.HTTP 403 after a successful login (tier / entitlement)
OAuth completed in the browser, tokens are saved, but inference or token refresh returnsHTTP 403 with a message similar to “The caller does not have permission to execute the specified operation”.
This is not a stale-token problem — re-running mibyan model won’t change it. xAI’s backend has been seen to restrict OAuth API access to specific SuperGrok tiers despite the in-app subscription being active (issue #26847).
Fix: set XAI_API_KEY and switch to the API-key path:
”No xAI credentials found” error at runtime
The auth store has noxai-oauth entry and no XAI_API_KEY is set. You haven’t logged in yet, or the credential file was deleted.
Fix: run mibyan model and pick the xAI Grok OAuth provider, or run mibyan auth add xai-oauth.
Logging Out
To remove all stored xAI Grok OAuth credentials:auth.json and any credential-pool rows for xai-oauth. Use mibyan auth remove xai-oauth <index|id|label> if you only want to drop a single pool entry (run mibyan auth list xai-oauth to see them).
See Also
- OAuth over SSH / Remote Hosts — SSH tunnels for loopback-redirect providers (Spotify, MCP); xAI uses device code and does not need a tunnel
- AI Providers reference
- Environment Variables
- Configuration
- Voice & TTS

