Claude Code Integration with The Grid | Anthropic API Setup
Use Claude Code with The Grid through the Anthropic Messages API. Set environment variables, map model aliases, and run Claude Code normally.
Claude Code can talk to The Grid directly through The Grid's beta Anthropic Messages endpoint. No local proxy, no LiteLLM bridge, no format translation. Point Claude Code at the base URL, supply your key through a small helper script, map Claude Code's family aliases (Sonnet, Haiku, Opus) to Grid instruments, and run claude normally.
Prerequisites
Claude Code installed (
npm install -g @anthropic-ai/claude-codeor the native installer).A Grid account at app.thegrid.ai.
Credits in your account. The Grid is prepaid.
A Grid consumption API key from Settings → API Keys → Create Consumption Key.
Setup
1. Create ~/.claude/settings.json
Pick instrument IDs from the current instruments list. A reasonable default mapping is Sonnet → Code Prime, Haiku → Code Standard, Opus → Code Max.
{
"apiKeyHelper": "~/.claude/thegrid_key.sh",
"env": {
"ANTHROPIC_BASE_URL": "https://messages-beta.api.thegrid.ai",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "code-prime",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "code-standard",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "code-max",
"CLAUDE_CODE_SUBAGENT_MODEL": "code-standard"
}
}settings.json persists across terminal sessions and is shared with the VS Code extension. Set ANTHROPIC_BASE_URL to the host root, not the full /v1/messages path. apiKeyHelper points at the script you create in the next step, so your key never sits inline in settings.json.
2. Create the API key helper script
Create ~/.claude/thegrid_key.sh and have it print your Grid consumption API key:
3. Make the helper script executable
Claude Code runs this script and uses its stdout as the API key. If you prefer plain shell exports instead of apiKeyHelper, you can set ANTHROPIC_API_KEY along with the same variables in ~/.zshrc or ~/.bashrc.
4. (Optional) Pin specific Anthropic versions with modelOverrides
If your team needs deterministic mapping at the version level instead of family aliases, use modelOverrides:
Keys must be full Anthropic model IDs. Short aliases like sonnet are silently ignored.
5. Start Claude Code
Verification
Run a simple prompt: "Summarize this repository in two sentences." A normal response confirms Claude Code is connected. /status inspects current settings.
Troubleshooting
403 from /v1/messages. First, verify the key works directly:
If that succeeds but Claude Code still 403s on an HTML page, restart Claude Code after editing settings.json. The beta endpoint can also surface 403s when Claude Code tries unsupported secondary endpoints during startup.
Model mapping not working. Check the instrument names against the current instruments list, confirm settings.json is valid JSON (a trailing comma breaks it), and restart Claude Code after any change.
Key helper not picked up. Confirm ~/.claude/thegrid_key.sh is executable (chmod +x), prints only the key (no extra output), and that apiKeyHelper sits at the top level of settings.json, not inside env. Restart Claude Code after changes.
Last updated
Was this helpful?