Guides · Claude Code

Claude Code on Layer X1.

Claude Code speaks the Anthropic Messages dialect natively — pointing it at Layer X1 is four environment variables, or one command.

One command

npx layerx1 setup --tool claude-code --key lx1_your_key

The CLI writes the config below into ~/.claude/settings.json, backs up what was there, and is safe to re-run. See CLI for everything it can do.

By hand

Set four variables — in ~/.claude/settings.json under env, or exported in your shell:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.layerx1.in",
    "ANTHROPIC_AUTH_TOKEN": "lx1_your_key",
    "ANTHROPIC_MODEL": "lx1-sonnet-4.6",
    "ANTHROPIC_SMALL_FAST_MODEL": "lx1-glm-4.7-flash"
  }
}
Either surface works — pick one
  • ANTHROPIC_BASE_URL — the gateway origin only. Do not append /v1; Claude Code adds /v1/messages itself.
  • ANTHROPIC_AUTH_TOKEN — your lx1_ key.
  • ANTHROPIC_MODEL — the main model. lx1-sonnet-4.6 for the premium ceiling (vision, top reasoning), or lx1-gpt-oss-120b for a fast everyday driver. Any catalog id works.
  • ANTHROPIC_SMALL_FAST_MODEL — the model for quick auxiliary calls; lx1-glm-4.7-flash keeps them near-free.

Verify

Start claude and run a trivial prompt. To confirm the wiring end-to-end without Claude Code in the loop:

npx layerx1 test --key lx1_your_key

Troubleshooting

  • Still using your Anthropic account? If you were signed in before, run /logout once so Claude Code picks up ANTHROPIC_AUTH_TOKEN instead of the stored session.
  • 404s on every call? The base URL probably includes /v1 — use the bare origin.
  • 401 unauthorized? The key must be in ANTHROPIC_AUTH_TOKEN (not ANTHROPIC_API_KEY) for a gateway base URL.
  • Context meter looks off? Claude Code budgets with count_tokens, which returns an estimate — billing always uses exact usage from real responses.
Note

Model choice is per-variable, so you can run the premium model as the main driver and keep the fast tier on auxiliary calls — every plan includes both.