Docs for SCORPIOX CODE @ 13253cf
xAI Grok Build and SuperGrok subscription via official Grok CLI device authentication.

Using Grok Build Subscription in SCORPIOX CODE

You have an xAI Grok Build subscription (the plan behind the official grok CLI) but you don't want to meter per-token against an XAI_API_KEY or run a separate paid API key just to use the models you already pay for. You can use it directly in SCORPIOX CODE. Instead of billing API tokens, the Grok provider signs you in through the official Grok CLI's OAuth device-auth flow and runs requests against the cli-chat-proxy.grok.com endpoint your subscription already pays for.

This page walks through the session login, how the token is stored and kept fresh by automatic refresh, how to juggle accounts with profiles (/profile and /use), how to inspect your models and credit usage, how to drive the login state without holding a TTY (machine mode), and how a Grok Build subscription differs from standard xAI API-key usage.

Docs for SCORPIOX CODE @ 13253cf.


When to use this provider

ScenarioExample
You have an xAI Grok Build subscriptionThe plan behind the official grok CLI — anything grok login --device-auth can sign in to
You don't have (or don't want) an XAI_API_KEYNo pay-per-token billing — requests draw on your Grok Build plan's credits
Headless / over SSHThe login is a device-auth flow: open the link on any device and sign in — no browser or redirect needed on the box you run from
Driven by SCORPIO BOTThe login state can be inspected as a single non-interactive command (--status) with no open TTY — see Machine mode

If you are instead calling the xAI API with an API key (XAI_API_KEY), use PROVIDER=openai pointed at api.x.ai (or an OpenAI-compatible endpoint). The two are different billing models for overlapping model families — see Grok Build subscription vs. the xAI API-key path below.

Subscription, not API key. The Grok provider authenticates with an OAuth session and draws on your account's included credits (the same weekly/monthly credit limit the official Grok CLI enforces). It does not accept an XAI_API_KEY for chat and does not bill per token.


Step 1 — Sign in with the device-auth flow

The Grok login hands the sign-in to the official Grok CLI's grok login --device-auth flow — the same OAuth device-auth the first-party CLI uses. It is deliberately SSH- and headless-friendly: you open a link, sign in to your xAI account on whatever device you already use, and the result lands in the credential file on the machine you're running from. There is no long URL to paste and no localhost redirect to capture, and nothing long-lived leaves the terminal.

scorpiox-grok-login

SCORPIOX CODE first checks for the official grok binary on your PATH. If it's present, it launches grok login --device-auth and lets the official flow do the sign-in:

  1. Open the printed link in your browser — on any device, wherever you're signed in to xAI.
  2. Sign in to your xAI / Grok Build account and approve the device.
  3. Come back to your terminal. The official flow polls and, the moment you approve, writes the session credential to ~/.grok/auth.json.

If the official grok CLI is not installed, scorpiox-grok-login tells you how to get it (or copy an existing credential file to a headless box):

curl -fsSL https://x.ai/cli/install.sh | bash
grok login --device-auth

or, if you already signed in somewhere else:

scp ~/.grok/auth.json root@host:~/.grok/auth.json

Whether the official CLI is installed or not, scorpiox-grok-login always writes a ready-to-use grok profile so the provider is one switch away (see Step 2). A few things worth knowing about this flow:


Step 2 — Turn on the Grok provider

The provider switches on with PROVIDER=grok. For a personal Grok Build subscription you set GROK_TOKEN_SOURCE=local so the provider reads the credential file your login just wrote. That is the whole setup:

PROVIDER=grok
GROK_TOKEN_SOURCE=local

Activate the profile (or set those keys in any cascade tier, or as OS environment variables) and SCORPIOX CODE connects.

/profile grok      # activate this profile and persist it
/use grok          # activate for this session only (no file change)

The grok profile scorpiox-grok-login writes looks like this:

PROVIDER=grok
MODEL=grok-4.6
GROK_MODEL=grok-4.6
GROK_TOKEN_SOURCE=local
# Token: ~/.grok/auth.json via scorpiox-grok-fetchtoken -local
# Host:  cli-chat-proxy.grok.com (OAuth) — not api.x.ai

