Skip to main content
Watch: Anthropic Just Hit the Brakes on Its Next AI Model

Setup guide - Documented by OpenCode

Use Grok in OpenCode

OpenCode's providers page documents a generic flow: run /connect, choose a provider and enter its credentials, then run /models. For an explicit setup, its documented custom-provider config can point a Responses-compatible runtime package at xAI's base URL https://api.x.ai/v1 with XAI_API_KEY.

Last verified 3 steps4 official sources

Steps

  1. Step 1.

    Create an xAI API key on the xAI console API Keys page and export it (from xAI quickstart):

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

    OpenCode's documented setup: run /connect, choose a provider (xAI, if it is in your version's catalog), and enter its credentials. Then run /models to select one of its models (xAI's current recommendation for code is grok-4.7).

    Snippet
    /connect
    /models
  3. Step 3.

    Alternatively, define a custom provider in opencode.jsonc using OpenCode's documented providers fields (name, env, package, settings.baseURL, models) and its listed @opencode/ai/providers/openai-compatible/responses package, filled with xAI's documented base URL, env var and model id. Models are then referenced as xai-api/grok-4.7:

    JSON
    {
      "$schema": "https://opencode.ai/config.json",
      "model": "xai-api/grok-4.7",
      "providers": {
        "xai-api": {
          "name": "xAI",
          "env": ["XAI_API_KEY"],
          "package": "@opencode/ai/providers/openai-compatible/responses",
          "settings": {
            "baseURL": "https://api.x.ai/v1",
          },
          "models": {
            "grok-4.7": {
              "name": "Grok 4.7",
            },
          },
        },
      },
    }

Caveats

  • OpenCode's deployed providers page (read 2026-11-08) no longer has an xAI section; the earlier xAI-specific steps (SuperGrok Subscription, Manually enter API Key) are not on it. It documents only the generic /connect then /models flow and says the provider and model catalog comes from models.dev, so whether xAI and which Grok ids appear depends on your installed version.
  • The custom config combines OpenCode's documented providers shape and package with xAI's base URL and model id; neither OpenCode nor xAI documents this pairing. The Responses package is used because xAI lists the Responses API as grok-4.7's API. OpenCode's page also lists an @opencode/ai/providers/xai package but does not document its settings.
  • OpenCode's page says xAI Responses models can keep one WebSocket connection per session, and that xAI continues from stored responses only: with its default store: false, each step is sent in full over the reused connection.
  • xAI docs now brand the company as SpaceXSI; the API host is still https://api.x.ai.

FAQ

How do I use Grok in OpenCode?

OpenCode's providers page documents a generic flow: run /connect, choose a provider and enter its credentials, then run /models. For an explicit setup, its documented custom-provider config can point a Responses-compatible runtime package at xAI's base URL https://api.x.ai/v1 with XAI_API_KEY.

Which Grok model ids work in OpenCode?

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

Is this an official Grok and OpenCode setup?

OpenCode documents this setup in its own docs. It was last checked against 4 official pages on November 8, 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.