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
- Step 1.
API key path: head over to the xAI console (https://console.x.ai/), create an account, and generate an API key.
- Step 2.
Run the /connect command and search for xAI.
Snippet/connect - Step 3.
Select Manually enter API Key and paste your xAI API key.
Snippet┌ API key │ │ └ enter - Step 4.
Run the /models command to select a Grok model (current xAI recommendation for code is grok-4.7).
Snippet/models - 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.
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 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.
- opencode.aihttps://opencode.ai/docs/providers/
- raw.githubusercontent.comhttps://raw.githubusercontent.com/anomalyco/opencode/dev/packages/web/src/content/docs/providers.mdx
- docs.x.aihttps://docs.x.ai/developers/models.md
- docs.x.aihttps://docs.x.ai/developers/grok-4-7.md
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.