Skip to main content

Claude Code

Route Claude Code through LeanMCP AI Gateway. Every request gets logged — prompts, responses, token usage — visible in your dashboard in real time. Takes 2 minutes to set up.

Before you start

You need two things:
1

A LeanMCP account with credits

Go to app.leanmcp.com/billing to top up credits. Credits are required before the gateway will accept requests.
2

An API key

Go to app.leanmcp.com/api-keysCreate API Key → select SDK permissions → copy the key immediately (shown once only).Your key format: leanmcp_859fc75e...
Already have a key and credits? Skip straight to Configuration below.

Configuration

Claude Code reads environment variables from ~/.claude/settings.json. You’re pointing it at the LeanMCP gateway instead of Anthropic directly.
1

Find your settings file

OSPath
macOS / Linux~/.claude/settings.json
WindowsC:\Users\<username>\.claude\settings.json
If the file doesn’t exist, create it.
2

Add the gateway config

Add (or merge) the env block into your settings.json:
settings.json
{
  "autoUpdatesChannel": "latest",
  "env": {
    "ANTHROPIC_BASE_URL": "https://aigateway.leanmcp.com/v1/anthropic",
    "ANTHROPIC_AUTH_TOKEN": "leanmcp_your_api_key_here",
    "ANTHROPIC_API_KEY": ""
  }
}
Set ANTHROPIC_API_KEY to an empty string "". If both keys are present, they conflict and requests will fail.
3

Verify it works

Run any Claude Code command as normal:
claude "say hello"
Then open your dashboard at app.leanmcp.com/observability. You should see the request appear within a few seconds.If you see the log entry: you’re done. ✓

What you’ll see in the dashboard

Once configured, go to app.leanmcp.com/observability. Every Claude Code request is tracked:
FieldWhat it shows
Request BodyFull content sent to the AI
Response BodyComplete response received
ModelWhich model was used
TokensInput, output, and total token counts
LatencyResponse time in milliseconds
StatusSuccess or error
TimestampWhen the request was made

Troubleshooting

  1. Double-check ANTHROPIC_BASE_URL is exactly https://aigateway.leanmcp.com/v1/anthropic with no trailing slash
  2. Confirm ANTHROPIC_API_KEY is set to "" — a leftover value will bypass the gateway
  3. Confirm your account has credits at app.leanmcp.com/billing — zero credits means requests are rejected
Your ANTHROPIC_AUTH_TOKEN is wrong or the key was deleted. Go to app.leanmcp.com/api-keys, create a new key, and update settings.json.
Remove the env block from settings.json and restore your ANTHROPIC_API_KEY. The gateway is a proxy — removing it has no side effects.You can also set env vars in your shell profile as an alternative to settings.json:
export ANTHROPIC_BASE_URL="https://aigateway.leanmcp.com/v1/anthropic"
export ANTHROPIC_AUTH_TOKEN="leanmcp_your_api_key_here"
export ANTHROPIC_API_KEY=""

Next steps

View your logs

Open the dashboard to see your Claude Code sessions.

Observability features

What gets logged, sensitive data detection, export options, and alerts.

Use with other tools

Also using Cursor, Windsurf, or Cline? Connect them all to the same gateway.

For teams

Route your whole team through a shared gateway.