Practical Guide: Connecting Grok Models to Claude Code and Other AI Coding Assistants

With the right Base URL, API Key, and Model ID, most AI coding assistants can connect to any OpenAI-compatible endpoint.
The article explains that tools like Cline, Roo Code, Kilo Code, Aider, and opencode essentially only need three values when configuring custom model providers: Base URL, API Key, and Model ID. It recommends verifying the endpoint with a single cURL request and diagnosing issues via status codes. Claude Code is the exception, using the Anthropic Messages protocol and requiring a local relay. API Keys should be held via environment variables, encrypted storage, or a relay process, not config files. Gemini CLI and GitHub Copilot cannot point at custom endpoints. Prompt caching matters more than per-token list price for agent workloads.
AI coding assistants generally support custom model providers, but the configuration interfaces vary wildly across tools. In reality, most tools only care about three core pieces of information: Base URL (where requests are sent), API Key (what goes in the Authorization: Bearer header), and Model ID (what to put in the model field). Answer these three questions and you can point Cline, Aider, opencode, and Claude Code (with one extra step) at any OpenAI-compatible backend.
This article uses the Grokified gateway as an example (Base URL: https://api.grokified.com/v1, Key: gk_live_..., Model: grok-4.7), but all patterns apply to any OpenAI-compatible endpoint.

Step 1: First verify endpoint availability with cURL
Before configuring your editor, test the endpoint directly with a minimal request:
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"}]
}'
A 200 response means the Key, Base URL, and Model ID are all correct, so any subsequent errors can only be configuration issues in the proxy tool. If it fails, the status code points the way:
401: Wrong or revoked Key, or missingBearerprefix402: Account balance or billing issue403: Environment or permission mismatch (e.g. test Key used in production)400/404(for the model): Model ID has expired429/5xx: The only two status codes worth retrying
For proxy tools, looping retries on 401 just wastes time—fix the configuration first. Verification on the Python side is equally simple; the OpenAI SDK only needs the host changed:
from openai import OpenAI
client = OpenAI(
api_key="gk_live_...",
base_url="https://api.grokified.com/v1",
)
The essence of "OpenAI-compatible" is that the request structure stays the same—you just move the host line.
OpenAI-compatible endpoint means the server accepts the same request body structure as OpenAI's chat/completions (model, messages, temperature, etc.) and returns a response of the same shape. Many vendors and self-hosted solutions (such as vLLM, Ollama, LiteLLM) implement this protocol, so clients can reuse the same SDK as long as they point base_url at the other party's domain.
"Compatible" does not mean "identical": some endpoints may not support function calling, have different streaming response details, or impose extra restrictions on fields like max_tokens. When you encounter anomalies, first compare the official OpenAI request and response against yours using cURL to confirm whether it's a protocol difference or a configuration error.
Configuring Cline, Roo Code, and Kilo Code
Cline is a VS Code agent extension configured in its settings panel. Select 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 and fields. Two practical reminders:
- Model availability may depend on your subscription plan. With Grokified, for example,
grok-4.7requires a Basic plan or higher; otherwise the docs recommendgrok-4.6. Other providers have similar restrictions—if a model errors out but a cURL call with a different ID succeeds, this is likely the reason. - Keys are stored in VS Code's encrypted storage, not in plaintext files in the repository, which is the correct approach.

Aider configuration: environment variable driven
Aider reads the standard OpenAI environment variables, and the openai/ prefix before 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 don't want to export the Key in every shell, Aider also reads ~/.aider.conf.yml. But the Key itself should stay in environment variables rather than a YAML file, especially if you sync your dotfiles.
opencode: custom providers for the terminal agent
opencode is an open-source terminal agent that supports custom compatible providers. The config file is at ~/.config/opencode/opencode.json; when registering a provider, fill in the Base URL, read the Key from an environment variable, and add grok-4.7 as a model. Check the official opencode docs for the exact JSON schema, as it may change between versions. The three core values are exactly the same as above.
Claude Code: the one case that needs special handling
Claude Code uses Anthropic's Messages protocol, not OpenAI's chat completions. Setting only the Base URL cannot connect to an OpenAI-shaped endpoint because the request body structures differ. Two solutions:
- Use a provider that directly exposes an Anthropic-shaped endpoint.
- Run a local translator that accepts Anthropic-format requests and forwards them as OpenAI format.
Grokified takes the second approach: its CLI starts a local relay at 127.0.0.1:4111, and Claude Code's ~/.claude/settings.json points to that address. The Key is held by the relay process and not written to the settings file. You can manage the relay directly:
grokified relay status
grokified relay stop
If port 4111 is already in use, these two commands are the first step in troubleshooting.