You can also create it by hand under ~/.claude/scorpiox-env/grok.txt if you prefer.


Configuration keys

All keys can live in any cascade tier of scorpiox-env.txt, in a named profile, or as OS environment variables. See Configuration and Profiles for the full cascade and precedence rules.

KeyTypeDefaultDescription
PROVIDERchoice(empty)Set to grok to activate this provider.
GROK_TOKEN_SOURCEchoicelocalWhere to get the token: local, remote, ssh, tcp, or config. Use local for a Grok Build login you ran with scorpiox-grok-login. config makes the provider read this same key from the environment at runtime.
GROK_CREDENTIALS_FILEtext(empty)Override the path of the local credential file. Defaults to ~/.grok/auth.json (or $GROK_HOME/auth.json). Point it at a named account to pin a profile to a specific login.
MODEL / GROK_MODELtext(empty)Which model to run. GROK_MODEL takes precedence over MODEL. Defaults to grok-4.6 when neither is set.
GROK_HOMEenv(empty)Environment variable — an alternative base directory for auth.json, used in preference to $HOME.
GROK_REMOTE_URLtext(empty)Token endpoint, used only when GROK_TOKEN_SOURCE=remote.
GROK_SSH_HOST / _PORT / _USER / _PASStext(empty)Used only when GROK_TOKEN_SOURCE=ssh — fetch the token from a remote machine over SSH.

For a personal subscription, you only need two keys: PROVIDER=grok and GROK_TOKEN_SOURCE=local (plus optionally MODEL). The ssh / remote / tcp sources exist for shared or remote token setups and are not needed for a normal Grok Build login.

Where the token lives

On login, the credential is written to ~/.grok/auth.json (mode 0600). It holds one or more OIDC entries, each with an access token (key), its expires_at timestamp, and a refresh_token. On every request, GROK_TOKEN_SOURCE=local reads from that file (or from GROK_CREDENTIALS_FILE / $GROK_HOME if set), always picking the entry with the latest expiry. No API key is involved, and no key is ever written.


Token persistence and automatic refresh

Unlike a static API key, a Grok Build session token is short-lived — but you don't have to manage that. The provider keeps it fresh for you:

scorpiox-grok-refreshtoken            # refresh if the token is expired (5-min buffer)
scorpiox-grok-refreshtoken --force    # always refresh
scorpiox-grok-refreshtoken --verbose  # also print token details

Inspecting the resolved configuration

Use scorpiox-config to see resolved values and where each comes from (which cascade tier won):

scorpiox-config            # open the interactive config editor
scorpiox-config --verbose  # print key values (PROVIDER, GROK_TOKEN_SOURCE, MODEL, …) with their source tier

--verbose shows the resolved PROVIDER, GROK_TOKEN_SOURCE, and MODEL, so you can confirm you're pointed at the account and model you expect before a long run.

Checking your subscription usage

The provider runs against the same credit quota the official Grok CLI enforces. Check how full it is with:

scorpiox-grok-usage            # human-readable summary
scorpiox-grok-usage --json     # raw billing JSON

You'll see your current credit limit (weekly or monthly) as a percentage used, the reset time (UTC and local) and how long until it resets, plus your prepaid balance and on-demand spend. Useful for knowing when a window resets before you kick off a long run.

Listing the models you can use

The full set of model IDs your account can reach:

scorpiox-grok-models            # pretty-printed model list
scorpiox-grok-models --json     # raw JSON

Switching between accounts

Save more than one login

A Grok session lives in a single auth.json, so to use more than one xAI account you point each profile at its own copy of the file:

# sign in to account A (writes ~/.grok/auth.json), then set it aside
cp ~/.grok/auth.json ~/.grok/accounts/personal.json
# sign in to account B
scorpiox-grok-login
cp ~/.grok/auth.json ~/.grok/accounts/work.json

Bind each login to a profile

Now make one profile per account. Point GROK_CREDENTIALS_FILE at the right file so the profile always uses that account:

