Skip to main content
Watch: I Built an AI App Without Leaving Databricks

Setup guide - Documented by Codex CLI

Use Grok in Codex CLI

Codex CLI has no built-in xAI provider, but its documented custom model_providers config (Responses wire API only) can point at xAI's documented Responses endpoint at https://api.x.ai/v1 with XAI_API_KEY.

Last verified 3 steps4 official sources

Steps

  1. Step 1.

    Create an xAI API key and export it (from xAI quickstart):

    Terminal
    export XAI_API_KEY="your_api_key"
  2. Step 2.

    Add a custom provider to ~/.codex/config.toml using Codex's documented model_providers keys (name, base_url, env_key, wire_api) with xAI's documented base URL and model id:

    TOML
    model = "grok-4.7"
    model_provider = "xai"
    
    [model_providers.xai]
    name = "xAI"
    base_url = "https://api.x.ai/v1"
    env_key = "XAI_API_KEY"
    wire_api = "responses"
  3. Step 3.

    Run codex as usual; requests go to https://api.x.ai/v1/responses.

    Terminal
    codex

Caveats

  • Combined config: neither OpenAI nor xAI documents this pairing. The keys come from Codex's config reference; the base URL, env var and model id come from xAI docs.
  • Codex now supports only wire_api = "responses" ('responses is the only supported value'). xAI serves POST /v1/responses and lists Responses as grok-4.7's API, so the protocol lines up, but Codex-specific Responses features (hosted tools, compaction, WebSocket transport) may not be supported by xAI.
  • Custom providers cannot reuse the reserved ids openai, ollama or lmstudio.

FAQ

How do I use Grok in Codex CLI?

Codex CLI has no built-in xAI provider, but its documented custom model_providers config (Responses wire API only) can point at xAI's documented Responses endpoint at https://api.x.ai/v1 with XAI_API_KEY.

Which Grok model ids work in Codex CLI?

The official docs read for this guide list grok-4.7, grok-4.3 and grok-build-0.1. Requests go to https://api.x.ai/v1.

Is this an official Grok and Codex CLI setup?

Codex CLI documents this setup in its own docs. It was last checked against 4 official pages on October 17, 2026.

Sources

Last verified against 4 official pages.

Newsletter

New models, set up the day they ship

One email per week. New model releases, the coding tools that support them and how to wire them up.