Anthropic's Messages API differs significantly from OpenAI's chat completions in request body: message roles are only user and assistant (the system prompt goes in a top-level system field), content can be a string or an array of blocks like text and image, tool calls are expressed via tool_use / tool_result content blocks, and extended fields like thinking are supported. Responses also use a content block array rather than a single choices[0].message.
Therefore, a gateway that only accepts OpenAI format cannot directly serve Claude Code; the relay process's job is to perform bidirectional conversion between these two schemas, including mapping streaming events.
Complete all configuration with one command
Manually editing four config files once is fine, but repeating it on every new machine gets tiring. Grokified provides a CLI tool (Grokified-specific, but the approach is worth borrowing):
npm install -g grokified
grokified login # Browser login; or grokified login --key gk_live_... for headless environments
grokified setup # Opens a selector for configurable tools
grokified doctor # Checks Key, balance, relay, and wiring status
You can also specify tools individually:
grokified setup claude
grokified setup aider
grokified setup opencode
grokified setup vscode-agents # Cline / Roo Code / Kilo Code
The most central design choice: the Key is never copied into any tool's own config file. It is stored only in ~/.grokified/credentials, and tools obtain it at startup via environment variables (opencode, Aider), the relay (Claude Code), or the extension's encrypted storage (Cline). This means dotfiles repositories, screen sharing, and grep -r over your home directory won't leak the Key.
A common issue with npm global CLI installs: command not found after installation usually means npm's global bin isn't in PATH; run export PATH="$(npm config get prefix)/bin:$PATH". The CLI requires Node 18.17 or newer; the shell installer (curl -fsSL https://grokified.com/install.sh | bash) will prepare a private Node copy if the version is too old.
The boundaries of tools you can't reach
Some tools simply cannot point at custom endpoints:
- Gemini CLI only speaks Google's
generateContentformat; changing the Base URL only changes where requests go, not what they look like. - GitHub Copilot has no custom connection settings for this scenario.
- Cursor's built-in model selector is closed to this workflow, but extensions running inside Cursor, such as Cline, can still use custom providers.
Cost considerations: prompt caching matters more than list price
Grokified bills Grok usage below list price (see the pricing page for details), but the more general lesson is: agents resend a large amount of context on every turn, so for agent workloads, prompt caching matters more than the per-token list price. Whichever provider you use, confirm whether repeated prefixes are cached automatically or need to be enabled manually.
Prompt caching lets the server save repeated prefixes in requests (such as system prompts and codebase context); subsequent requests that hit the cache are billed at a discount, typically 10%–50% of the original price, and significantly reduce first-token latency. Mainstream implementations include OpenAI's automatic prefix caching, Anthropic's explicit cache_control markers, and transparent caching layers in some gateways.
For agent workloads, each turn may resend tens of thousands of tokens of historical context, so the cache hit rate directly determines actual cost. When choosing a provider, prioritize confirming whether caching is supported, whether it needs to be enabled manually, and whether the cache TTL covers the duration of a session.
Recap
- Before configuring any tool, verify the endpoint with a single cURL call.
- Cline, Aider, and opencode each need only a Base URL, Key, and Model ID.
- Claude Code requires an Anthropic-shaped endpoint or a local relay.
- Keep Keys out of config files: use environment variables or encrypted storage.
One-line Summary
As long as the Base URL, API Key, and Model ID are correct, most AI coding assistants can connect to any OpenAI-compatible endpoint.
Paragraph Summary
The article points out that when tools like Cline, Roo Code, Kilo Code, Aider, and opencode configure custom model providers, they essentially only care about three values: Base URL, API Key, and Model ID. The author recommends first verifying the endpoint with a single cURL request and quickly diagnosing issues based on status codes such as 401, 402, 403, 400/404, and 429/5xx. Claude Code is the exception—it uses the Anthropic Messages protocol and requires a local relay for format translation. API Keys should be held via environment variables, encrypted storage, or a relay process, and avoided in config files. Tools like Gemini CLI and GitHub Copilot cannot point at custom endpoints. Finally, the article reminds that for agent workloads, prompt caching determines actual cost more than per-token list price.
Related articles

Python 3.15 New Feature: Is the sentinel Type Better Than None?
Python 3.15 adds the sentinel type, using named unique sentinel objects to replace None and bare object(), resolving confusion among missing values, explicit emptiness, and invalid input while avoiding type hint failures.

Deep Learning's Three Architectures and the Universal Approximation Theorem: A Complete Guide to MLPs, CNNs, and Transformers
Explaining the inductive bias differences among MLP, CNN, and Transformer, the existence meaning of the Universal Approximation Theorem (UAT), and the role of Taylor expansion in approximation analysis, while clearing up common misconceptions.

GitLab Emergency Patch Release: Analysis of Critical Security Fixes
GitLab releases critical patch 19.5.1, sparking 355 points of discussion on Hacker News. This article analyzes the background, upgrade steps for self-hosted instances, and verification points to help DevOps teams respond quickly to security updates.