Use Claude Code with InferFoundry¶
Claude Code is Anthropic's agentic coding tool that works directly in your terminal. By routing it through InferFoundry, you get access to Claude models hosted in your region — with your data staying in your chosen geography and your usage tracked through your InferFoundry workspace.
Why use Claude Code with InferFoundry?¶
Data residency. Claude Code requests are processed through your regional InferFoundry endpoint. Pick Switzerland, Germany, the US, Australia, or the UK.
Team budget controls. Set spending limits per team, user, and key from portal.dev.if-service.ai. No surprise invoices.
Usage visibility. All Claude Code activity shows up in your InferFoundry usage dashboard — per key, per user, per team.
Quick start¶
Step 1 — Install Claude Code¶
Step 2 — Get your endpoint and key¶
Log in at portal.dev.if-service.ai, go to your workspace, and copy:
- Your API endpoint:
https://gateway.dev.if-service.ai - Your API key
Step 3 — Connect Claude Code to InferFoundry¶
Add these environment variables to your shell profile (~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish):
export INFERFOUNDRY_API_KEY="your-api-key-here"
export ANTHROPIC_BASE_URL="https://gateway.dev.if-service.ai"
export ANTHROPIC_AUTH_TOKEN="$INFERFOUNDRY_API_KEY"
export ANTHROPIC_API_KEY="" # must be explicitly empty
Then reload your shell:
ANTHROPIC_API_KEY must be empty — not unset
Claude Code falls back to direct Anthropic authentication if this variable is unset. Set it to an empty string "" to prevent that.
If you were previously logged in to Anthropic
Run /logout inside a Claude Code session to clear cached credentials before the new config takes effect.
Step 4 — Start a session¶
Step 5 — Verify¶
Run /status inside Claude Code:
You can also check portal.dev.if-service.ai → Usage to see requests appearing in real time.
How it works¶
InferFoundry's API gateway speaks the same protocol as the Anthropic API. When you set ANTHROPIC_BASE_URL, Claude Code routes all requests to your InferFoundry endpoint instead of Anthropic's servers. No local proxy needed.
Configuring models¶
Claude Code uses different models for different task types. You can pin each role to a specific model:
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5"
export CLAUDE_CODE_SUBAGENT_MODEL="claude-sonnet-4-5"
| Variable | Used for |
|---|---|
ANTHROPIC_DEFAULT_OPUS_MODEL |
Complex reasoning tasks |
ANTHROPIC_DEFAULT_SONNET_MODEL |
General coding |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
Quick completions |
CLAUDE_CODE_SUBAGENT_MODEL |
Sub-agents spawned during a session |
Add these to the same shell profile as your ANTHROPIC_BASE_URL.
See Available Models for the full list.
GitHub Actions¶
To use InferFoundry in the Claude Code GitHub Action:
- name: Run Claude Code
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.INFERFOUNDRY_API_KEY }}
env:
ANTHROPIC_BASE_URL: https://gateway.dev.if-service.ai
Store your key as a GitHub secret named INFERFOUNDRY_API_KEY.
Troubleshooting¶
- Auth errors / "invalid API key"
- Make sure
ANTHROPIC_API_KEYis set to""(empty string), not unset. Runecho $ANTHROPIC_API_KEY— it should print nothing. If it prints a key value, something in your shell config is still setting it. - Requests going to Anthropic instead of InferFoundry
- Run
/logoutin Claude Code, then verifyANTHROPIC_BASE_URLis set correctly withecho $ANTHROPIC_BASE_URL. - Model not found
- Check Available Models. Use the exact model ID shown there. Model availability depends on your region and plan.
- Context length errors
- Break the task into smaller chunks or start a fresh session (
/clear).