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
- Step 1.
Create an xAI API key on the xAI console API Keys page and export it (from xAI quickstart):
Terminalexport XAI_API_KEY="your_api_key" - 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 - 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.
More setup guides
Same tool, other providers
Related reading
- Grok 4.6: xAI's Agent-Focused Update Matches GPT-5.6 Sol at the Same $2/$6 PriceGrok 4.6 release guide: xAI's agent-focused update matches GPT-5.6 Sol on the AA index at the same $2/$6 pricing, and runs in Cursor and OpenCode.
- GPT-6 Sol vs Claude Opus 5.5 vs Grok 4.7: The September 2026 Price WarGPT-6 Sol vs Claude Opus 5.5 vs Grok 4.7 pricing: verified per-token rates, cost-per-task math and a decision guide for the September 2026 price war.
- Grok Bot's Core Primitive: Every Bot Gets a ComputerGrok Bot gives every Bot a persistent cloud computer with a browser and terminal. Why that one primitive explains routines, Bot teams, and always-on work.
- Grok Bot's Meta Controls: Oversight as a Product PrimitiveGrok Bot's meta controls make agent oversight a product primitive: approval gates, a chief-of-staff structure and escalation learning, not a settings page.
- Grok Bot Has the Right Shape: Four Primitives, Nothing ElseGrok Bot ships four primitives that compose - a text thread, its own cloud computer, a chief of staff over Bots, and show-it-once routines - and nothing else.
- Grok Bot Routines: Automations Without Automation-BuildingGrok Bot routines let you demonstrate a job once, correct it in plain language and hand the Bot the schedule. How it works and how approval gates keep it safe.
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.