Claude Code setup
Claude Code (Anthropic's CLI coding agent) speaks the Anthropic protocol. The
Mafdet AI gateway serves it natively on /v1/messages, so Claude Code works by
setting environment variables only — no config file changes.
Configuration
Add to your shell profile (or run in a terminal), then start claude:
export ANTHROPIC_BASE_URL="https://api.mafdet.ai"
export ANTHROPIC_AUTH_TOKEN="sk-mafdet-xxxxxxxxxxxxxxxx"
export ANTHROPIC_MODEL="deepseek-v4-pro"
export ANTHROPIC_SMALL_FAST_MODEL="deepseek-v4-flash"
claude
ANTHROPIC_BASE_URLmust not include/v1— Claude Code appends/v1/messagesitselfANTHROPIC_AUTH_TOKENis your Mafdet AI key (prefer an environment variable over pasting it into files)ANTHROPIC_MODELis a Mafdet AI model ID (see Models overview); coding-capable models such as the DeepSeek V4 or Kimi families work bestANTHROPIC_SMALL_FAST_MODELhandles Claude Code's lightweight background calls — a cheap fast model keeps costs down
You can also generate this snippet pre-filled with your model from
Console → API Keys → Developer Tools. Usage over /v1/messages is billed
the same way as the OpenAI-compatible endpoint.
Common errors
| Symptom | Meaning | Fix |
|---|---|---|
| 401 | Wrong key or bad format | Check ANTHROPIC_AUTH_TOKEN |
| 404 | Base URL includes /v1 | Use https://api.mafdet.ai (no /v1) |
| 429 | Rate limited (RPM/TPM) | Coding agents need a key with a high TPM limit |
insufficient_credit | Out of balance | See Balance & usage |