# ~/.claude/scorpiox-env/grok-personal.txt
PROVIDER=grok
GROK_TOKEN_SOURCE=local
GROK_CREDENTIALS_FILE=~/.grok/accounts/personal.json
MODEL=grok-4.6
# ~/.claude/scorpiox-env/grok-work.txt
PROVIDER=grok
GROK_TOKEN_SOURCE=local
GROK_CREDENTIALS_FILE=~/.grok/accounts/work.json
MODEL=grok-4.6

Switch accounts and models in-session

With those profiles in place, switching accounts is just switching profiles — no re-login, no restart:

/profile grok-work       # persistent — writes ACTIVE_PROFILE, survives restarts
/use grok-personal       # session-only — gone when the session ends
/profile                 # open the profile picker (or list if no picker is installed)
/profile off             # deactivate the profile

/profile and /use both trigger a live provider reload, so the new account and model take effect immediately. If the new profile fails to initialize, SCORPIOX CODE reverts to the previous one. The difference is scope: /profile <name> persists (it writes ACTIVE_PROFILE, so it survives restarts), while /use <name> is session-only (an in-memory switch that disappears when the session ends). See Configuration and Profiles for the full switching semantics.


Choosing a model

MODEL (or GROK_MODEL) takes a Grok model ID; GROK_MODEL takes precedence over MODEL. When neither is set, the provider defaults to grok-4.6.

MODEL valueBehaviour
(empty)grok-4.6 (provider default)
any grok-* IDpassed through as-is

The full list your account can reach is always available from scorpiox-grok-models. You can pin a specific version by setting MODEL in your profile, or switch it at runtime with the /model command.

Note: the login-offered grok profile ships with MODEL=grok-4.6 out of the box. Change it to any model ID from scorpiox-grok-models depending on the model you want by default.


Machine mode (no TTY)

Sometimes you can't hold a terminal open while a device-auth sign-in is in progress — a background agent, a CI step, or SCORPIO BOT's provider flow. The Grok login ships an additive machine mode: the same non-interactive commands that print a single line of JSON to stdout. Tokens are never printed — only status. Running the tool with no machine flag is the original interactive behaviour, unchanged.

Because Grok Build signs in through the official Grok CLI (grok login --device-auth) — a protocol SCORPIOX CODE does not own — machine mode is status-only (flow "terminal"): it reports the state and points you at a terminal login. It does not start or poll the device-auth flow itself, and it never writes the profile; the interactive path below still does.

FlagWhat it does
--statusReport the login state for this node as a single JSON line.
--cancelCancel a pending machine-mode login state.
--start / --poll / --finishRecognised, but rejected with terminal_only: Grok signs in through the official grok CLI, so use Terminal login.

A typical machine-mode check:

scorpiox-grok-login --status
# {"ok":true,"provider":"grok","display":"Grok (xAI)","flow":"terminal","path":"~/.grok/auth.json","logged_in":true,"has_refresh":true,"profile_exists":true,...}

If logged_in is false, drive the user to a terminal scorpiox-grok-login. A few things worth knowing:


Grok Build subscription vs. the xAI API-key path

It's easy to confuse the two because they can both reach Grok models. Here's the difference:

Grok provider (this page)xAI API-key path (PROVIDER=openai at api.x.ai)
PROVIDER valuegrokopenai (pointed at api.x.ai)
AuthenticationOAuth session login (scorpiox-grok-login via the official grok CLI)XAI_API_KEY bearer token
BillingDraws on your Grok Build plan's credits (the same credit limit the official Grok CLI enforces)Pay-per-token xAI API usage
What you needAn xAI Grok Build subscription the grok CLI can sign in toAn XAI_API_KEY and a platform account
Token lifecycleShort-lived OAuth session, auto-refreshed before expiry and on 401Static API key, no refresh
Chat endpointcli-chat-proxy.grok.com/v1/responses (OpenAI Responses wire)api.x.ai chat completions

They can reach the same underlying models, but the Grok provider bills against your existing Grok Build subscription while the xAI API-key path bills per token against your XAI_API_KEY (and, via openai, can point at any OpenAI-compatible server, local or remote). Note the chat provider deliberately targets cli-chat-proxy.grok.com — not api.x.ai, which is the API-key path. Pick the one that matches how you already pay for models. See Using the OpenAI Provider.


See also