Skip to main content

xAI

xAI is available on the Spanway gateway through the xai/ model prefix. You register a xAI model once in the gateway's config.yaml (or through the Admin UI), and every application then calls it through the gateway's OpenAI-compatible API with a Spanway virtual key. The provider credential stays on the gateway, and every request is authenticated, rate limited, logged and costed in the same way as any other provider.

The gateway translates requests and responses for xAI natively, so provider specific parameters and errors are mapped to the OpenAI format for you.

Supported endpoints​

The gateway's endpoint support matrix lists the following endpoints for xAI. Each link explains the request shape and the gateway features that apply to that endpoint.

Model types​

The bundled price map lists 58 xAI models across these modes: Responses, Chat, Image generation, Video, Transcription. The mode decides which gateway endpoint a model is meant for, and it is also used by the gateway's health checks to send the right kind of test request.

Environment variables​

The xAI integration reads the following environment variables. Variables marked as required are the ones the gateway's environment validation checks for this provider. You can also pass any of these values directly in spanway_params (for example api_key or api_base), and the per-model value wins over the environment.

VariableRequiredPurpose
XAI_API_KEYYesCredential the gateway sends to the provider
XAI_API_BASENoOverrides the provider base URL
XAI_OAUTH_TOKEN_DIRNoRead by the provider integration
XAI_OAUTH_AUTH_FILENoRead by the provider integration
XAI_OAUTH_API_BASENoOverrides the provider base URL

Reference a variable from config.yaml with the os.environ/ prefix so that the secret never appears in the file itself. Secrets can also come from a secret manager, see secret managers.

Register a model on the gateway​

Add an entry to model_list in config.yaml. The model_name is the public name your applications send, and spanway_params.model tells the gateway which provider and upstream model to call.

model_list:
- model_name: grok-4.6
spanway_params:
model: xai/grok-4.6
api_key: os.environ/XAI_API_KEY

Start the gateway with this file:

export XAI_API_KEY="..."
spanway --config config.yaml
Private preview

Spanway is in private preview. The container images and Helm charts will be published soon. To request access, write to sales@spanway.ai, and preview customers receive download instructions in their onboarding pack.

To add the model without a restart, call POST /model/new with the same model_name and spanway_params, or use the Models + Endpoints page in the Admin UI. See model management for details.

Call the model through the gateway​

Send requests to the gateway's /v1/chat/completions endpoint with a virtual key. The gateway maps the public model name to the xAI deployment, translates the request, and returns the response in the OpenAI format.

curl -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.6",
"messages": [{"role": "user", "content": "Summarize what an AI gateway does in two sentences."}]
}'

The same request works from any OpenAI SDK by setting the base URL to http://localhost:4000 and the API key to a Spanway virtual key. Create keys with POST /key/generate as described in virtual keys.

Models and pricing​

The table lists every xAI model in the gateway's bundled price map. Prices are shown in US dollars per 1 million tokens, computed from the per-token values the gateway uses for spend tracking. Context window sizes are the provider limits recorded in the same file. Capabilities are the supports_* flags set for each model.

info

Prices come from the price map bundled with this Spanway build. They are used to calculate the spend recorded for each request, key, team and user. Your negotiated rates may differ, and you can override them per deployment with custom pricing.

Model (model value)ModeMax input tokensMax output tokensInput per 1M tokensOutput per 1M tokensOther pricingCapabilities
xai/low/1024-x-1024/grok-imagine-image-2.0Image generation
xai/grok-4.3Chat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.3-latestChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.5Chat500,000500,000$2.00$6.00tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.5-latestChat500,000500,000$2.00$6.00tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.6Chat500,000500,000$2.00$6.00tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.7Chat500,000500,000$2.00$6.00tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20Chat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-0309Chat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-0309-non-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, prompt caching, structured output, web search
xai/grok-4.20-0309-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-betaChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-beta-0309Chat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-beta-0309-non-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, prompt caching, structured output, web search
xai/grok-4.20-beta-0309-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-beta-latestChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-beta-latest-non-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, prompt caching, structured output, web search
xai/grok-4.20-beta-latest-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-beta-non-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, prompt caching, structured output, web search
xai/grok-4.20-beta-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-experimental-beta-0304Chat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-experimental-beta-0304-non-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, prompt caching, structured output, web search
xai/grok-4.20-experimental-beta-0304-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-experimental-beta-latestChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-experimental-beta-non-reasoning-latestChat1,000,0001,000,000$1.25$2.50tools, vision, prompt caching, structured output, web search
xai/grok-4.20-experimental-beta-reasoning-latestChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-multi-agentResponses1,000,0001,000,000$1.25$2.50vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-multi-agent-0309Responses1,000,0001,000,000$1.25$2.50vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-multi-agent-beta-0309Responses1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-multi-agent-beta-latestResponses1,000,0001,000,000$1.25$2.50vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-multi-agent-experimental-beta-0304Responses1,000,0001,000,000$1.25$2.50vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-multi-agent-experimental-beta-latestResponses1,000,0001,000,000$1.25$2.50vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-multi-agent-latestResponses1,000,0001,000,000$1.25$2.50vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-non-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, prompt caching, structured output, web search
xai/grok-4.20-non-reasoning-gv2Chat1,000,0001,000,000$1.25$2.50tools, vision, prompt caching, structured output, web search
xai/grok-4.20-non-reasoning-latestChat1,000,0001,000,000$1.25$2.50tools, vision, prompt caching, structured output, web search
xai/grok-4.20-reasoningChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-reasoning-gv2Chat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-4.20-reasoning-latestChat1,000,0001,000,000$1.25$2.50tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-build-0.1Chat256,000256,000$1.00$2.00tools, vision, reasoning, prompt caching, structured output
xai/grok-build-latestChat500,000500,000$2.00$6.00tools, vision, reasoning, prompt caching, structured output, web search
xai/grok-code-fastChat256,000256,000$1.00$2.00tools, vision, reasoning, prompt caching, structured output
xai/grok-code-fast-1Chat256,000256,000$1.00$2.00tools, vision, reasoning, prompt caching, structured output
xai/grok-code-fast-1-0825Chat256,000256,000$1.00$2.00tools, vision, reasoning, prompt caching, structured output
xai/grok-imagine-imageImage generation
xai/grok-imagine-image-2.0Image generation
xai/grok-imagine-image-2026-03-02Image generation
xai/grok-imagine-image-proImage generation
xai/grok-imagine-image-qualityImage generation
xai/grok-imagine-image-quality-20260403Image generation
xai/grok-imagine-image-quality-latestImage generation
xai/grok-imagine-videoVideo$0.05 per output second
xai/grok-imagine-video-1.5Video$0.08 per output second
xai/grok-imagine-video-1.5-2026-05-30Video$0.08 per output second
xai/grok-imagine-video-1.5-liteVideo$0.02 per output second
xai/grok-imagine-video-1.5-previewVideo$0.08 per output second
xai/grok-voice-transcribe-1.0Transcription$0.00002778 per input second, $0 per output second
xai/grok-voice-transcribe-2.0Transcription$0.00002778 per input second, $0 per output second