Use Claude Code with MagicAI
Overview
Claude Code is Anthropic's agentic coding tool for the terminal. MagicAI serves the Anthropic Messages API at https://magicai.lol/v1/messages (streaming and tool use included), so Claude Code can run on your MagicAI credits with no Anthropic account. You point two environment variables at MagicAI and pin every model tier to claude-opus-4-6, the Claude model currently live on MagicAI.
Prerequisites
- macOS 13+, Ubuntu 20.04+, Debian 10+, Alpine 3.19+, or Windows 10 1809+ / Server 2019+ (native or WSL).
- 4 GB+ RAM, x64 or ARM64 CPU, and outbound HTTPS to
magicai.lol(plusclaude.ai/downloads.claude.aifor installing). - A MagicAI account with credits. Claude Code sends a lot of context per request, so start with at least $5.
Install
Use Anthropic's native installer (recommended; it auto-updates):
# macOS, Linux, WSL curl -fsSL https://claude.ai/install.sh | bash # Windows PowerShell irm https://claude.ai/install.ps1 | iex
Then open a new shell and check it:
claude --version
Alternatives: brew install --cask claude-code, winget install Anthropic.ClaudeCode, Anthropic's signed apt/dnf/apk repositories, or npm install -g @anthropic-ai/claude-code (Node.js 22+, no sudo). If claude isn't found, add ~/.local/bin to your PATH. See the official setup guide.
Get an API key
- Sign in at magicai.lol/dashboard and add credits under Credits.
- Under API keys, create a key (or use an existing one) and click Copy. Keys start with
sk-.
Treat the key like a password. On shared servers, prefer a dedicated key per machine so you can revoke it on its own.
Configure
Option A: settings file (recommended). Create ~/.claude/settings.json. Claude Code reads it on every launch, however it was started:
{
"env": {
"ANTHROPIC_BASE_URL": "https://magicai.lol",
"ANTHROPIC_AUTH_TOKEN": "sk-your-magicai-key",
"ANTHROPIC_MODEL": "claude-opus-4-6",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-6",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-opus-4-6",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-opus-4-6",
"CLAUDE_CODE_SUBAGENT_MODEL": "claude-opus-4-6",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
}
}chmod 600 ~/.claude/settings.json
Option B: environment variables. Put these in ~/.bashrc / ~/.zshrc, or in your service's environment:
export ANTHROPIC_BASE_URL="https://magicai.lol" export ANTHROPIC_AUTH_TOKEN="sk-your-magicai-key" export ANTHROPIC_MODEL="claude-opus-4-6" export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-6" export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-opus-4-6" export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-opus-4-6" export CLAUDE_CODE_SUBAGENT_MODEL="claude-opus-4-6" export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
If both are set, the settings file usually wins. What each one does:
ANTHROPIC_BASE_URL: send requests to MagicAI instead of Anthropic. Usehttps://magicai.lolwith no/v1. Claude Code adds the path itself.ANTHROPIC_AUTH_TOKEN: your MagicAI key, sent asAuthorization: Bearer. You can useANTHROPIC_API_KEYinstead (sent asx-api-key; MagicAI accepts both). In interactive mode Claude Code asks you once to approve anANTHROPIC_API_KEY. Don't set both.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: optional. Turns off auto-updates, telemetry, error reporting and feedback calls to Anthropic. Leave it out if you want the native installer to auto-update, or runclaude updateyourself.
If you have previously signed in with a Claude subscription, a gateway token set this way takes over for requests, and subscription limits don't apply.
Model selection
Claude Code uses aliases (opus, sonnet, haiku). It also uses the Haiku-class model for background work such as session titles. MagicAI only serves claude-opus-4-6 right now, so the config above maps every alias and subagents to it. A model that isn't mapped would fail with “model not found”.
ANTHROPIC_MODEL: the main session model.ANTHROPIC_DEFAULT_OPUS_MODEL/_SONNET_MODEL/_HAIKU_MODEL: what each alias resolves to (Haiku also handles background tasks).ANTHROPIC_SMALL_FAST_MODELis deprecated; useANTHROPIC_DEFAULT_HAIKU_MODEL.CLAUDE_CODE_SUBAGENT_MODEL: the default model for subagents.
To save cost, you can stop the background title request with CLAUDE_CODE_DISABLE_TERMINAL_TITLE=1. See the model catalog for what's live.
Verify
mkdir -p ~/cc-test && cd ~/cc-test claude -p "Reply with just: OK"
You should see OK, and the request should appear under Usage in your dashboard as claude-opus-4-6. Then run claude in a project for an interactive session, and use /status to confirm the base URL and model. claude doctor checks your install and settings.
Cost
Claude Opus 4.6 costs $5 per 1M input tokens and $25 per 1M output tokens. That's the list price, with no markup. Prompt caching is billed the Anthropic way: cache writes cost more than normal input, and cache reads cost much less. Claude Code sends a large system prompt and tool schema with each request, roughly 30K tokens.
- In our test, the first request of a session cost about $0.19 (writing ~30K tokens to cache). The follow-up turn cost about $0.02 (a cache read).
- A short two-turn task (create a file, then reply) cost $0.20 in total. Long agentic sessions on big repos can cost several dollars.
Cache entries last only a few minutes, so a session you resume after a break pays the cache write again. Keep an eye on Usage in your dashboard. A dedicated key with only the credits you plan to spend is a simple way to cap spending.
Troubleshooting
- 401 / “invalid token”: the key is wrong, disabled or expired. Copy it again from the dashboard (the full key starts with
sk-, not the masked one), and check there's no strayANTHROPIC_API_KEYleft from an older setup (env | grep ANTHROPIC). - 403 / “insufficient quota” or balance errors: your credits are used up, or the key's own quota is reached. Top up under Credits, or raise the key's limit.
- “model not found” / no available channel: some alias still points to a model MagicAI doesn't serve (for example a Sonnet or Haiku ID). Set all the model variables above to
claude-opus-4-6, then restartclaude. - 404 on every request:
ANTHROPIC_BASE_URLprobably ends in/v1. Usehttps://magicai.lol. - 429: you hit a rate limit. Claude Code retries automatically. If it keeps happening, slow down parallel sessions.
- 400 “invalid beta flag” or “Extra inputs are not permitted”: MagicAI already filters out the beta features its upstream doesn't support, so this shouldn't happen. If it does, please tell us. As a client-side workaround, set
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1, which stops Claude Code from sending pre-release beta headers and fields. - It still asks you to log in: the token variable isn't reaching Claude Code. Check the JSON in
~/.claude/settings.jsonis valid (claude doctor).
Still stuck? Email support@magicai.lol with the time of the request and the error text (never send your key).
Claude and Claude Code are products of Anthropic. MagicAI is an independent gateway and isn't affiliated with Anthropic.