xAI
first_party
Getting credentials
api-key
api_key via header (header Authorization: Bearer)
Environment: XAI_API_KEY
Create a key at console.x.ai. OpenAI SDKs work by changing base_url only; also Anthropic-compatible.
oauth
oauth via header (header Authorization: Bearer)
Flow: browser OIDC or device code at auth.x.ai (endpoints not publicly documented)
grok login (or grok login --device-auth) with a SuperGrok or X Premium subscription. Tokens persist in ~/.grok/auth.json with background refresh; requests use subscription quota (a weekly pool shared across Grok chat, Build, and API), not API billing.
Endpoints
| ID | URL | Protocol | Auth |
|---|---|---|---|
| v1-chat-completions | https://api.x.ai/v1/chat/completions | openai-chat | any |
| v1-responses | https://api.x.ai/v1/responses | openai-responses | any |
API surfaces
textstreaming
Quirks
- Responses is the preferred API per xAI docs. presence_penalty, frequency_penalty, and stop cannot be used with reasoning models — requests including them error. grok-4.20-multi-agent maps reasoning.effort to agent count (4 or 16), not depth. (docs)
- OAuth sessions call https://api.x.ai/v1 with Bearer tokens; an entitlement-aware catalog is available at https://cli-chat-proxy.grok.com/v1/models-v2. xAI decides which accounts receive OAuth tokens — some non-Heavy tiers report 403. SuperGrok is $30/mo, SuperGrok Plus $100/mo. (docs)
Models offered
| Model | Wire ID | Endpoint | Status | Reasoning |
|---|---|---|---|---|
| xai/grok-4-5 | grok-4.5 | v1-chat-completions | ga | effort · default on · mandatory · returns reasoning_content |
| xai/grok-4-5 | grok-4.5 | v1-responses | ga | effort · default on · mandatory · returns hidden · round-trips encrypted_content |
| xai/grok-4-6 | grok-4.6 | v1-chat-completions | ga | effort · default on · mandatory · returns reasoning_content |
| xai/grok-4-6 | grok-4.6 | v1-responses | ga | effort · default on · mandatory · returns reasoning_content · round-trips encrypted_content |