Skip to content

DocsCoding agents

Claude Code

Point Claude Code at Osarai's Anthropic-compatible endpoint and run it on your own GPU.

Claude Code is Anthropic's coding agent for the terminal. It speaks the Anthropic Messages API, which Osarai serves at https://osarai.xyz/v1/messages, so it connects like any LLM gateway: with a base URL and a key.

Claude Code answering on qwen3.8-27b through the Osarai Messages endpoint
Claude Code running on an Osarai instance.

Install

Terminal
npm install -g @anthropic-ai/claude-code

Configure

Terminal
export ANTHROPIC_BASE_URL="https://osarai.xyz"
export ANTHROPIC_AUTH_TOKEN="$OSARAI_API_KEY"
export ANTHROPIC_MODEL="qwen3.8-27b"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.8-27b"
export CLAUDE_CODE_SUBAGENT_MODEL="qwen3.8-27b"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=131072
VariableWhy
ANTHROPIC_BASE_URLSends requests to Osarai. Use the site address, without /v1
ANTHROPIC_AUTH_TOKENYour key, sent as Authorization: Bearer (ANTHROPIC_API_KEY works too, sent as x-api-key)
ANTHROPIC_MODELThe model for the session: your instance's model id
ANTHROPIC_DEFAULT_HAIKU_MODELBackground tasks such as session titles also go to your model
CLAUDE_CODE_SUBAGENT_MODELSubagents use your model too
CLAUDE_CODE_MAX_CONTEXT_TOKENSThe real context window, so Claude Code compacts in time (it assumes 200K for models it does not know)

Keep the key out of a project's .claude/settings.json, which is usually committed.

Check the connection

Terminal
curl "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "qwen3.8-27b", "max_tokens": 64, "messages": [{"role": "user", "content": "Hi"}]}'

A JSON answer starting with {"id":"msg_ means the URL and key work. Then start Claude Code in your project and run /status: the Anthropic base URL line shows Osarai.

Terminal
cd your-project
claude

What works

FeatureStatus
Chat, streamingWorks
Tool use (read, edit, bash, search)Works with models that call tools (qwen3.8-27b)
ThinkingWorks; shown as thinking blocks
Images in promptsWorks on models with image input
Token counting (/context)Works through /v1/messages/count_tokens
/model pickerSet CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 to list your instance's models
Web search, fast mode, Claude-only betasNot available

Troubleshooting

SymptomFix
Claude Code asks you to log inSet ANTHROPIC_AUTH_TOKEN in the shell or ~/.claude/settings.json before starting it
401Wrong variable: with ANTHROPIC_API_KEY approve the key once in /config, or use ANTHROPIC_AUTH_TOKEN
Claude Code doesn't recognize the modelExpected for open models; set CLAUDE_CODE_MAX_CONTEXT_TOKENS to silence the context warning
400 naming an unknown fieldSet CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
529 overloaded or 503The instance is starting or stopped; check the instance page