Claude Code
Run Claude Code on OhMyGPT with your OhMyGPT key, on Claude or any other model in the catalog.
Claude Code works with OhMyGPT out of the box. Set two environment variables and it runs on your OhMyGPT key, with every Claude model and the rest of the catalog one /model command away. Billing goes to your OhMyGPT balance, and you can test the whole setup for free with ohmygpt/mock.
Configure
Set the variables, then start Claude Code from the same shell:
export ANTHROPIC_BASE_URL="https://api.ohmygpt.com"
export ANTHROPIC_AUTH_TOKEN="$OHMYGPT_API_KEY"
export ANTHROPIC_MODEL="anthropic/claude-sonnet-5-5"
claudeANTHROPIC_BASE_URLhas no/v1. Claude Code appends/v1/messagesitself.ANTHROPIC_AUTH_TOKENsends your key asAuthorization: Bearer.ANTHROPIC_API_KEY(sent asx-api-key) works too, but Claude Code asks you to approve it once.ANTHROPIC_MODELis any model ID from Choose a model.
To keep the setup across terminals, put the same values in the env block of ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.ohmygpt.com",
"ANTHROPIC_AUTH_TOKEN": "sk-...",
"ANTHROPIC_MODEL": "anthropic/claude-sonnet-5-5"
}
}Keep the key out of a project's .claude/settings.json, because that file is committed with the repository. Use ~/.claude/settings.json or a git-ignored .claude/settings.local.json.
Check the connection
Send the request Claude Code sends, to the free test model ohmygpt/mock:
curl https://api.ohmygpt.com/v1/messages \
-H "Authorization: Bearer $OHMYGPT_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model": "ohmygpt/mock", "max_tokens": 64, "messages": [{"role": "user", "content": "ping"}]}'{
"id": "chatcmpl-ohmygpt-mock",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "This is a mock reply from OhMyGPT. Your integration works; switch to a real model when ready."
}
],
"model": "mock",
"stop_reason": "end_turn",
"usage": { "input_tokens": 19, "output_tokens": 17 }
}Then start claude and run /status. The Anthropic base URL line shows https://api.ohmygpt.com, and the credential line names ANTHROPIC_AUTH_TOKEN.
You can also run Claude Code itself on the mock with claude --model ohmygpt/mock. When Claude Code sends tools, the mock calls the first one and then replies with text, so you see one full turn of the agent loop at no cost. The mock is available once your account has been topped up.
Choose a model
List the models you can use with Claude Code:
curl -s https://api.ohmygpt.com/v1/models \
| jq -r '.data[] | select(.available and any(.protocols[]?; .id == "anthropic-messages")) | .id'Prices for each are on the Models page.
Claude Code is built for Claude, and anthropic/claude-* models give you the full experience. Other models in the list, such as zhipu/glm-5.3, run Claude Code too, including its tool calls and thinking settings.
Switch models inside a session with /model <model id>. Claude Code's built-in choices (opus, sonnet, haiku, fable) also work, because OhMyGPT accepts the Claude model names they send, such as claude-sonnet-5-5.
Claude Code runs some background work, such as session titles, on its Haiku-class model. To choose that model too, set:
export ANTHROPIC_DEFAULT_HAIKU_MODEL="anthropic/claude-haiku-5-5"To see OhMyGPT's Claude models in the /model picker, set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1. Claude Code then reads GET /v1/models at startup and lists every ID that contains claude or anthropic.
GitHub Actions
claude-code-action sends its anthropic_api_key input as x-api-key, which OhMyGPT accepts. Store your OhMyGPT key as a repository secret and set the base URL in env:
env:
ANTHROPIC_BASE_URL: https://api.ohmygpt.com
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.OHMYGPT_API_KEY }}Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
Every request returns 404 page not found | ANTHROPIC_BASE_URL ends in /v1, so requests go to /v1/v1/messages | Set it to https://api.ohmygpt.com |
401 with Invalid API key | The key is mistyped or was deleted | Copy a key from API keys |
| Login screen at startup | Claude Code found no credential | Export ANTHROPIC_AUTH_TOKEN in the shell that runs claude, or set it in ~/.claude/settings.json |
ANTHROPIC_API_KEY is set but not used | The key was declined at Claude Code's approval prompt | Use ANTHROPIC_AUTH_TOKEN, or enable the key under /config → Use custom API key |
404 saying the model does not exist | The ID is misspelled | Copy the ID from GET /v1/models |
402 | The balance or the key's spending limit is used up | Top up at Billing |
Every response carries an X-Request-ID header, and Usage shows what each request cost.