BETA
How to connect Claude Code to Apily
Claude Code talks to model providers over the Anthropic Messages protocol by default. Apily serves that protocol natively at https://apily.pro, so point Claude Code at it with ANTHROPIC_BASE_URL/ANTHROPIC_API_KEY — no openai_compatible shim required. (That OpenAI-compatible path still works too, if you'd rather use it — see the alternative below.)
https://apily.proapily_your-api-keyANTHROPIC_BASE_URL / ANTHROPIC_API_KEYRequirements
- macOS, Linux or Windows with a terminal.
- Node.js 18+ (or the standalone installer from Anthropic).
- An Apily API key — created in your account at apily.pro.
- Outbound HTTPS access to
apily.pro.
Install Claude Code
npm install -g @anthropic-ai/claude-code
claude --versionGet an API key
- Sign in at apily.pro (Telegram, Google or email) and open your account.
- Open API in the sidebar and press Generate. The examples below use the placeholder
apily_your-api-key— paste your real key in its place. - Copy the key whole, including the
apily_prefix. Never publish a real key in repositories or screenshots.
Configuration
Set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY before launching Claude Code — in your shell profile, or inline for one session:
export ANTHROPIC_BASE_URL="https://apily.pro"
export ANTHROPIC_API_KEY="apily_your-api-key"
claudeOr persist the same two values under env in ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_BASE_URL": "https://apily.pro",
"ANTHROPIC_API_KEY": "apily_your-api-key",
"ANTHROPIC_MODEL": "claude-sonnet-5"
}
}- Set the two environment variables (shell export or
settings.json), replacing the key with your own. - If you were previously signed in with an Anthropic subscription, run
claudeand then/logoutonce — a saved login can override the configured base URL. - Restart the terminal session and launch
claudein a project folder. Ask it anything — requests now go through Apily.
Your first request
Before starting the agent, confirm the key and model both work with a single curl call:
curl https://apily.pro/v1/messages \
-H "x-api-key: apily_your-api-key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model":"claude-opus-5","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}'A JSON response with a "content" field means the key is valid, the model is allowed and the upstream is reachable. Then send any message inside claude.
Switching models
Change the model with /model inside a session, or the --model flag. The base URL and key stay the same. Check the current catalog on the Models page in your account, or with GET /v1/models — for example:
claude-opus-5·claude-sonnet-5·gpt-5.6-soldeepseek-v4-flash-0731·gemini-3.5-flash·grok-4.7
Common errors and how to fix them
| Symptom | Cause | Fix |
|---|---|---|
401 Invalid API key | Key copied with stray spaces, truncated, or revoked. | Copy the key whole from the API page in your Apily account, the apily_ prefix included. |
401 Missing API key | No auth header was sent. | Apily accepts Authorization: Bearer … and x-api-key: …. |
403 Email not verified | Your Apily account's email address isn't verified yet. | Verify your email from the banner in the Apily app, then retry. |
402 Insufficient balance | Your token balance can't cover the request's estimated cost. | Top up your balance on the Billing page in your Apily account. |
404 Not found | ANTHROPIC_BASE_URL is missing, or points somewhere other than https://apily.pro. | Base URL: https://apily.pro/v1 — every request must land on a path Apily serves (/chat/completions, /responses, /models, …). |
503 Model temporarily unavailable | The model exists, but no upstream provider is reachable right now. | Retry in a moment — it usually recovers within a minute. Switch models if it keeps happening. |