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

Setup guide - Documented by OpenCode

Use Grok in OpenCode

OpenCode has a built-in xAI provider. Connect with /connect (SuperGrok subscription via device-code OAuth, or a pay-as-you-go xAI API key), then pick a Grok model with /models.

Last verified 5 steps4 official sources

Steps

  1. Step 1.

    API key path: head over to the xAI console (https://console.x.ai/), create an account, and generate an API key.

  2. Step 2.

    Run the /connect command and search for xAI.

    Snippet
    /connect
  3. Step 3.

    Select Manually enter API Key and paste your xAI API key.

    Snippet
    ┌ API key
    │
    │
    └ enter
  4. Step 4.

    Run the /models command to select a Grok model (current xAI recommendation for code is grok-4.7).

    Snippet
    /models
  5. Step 5.

    Subscription path instead: run /connect, search for xAI, select SuperGrok Subscription, approve the consent screen (enter the user code OpenCode shows if xAI asks), then run /models. OpenCode refreshes the OAuth access token automatically; any Grok or X Premium plan that includes Grok API access works and you do not need a separate XAI_API_KEY.

    Snippet
    /connect

Caveats

  • OpenCode's xAI section still says to pick 'a model like Grok Beta'; that example is stale. Current model ids come from docs.x.ai/developers/models (grok-4.7 is xAI's recommended model for code).
  • Which Grok ids appear in /models depends on OpenCode's model list for your installed version.
  • 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 has a built-in xAI provider. Connect with /connect (SuperGrok subscription via device-code OAuth, or a pay-as-you-go xAI API key), then pick a Grok model with /models.

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 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.