Claude Code

Claude Code speaks the Anthropic messages format, which Foglare serves at /v1/messages. Point ANTHROPIC_BASE_URL at the gateway root and pick a Foglare model id.

Prerequisites

  • Claude Code installed (claude on your PATH).
  • No Anthropic account needed; Claude Code only requires that some token value exists.
  • Optional: a Foglare API key (sk-fog-…) from the dashboard, used as the auth token below for per-key usage stats. Without one, any placeholder works and calls run anonymously on the shared pool.
  • A model id: auto:fast to start, or any id from GET /v1/models.

Configuration

The base URL is the gateway root without /v1: Claude Code appends /v1/messages itself. Put this in ~/.claude/settings.json (%USERPROFILE%\.claude\settings.json on Windows):

~/.claude/settings.json

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.foglare.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-fog-YOUR_KEY",
    "ANTHROPIC_MODEL": "auto:fast",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "auto:fast",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "auto:M",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "auto:XL"
  }
}
Variable Value Why
ANTHROPIC_BASE_URLhttps://api.foglare.comGateway root, no /v1 suffix.
ANTHROPIC_AUTH_TOKENsk-fog-YOUR_KEYYour Foglare API key, sent as a bearer token. Any placeholder also works (anonymous).
ANTHROPIC_MODELauto:fastMain model. Overrides the settings "model" key.
ANTHROPIC_DEFAULT_*_MODELauto:fast / auto:M / auto:XLMaps the haiku/sonnet/opus aliases, so background tasks and /model switches stay on Foglare ids.

Prefer shell variables for a one-off session? Same values, exported before launch:

Shell (macOS, Linux, WSL)

export ANTHROPIC_BASE_URL="https://api.foglare.com"
export ANTHROPIC_AUTH_TOKEN="sk-fog-YOUR_KEY"
export ANTHROPIC_MODEL="auto:fast"
claude

Values in a settings file env block override shell exports. Config format verified against the Claude Code settings and environment-variable reference.

Verify

First check the endpoint from your shell, then start claude and send a message. The curl output should stream message_start, content_block_delta events and message_stop.

curl the messages endpoint

curl -N https://api.foglare.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-fog-YOUR_KEY" \
  -d '{"model":"auto:fast","max_tokens":1024,"stream":true,"messages":[{"role":"user","content":"Hello"}]}'

Expected stream (trimmed)

event: message_start
data: {"type":"message_start","message":{"id":"fglr_...","model":"auto:fast","role":"assistant"}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}

event: message_stop
data: {"type":"message_stop"}

List accepted model ids (trimmed response)

curl https://api.foglare.com/v1/models

{
  "object": "list",
  "data": [
    { "id": "deepseek-v4.1-flash", "object": "model", "created": 1763769600, "owned_by": "foglare" },
    { "id": "qwen4-max", "object": "model", "created": 1763769600, "owned_by": "foglare" },
    { "id": "auto:fast", "object": "model", "created": 1763769600, "owned_by": "foglare" }
  ]
}

Troubleshooting

Symptom Fix
404, model not found The model id is not in the catalog. List accepted ids with GET /v1/models. Tier ids are auto:fast, auto:S, auto:M, auto:L, auto:XL; direct ids carry no suffix.
404 on the endpoint path The base URL is wrong for this tool. Check whether it expects the root (https://api.foglare.com) or the versioned root (https://api.foglare.com/v1); the configuration table above says which.
503, capacity exhausted All upstream routes are busy or rate-limited. The error message says when to retry. Retry after that window, or switch to a routing tier so the gateway picks healthy capacity.
Output arrives all at once, or the stream hangs Something between you and the gateway is buffering SSE. Use curl -N, disable proxy buffering (nginx: proxy_buffering off), and read the response as a stream instead of waiting for the full body.
Claude Code still asks to sign in The env block did not load. Run /status inside Claude Code to see which settings files loaded; check the JSON is valid (no comments, no trailing commas).
Requests go to Anthropic, not Foglare A stale ANTHROPIC_BASE_URL or a managed settings file overrides yours. /status lists the active sources. The env block in ~/.claude/settings.json wins over shell exports.
Background tasks fail with unknown model Claude Code sends its haiku alias for small jobs. Set ANTHROPIC_DEFAULT_HAIKU_MODEL to auto:fast as shown above.