Skip to main content

xAI (Grok)

xAI provides the Grok model family through an OpenAI-compatible API. WednesdayAI integrates with xAI for text and vision inference. The default model is grok-4.

Prerequisites

Quick setup

1. Get an API key

Sign in to console.x.ai and create an API key. Keys start with xai-. Store it on the gateway host:
echo 'XAI_API_KEY=xai-...' >> ~/.openclaw/.env

2. Run onboarding

openclaw onboard --auth-choice xai-api-key
Or non-interactive:
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice xai-api-key \
  --xai-api-key "$XAI_API_KEY"

3. Configure

{
  models: {
    providers: {
      xai: {
        apiKey: "XAI_API_KEY", // references the env var
      },
    },
  },
  agents: {
    defaults: {
      model: { primary: "xai/grok-4" },
    },
  },
}
apiKey is the name of the environment variable, not the key value itself. Keep secrets in .env, not in committed config files.

Provider settings

SettingValue
Provider IDxai
Base URLhttps://api.x.ai/v1
APIOpenAI-compatible
Auth env varXAI_API_KEY
Default modelgrok-4
Default context window256,000 tokens

Verification

openclaw models status --probe-provider xai

Available models

Model IDContextNotes
grok-4256KDefault; reasoning
grok-4-fast2MReasoning; vision
grok-4-fast-non-reasoning2MVision
grok-4-1-fast2MReasoning; vision
grok-4-1-fast-non-reasoning2MVision
grok-code-fast-1256KReasoning; coding
grok-3131K
grok-3-latest131K
grok-3-fast131K
grok-3-mini131KReasoning
grok-3-mini-fast131KReasoning
grok-2131K
grok-2-vision8KVision
Use model IDs as xai/<model-id> — for example, xai/grok-4. Run openclaw models list --provider xai for the full current catalog.

Web search with Grok

Grok supports live web search. Configure it separately for the web search tool:
{
  tools: {
    web: {
      search: {
        grok: {
          apiKey: "XAI_API_KEY", // falls back to XAI_API_KEY env var
        },
      },
    },
  },
}
The web search tool uses grok-4-1-fast by default when Grok search is enabled.

Troubleshooting

Verify your key starts with xai- and is copied in full. Re-run openclaw onboard --auth-choice xai-api-key to refresh the stored credential.
xAI rejects certain JSON Schema keywords in tool definitions. WednesdayAI automatically sanitizes tool schemas for xAI — no configuration needed.
Confirm the model ID is correct and your xAI plan includes it. Run openclaw models status to see detected xAI models.