Setting up Grok in OpenCode
Updated:
Grok in OpenCode: setting it up through Grok API Dev takes under 5 minutes.
What OpenCode is
OpenCode calls itself an open source AI coding agent: it helps you write code in the terminal, an IDE, or a desktop app. It is deliberately not tied to one vendor — it reaches 75+ LLM providers through Models.dev, local models included, and any OpenAI-compatible endpoint can be declared as your own provider. That last part is exactly how Grok 4.5 gets in.
Terminal, desktop, or IDE
The same agent ships as a terminal interface, a desktop app, and an editor extension — the provider config is shared across all three.
Any model, any provider
75+ providers out of the box, plus your own OpenAI-compatible endpoint declared in the config, so the key and the address stay yours.
What you'll need
- A Grok API Dev account — a new one comes with $0.25 in test credit and lets you issue an API key straight from the dashboard.
Setting up OpenCode
Install OpenCode
The quickest way is the official install script. It is also on npm, Homebrew, Scoop, and Chocolatey. Launch it once so it creates its config directory.
curl -fsSL https://opencode.ai/install | bashRegister the provider in the config
All OpenCode settings live in a single file. Open it in any editor and add the provider block below.
~/.config/opencode/opencode.json
If the file does not exist yet, create it together with its parent folders.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"llm-gate": {
"npm": "@ai-sdk/openai-compatible",
"name": "LLM Gate",
"options": {
"baseURL": "https://api.llm-gate.tech/v1",
"apiKey": "YOUR_API_KEY"
},
"models": {
"grok-4.5": {
"name": "Grok 4.5"
}
}
}
}
}- Replace YOUR_API_KEY with the key from your dashboard, and keep the file out of your repository.
Run it and check
Save the file and start OpenCode in your project folder. Worth knowing before you debug anything: OpenCode merges its config files rather than replacing them, and an opencode.json in the project root outranks the global one. So if the model does not turn up, check the repository for its own config overriding your provider before you touch the global file.
opencodeopencode
Ask anything... "Fix broken tests"
Build · Grok 4.5 LLM Gate
tab agentsctrl+p commands
Tip Press ctrl+p to see all available actions and commands
Frequently asked questions
Why is the provider called llm-gate and not grok?
The key under provider is an identifier you choose, and it is what OpenCode shows as the provider name. It has nothing to do with the model: the model is grok-4.5, declared in the models block underneath.
OpenCode does not see the model. What is wrong?
Three usual causes: the baseURL is missing the /v1 suffix and must read exactly https://api.llm-gate.tech/v1; the config sits somewhere other than ~/.config/opencode/opencode.json; or the JSON is invalid after merging — a trailing comma is enough to make OpenCode skip the whole file.
What is the npm field for?
It tells OpenCode which adapter to load for this provider. @ai-sdk/openai-compatible is the generic OpenAI-compatible one, which is what a GrokAPI endpoint needs. Drop it and OpenCode will not know how to talk to the provider.
Can I keep other providers alongside this one?
Yes. provider is an object, so several providers live side by side — add ours next to the existing keys rather than replacing them. You then switch models from inside OpenCode.
Is it safe to put the key in the config file?
The file sits in your home directory, not in the project, so it does not reach the repository by default. Just make sure you never copy it into a project folder that gets committed, and reissue the key from the dashboard if it leaks.