# Claude Code

Use eWest models in the Claude Code terminal agent.

Claude Code talks to eWest over the Anthropic Messages API (`/v1/messages`). Point it at `https://api.ewest.ai`, give it your eWest key, and pick `ewest/claude-*` models.

## Setup

Set `ANTHROPIC_BASE_URL` to `https://api.ewest.ai`, **without** `/v1`, and your key in `ANTHROPIC_AUTH_TOKEN`, which Claude Code sends as `Authorization: Bearer`. `ANTHROPIC_API_KEY` works too (sent as `x-api-key`); in an interactive session Claude Code asks once before using it. Set one of the two, not both.

Shell exports last for one terminal. To keep the settings, put them in the `env` block of `~/.claude/settings.json`. Never put your key in a project's `.claude/settings.json`: that file is committed.

Shell:

```bash
# ANTHROPIC_AUTH_TOKEN is sent as "Authorization: Bearer". No /v1 on the base URL.
export ANTHROPIC_BASE_URL=https://api.ewest.ai
export ANTHROPIC_AUTH_TOKEN="$EWEST_KEY"
export ANTHROPIC_MODEL=ewest/claude-sonnet
claude
```

~/.claude/settings.json:

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.ewest.ai",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_EWEST_KEY",
    "ANTHROPIC_MODEL": "ewest/claude-sonnet",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "ewest/claude-opus",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "ewest/claude-sonnet",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "ewest/claude-haiku"
  }
}
```

## Choose a model

`ANTHROPIC_MODEL` is the main model. The `ANTHROPIC_DEFAULT_OPUS_MODEL`, `_SONNET_` and `_HAIKU_` variables decide what the opus, sonnet and haiku aliases mean; the haiku one also runs background tasks such as session titles, so a cheap model there saves money.

- Every name needs the `ewest/` prefix: `ewest/claude-sonnet` works, `claude-sonnet` returns `404`.
- `ewest/claude-opus` for the hardest tasks, `ewest/claude-sonnet` for everyday coding, `ewest/claude-haiku` for fast, cheap work. The full list is in [Models](https://ewest.ai/docs/models).
- With `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`, the `/model` picker also lists the `ewest/claude-*` models your key may use (Claude Code reads them from `GET /v1/models`).

Shell:

```bash
# The main model, and what the opus / sonnet / haiku aliases and background tasks use.
export ANTHROPIC_MODEL=ewest/claude-sonnet
export ANTHROPIC_DEFAULT_OPUS_MODEL=ewest/claude-opus
export ANTHROPIC_DEFAULT_SONNET_MODEL=ewest/claude-sonnet
export ANTHROPIC_DEFAULT_HAIKU_MODEL=ewest/claude-haiku

# One session on another model:
claude --model ewest/claude-opus
```

## Verify it works

`claude -p` sends one prompt and prints the answer. In an interactive session, `/status` shows the `Anthropic base URL` and which key variable is active. If Claude Code fails, try the cURL request: it uses the same key and model without Claude Code.

Every response has an `x-request-id` header; paste it into the console under Requests to see the request ([trace IDs](https://ewest.ai/docs/traces)).

Claude Code:

```bash
export ANTHROPIC_BASE_URL=https://api.ewest.ai
export ANTHROPIC_AUTH_TOKEN="$EWEST_KEY"
claude -p "Reply with the single word OK" --model ewest/claude-sonnet
```

cURL:

```bash
# The same request without Claude Code: if this fails, the key or model is the problem.
curl https://api.ewest.ai/v1/messages \
  -H "x-api-key: $EWEST_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "ewest/claude-haiku", "max_tokens": 32, "messages": [{"role": "user", "content": "Reply with the single word OK"}]}'
```

## Streaming and tools

Nothing to set up: Claude Code always streams, and runs its tools (reading and editing files, shell commands) through tool calling on `/v1/messages`. In scripts, `--output-format stream-json --verbose` prints every event, including tool calls, as a JSON line.

Claude Code:

```bash
export ANTHROPIC_BASE_URL=https://api.ewest.ai
export ANTHROPIC_AUTH_TOKEN="$EWEST_KEY"
# Streams every event (text, tool calls, tool results) as JSON lines.
claude -p "How many files are in this folder? Use ls." \
  --model ewest/claude-sonnet \
  --allowedTools "Bash(ls:*)" \
  --output-format stream-json --verbose
```

## Troubleshooting

- `401`: the key is missing, mistyped or revoked. Copy it again from [API keys](https://ewest.ai/keys). Run `/status` to see which variable Claude Code uses, and set only one of `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_API_KEY`.
- `404` with `model_not_found`: the model name needs the `ewest/` prefix (`ewest/claude-haiku`, not `claude-haiku`) and must be in [Models](https://ewest.ai/docs/models).
- `400` naming `context_management`, `output_config` or `Extra inputs are not permitted`: set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`.
- `400` with `output_config.effort is not supported by this model`: Claude Code sends an effort setting that `ewest/claude-haiku` does not take on `/v1/messages`. Use `ewest/claude-sonnet` or `ewest/claude-opus` as the main model. `ewest/claude-haiku` is the exception on `/v1/messages`, even though its `reasoning_efforts` list effort values for other endpoints.
- Claude Code asks you to log in although the key is set: put `ANTHROPIC_AUTH_TOKEN` in your shell or in `~/.claude/settings.json`, not only in a project settings file.
- Harmless, nothing to fix: the first request of a session can get a `400` saying role `system` is not supported, which Claude Code retries by itself; a warning that the model is not recognized; and a cost estimate inside Claude Code that differs from your eWest usage. Your real cost is in the console under Usage.

Shell:

```bash
# 400 errors naming context_management, output_config or "Extra inputs are not permitted":
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1

# 401 errors: your key is in a header eWest does not read. Use one of these, not both:
export ANTHROPIC_AUTH_TOKEN="$EWEST_KEY"   # sent in the Authorization header
# export ANTHROPIC_API_KEY="$EWEST_KEY"    # sent as x-api-key (approve it once in /config)

# See what Claude Code uses: run /status inside Claude Code, or list the models your key may call:
curl -H "Authorization: Bearer $EWEST_KEY" https://api.ewest.ai/v1/models
```

Still stuck? Follow [Troubleshoot a request](https://ewest.ai/docs/troubleshooting).

Source: https://ewest.ai/docs/guides/claude-code
