Disclosure: I build Grokified, the gateway used as the worked example here. The patterns below work with any OpenAI-compatible endpoint. Swap in your own base URL, key and model id.
Most AI coding agents let you bring your own model provider now. The settings screens look different, but under the hood nearly all of them ask the same three questions:
- Base URL: where should requests go?
-
API key: what goes in the
Authorization: Bearerheader? -
Model id: what string goes in the
modelfield?
Once you can answer those three, you can point Cline, Aider, opencode and (with one extra step) Claude Code at almost any OpenAI-compatible backend. This post walks through each tool with real values, then covers the one case that doesn't fit the pattern.
My examples use these values from the Grokified docs:
| Field | Value |
|---|---|
| Base URL | https://api.grokified.com/v1 |
| Key |
gk_live_... (production) or gk_test_... (test) |
| Model | grok-4.7 |
Step 0: Prove the endpoint works before touching any agent
Don't debug three layers at once. Before configuring an editor, send the smallest possible request with cURL:
curl https://api.grokified.com/v1/chat/completions \
-H "Authorization: Bearer $GROKIFIED_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.7",
"messages": [{"role": "user", "content": "Hello"}]
}'
If that returns 200, your key, base URL and model id are all good, so any later failure is the agent's config. If it doesn't, the status code tells you where to look:
-
401: wrong or revoked key, or a missingBearerprefix -
402: balance or billing on the account -
403: environment or permission mismatch (e.g. a test key against production) -
400/404on the model: the model id isn't current -
429/5xx: the only codes worth retrying
That last point matters for agents. Retrying a 401 in a loop just wastes time. Fix the config first.
The same check in Python, using the OpenAI SDK unchanged except for the host:
from openai import OpenAI
client = OpenAI(
api_key="gk_live_...",
base_url="https://api.grokified.com/v1",
)
The point of "OpenAI-compatible" is that the request shape stays the same. Only the host line moves.
Cline (and Roo Code / Kilo Code)
Cline is a VS Code agent extension, so the config lives in its own settings panel rather than a file. Pick the OpenAI-compatible provider and fill in four fields:
API Provider: OpenAI Compatible
Base URL: https://api.grokified.com/v1
API Key: gk_live_...
Model ID: grok-4.7
Roo Code and Kilo Code have the same "custom provider" slot with the same fields.
Two practical notes:
-
Model availability can depend on your plan. With Grokified,
grok-4.7needs the Basic plan or above, and the docs suggestgrok-4.6otherwise. Other providers have similar gating, so if the model returns an error and cURL with a different id works, this is probably why. - The key goes into VS Code's encrypted key storage, not a plaintext file in your repo. That's the right place for it.
Aider
Aider reads the standard OpenAI environment variables, and the openai/ prefix on the model name tells it to use the OpenAI-compatible client:
export OPENAI_API_BASE=https://api.grokified.com/v1
export OPENAI_API_KEY=gk_live_...
aider --model openai/grok-4.7
If you'd rather not export a key into every shell, Aider also reads ~/.aider.conf.yml. Keep the key itself in an environment variable rather than the YAML file, especially if you sync dotfiles.
opencode
opencode is an open-source terminal agent that supports custom compatible providers. Its config lives at ~/.config/opencode/opencode.json. You register a provider with the base URL, read the key from an environment variable, and add grok-4.7 as a model. Check opencode's own provider docs for the exact JSON schema, since it changes between versions. The three values are the same as everywhere else.
Claude Code: the one that's different
Claude Code speaks Anthropic's Messages protocol, not OpenAI's chat completions. Setting a base URL alone won't work against an OpenAI-shaped endpoint, because the request bodies are different.
You have two options:
- Use a provider that exposes an Anthropic-shaped endpoint directly.
- Run a small local translator that accepts Anthropic-format requests and forwards OpenAI-format ones.
Grokified takes the second approach. Its CLI starts a local relay on 127.0.0.1:4111, and Claude Code's ~/.claude/settings.json points there. The key is held by the relay process rather than written into the settings file. You can manage the relay directly:
grokified relay status
grokified relay stop
If something else is already on port 4111, those two commands are your first stop.
Doing all of the above in one command
Hand-editing four configs is fine once. Doing it on every new machine gets old, which is why I built a CLI for it. It's specific to Grokified, but here's what it does:
npm install -g grokified
grokified login # browser sign-in; or: grokified login --key gk_live_... for headless
grokified setup # opens a picker of tools it can configure
grokified doctor # checks key, balance, relay, and what's wired up
You can also target one tool at a time:
grokified setup claude
grokified setup aider
grokified setup opencode
grokified setup vscode-agents # Cline / Roo Code / Kilo Code
The design choice I care most about is that the key is never copied into any tool's own config file. It's stored once in ~/.grokified/credentials, and tools get it as an environment variable at launch (opencode, Aider), through the relay (Claude Code), or through the extension's encrypted storage (Cline). That means your dotfiles repo, screen shares and grep -r of your home directory don't leak it.
The CLI page lists every config file it touches.
Troubleshooting notes from the docs that apply to most npm-installed CLIs:
-
command not foundafter install usually means npm's global bin isn't on yourPATH:export PATH="$(npm config get prefix)/bin:$PATH" - The CLI needs Node 18.17 or newer. The shell installer (
curl -fsSL https://grokified.com/install.sh | bash) sets up a private copy of Node if yours is older.
What this can't reach
Be honest about the limits. Some tools can't be pointed at a custom endpoint at all:
-
Gemini CLI only speaks Google's
generateContentformat. Changing its base URL changes where requests go, not what they look like. - GitHub Copilot has no custom connection setting for this.
- Cursor's built-in model picker is closed for this flow, but extensions like Cline running inside Cursor can still use a custom provider.
A note on cost
I won't pretend there's no commercial angle: Grokified bills Grok usage at a discount to list price, and the details are on the pricing page. The more general lesson is that agents resend a lot of context on every turn, so prompt caching matters more than headline per-token prices for agent workloads. Whatever provider you use, check whether repeated prefixes are cached automatically or need opting in.
Recap
- Verify the endpoint with one cURL call before configuring anything.
- Cline, Aider and opencode each need just a base URL, a key and a model id.
- Claude Code needs an Anthropic-shaped endpoint or a local relay.
- Keep keys out of config files: use env vars or encrypted storage.
If you try this with another OpenAI-compatible provider and hit a quirk, I'd like to hear about it in the comments.
Top comments (0)