> ## Documentation Index
> Fetch the complete documentation index at: https://docs.snapgen.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

> Connect Claude Code to SnapGen through the Anthropic Messages-compatible gateway.

Claude Code can connect to an LLM gateway through `ANTHROPIC_BASE_URL` and a bearer token. SnapGen exposes `POST /v1/messages` and model discovery for this workflow.

<Note>
  Anthropic documents gateway connectivity but does not officially support
  routing Claude Code to non-Claude models. SnapGen currently converts Claude
  Messages requests to its GPT routes; retest after major Claude Code upgrades.
</Note>

## Prerequisites

* Install Claude Code and confirm `claude --version` works.
* Create a SnapGen API key and add prepaid balance.
* Choose a current text model, such as `gpt-5.4-mini` or `gpt-5.5`.

## Configure the current shell

```bash theme={null}
export ANTHROPIC_BASE_URL="https://api.snapgen.org"
export ANTHROPIC_AUTH_TOKEN="$SNAPGEN_API_KEY"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
```

Use `ANTHROPIC_AUTH_TOKEN`, not `ANTHROPIC_API_KEY`. SnapGen expects `Authorization: Bearer ...`; Claude Code sends that header for `ANTHROPIC_AUTH_TOKEN`.

## Verify the gateway

Test the Messages endpoint before starting Claude Code.

```bash theme={null}
curl "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "gpt-5.4-mini",
    "max_tokens": 16,
    "messages": [{"role": "user", "content": "Reply with OK."}]
  }'
```

A successful response has `type: "message"` and text under `content[0].text`.

## Start Claude Code

```bash theme={null}
claude --model gpt-5.4-mini
```

Run `/status` inside Claude Code. Confirm that the Anthropic base URL is `https://api.snapgen.org` and the credential source is `ANTHROPIC_AUTH_TOKEN`.

## Persist the configuration

Add the gateway variables to the `env` object in `~/.claude/settings.json`:

```json theme={null}
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.snapgen.org",
    "ANTHROPIC_AUTH_TOKEN": "sk-xxxx",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  }
}
```

Prefer a shell secret manager or managed settings for production teams. Do not put the key in a repository's `.claude/settings.json`.

## Troubleshooting

<AccordionGroup>
  <Accordion title="Claude Code shows a login screen">
    Start it from the shell where `ANTHROPIC_AUTH_TOKEN` is exported, or place
    the variables in the user-level `~/.claude/settings.json` file.
  </Accordion>

  <Accordion title="The model is missing from /model">
    Set `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`, restart Claude Code, and
    confirm that [`GET /v1/models`](/api-reference/list-models) returns the ID.
  </Accordion>

  <Accordion title="A new Claude Code version sends unsupported fields">
    Update the gateway when available. As a temporary diagnostic, set
    `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` and retry.
  </Accordion>

  <Accordion title="Requests return 401">
    Confirm the key is active and assigned to `ANTHROPIC_AUTH_TOKEN`. A key in
    `ANTHROPIC_API_KEY` is sent through `x-api-key`, which SnapGen does not use.
  </Accordion>
</AccordionGroup>
