Skip to main content

xAI

xAI builds the Grok model family. AgentXchain connects via api_proxy using xAI's OpenAI-compatible API.

Which adapter?

api_proxy with provider: "openai" and a custom base_url.

Prerequisites

  • An xAI API key — get one from console.x.ai
  • XAI_API_KEY set in your environment
  • agentxchain CLI installed

Configuration

{
"runtimes": {
"grok-dev": {
"type": "api_proxy",
"provider": "openai",
"model": "grok-4.20-beta-2",
"auth_env": "XAI_API_KEY",
"base_url": "https://api.x.ai/v1/chat/completions"
}
},
"roles": {
"dev": {
"runtime": "grok-dev",
"mandate": "Implement features and fix bugs",
"authority": "proposed"
}
}
}

Minimal working example

agentxchain init --governed --template api-service --goal "Build a feedback intake API" --dir my-project -y
cd my-project
# Replace the scaffolded runtime wiring in agentxchain.json with the xAI config above.
agentxchain doctor
agentxchain connector check
agentxchain connector validate grok-dev
agentxchain run

If you prefer the guided interactive scaffold, run agentxchain init --governed without -y, then update agentxchain.json with the xAI config above before agentxchain connector check and agentxchain connector validate grok-dev.

Available models

ModelBest for
grok-4.20-beta-2Most capable, complex reasoning
grok-4.1-fastFast, balanced performance
grok-code-fast-1Optimized for code generation

Verify the connection

export XAI_API_KEY="xai-..."
agentxchain connector check
agentxchain connector validate grok-dev

Gotchas

  • OpenAI-compatible: Use provider: "openai" with base_url pointing to api.x.ai.
  • Beta models: Some Grok models are in beta. Check xAI's documentation for availability and rate limits.
  • Cost rates: Add an operator override keyed by the exact runtime model string, since xAI models are not in the bundled defaults:
{
"budget": {
"cost_rates": {
"grok-4.20-beta-2": { "input_per_1m": 3.00, "output_per_1m": 15.00 }
}
}
}