# Claude Code

> Connect Claude Code to HeyEly using the Anthropic Messages API and your HeyEly key.

Claude Code connects over the Anthropic Messages API. Point its base URL to `https://heyely.si` (omit `/v1`) and supply your HeyEly API key as the auth token.

## Set up

1. Generate a key in [Developers](https://heyely.si/keys) and export it as `HEYELY_API_KEY`.
2. Add the HeyEly base URL, auth token, and gateway model discovery flag to your shell profile.

**macOS and Linux**

```bash
export ANTHROPIC_BASE_URL="https://heyely.si"
export ANTHROPIC_AUTH_TOKEN="$HEYELY_API_KEY"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"
```

**Windows**

```powershell
$env:ANTHROPIC_BASE_URL = "https://heyely.si"
$env:ANTHROPIC_AUTH_TOKEN = $env:HEYELY_API_KEY
$env:CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY = "1"
```

3. Launch `claude`. If you previously signed in to an Anthropic account, run `/logout` once so cached credentials do not override your HeyEly token.

Prefer not to modify your shell profile? You can place these values inside the `env` object of your user-level config at `~/.claude/settings.json` (or `%USERPROFILE%\.claude\settings.json` on Windows). Because JSON settings do not expand shell variables, paste the literal key string there.

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://heyely.si",
    "ANTHROPIC_AUTH_TOKEN": "sk-df-...",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  }
}
```

> **Keep the key out of your projects**
>
> Store credentials in your personal user settings file only, never inside a repository's `.claude/settings.json`. Note that Claude Code ignores these variables when placed in a project `.env` file.

## Verify

1. Confirm your key and endpoint with a quick smoke test. A JSON response beginning with `{"id":"msg_` confirms everything is wired up.

```bash
curl https://heyely.si/v1/messages \
  -H "Authorization: Bearer $HEYELY_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5.5",
    "max_tokens": 1,
    "messages": [{ "role": "user", "content": "." }]
  }'
```

2. Launch `claude`, send a brief test prompt, and run `/status`. You should see `https://heyely.si` listed as the Anthropic base URL alongside your auth token. If `/status` still displays a claude.ai login method, Claude Code has not loaded the token yet.
3. Want to inspect gateway model discovery directly? Start with `claude --debug` and check the discovery entries in the debug log.
4. Visit [Credit and usage](https://heyely.si/usage). Your test call appears at the top of **Spend**, and clicking the row shows Claude Code under **From**.

## Pick a model

By default, Claude Code maps shorthand classes like Opus, Sonnet, and Haiku to Anthropic's unprefixed model names. Override each class with a full HeyEly catalog ID so every request hits the right model.

| Variable                         | Sets                                                               |
| -------------------------------- | ------------------------------------------------------------------ |
| `ANTHROPIC_MODEL`                | Default model for the current session                              |
| `ANTHROPIC_DEFAULT_SONNET_MODEL` | Catalog ID mapped to Sonnet, such as `anthropic/claude-sonnet-5.5` |
| `ANTHROPIC_DEFAULT_HAIKU_MODEL`  | Catalog ID mapped to Haiku, such as `anthropic/claude-haiku-4.5`   |
| `ANTHROPIC_DEFAULT_OPUS_MODEL`   | Catalog ID mapped to Opus                                          |
| `CLAUDE_CODE_SUBAGENT_MODEL`     | Default catalog ID used for subagents                              |

* An explicit model inside a subagent definition or call takes precedence over `CLAUDE_CODE_SUBAGENT_MODEL`. On Claude Code 2.1.257 or newer, add `CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1` to lock every subagent to one ID.
* With gateway discovery turned on, `/model` displays catalog IDs matching `claude` or `anthropic`. You can still target any other catalog model by passing its full ID to `/model <id>` or `claude --model <id>`.
* For unfamiliar model IDs, Claude Code defaults to a 200K context window. Add `[1m]` to the end of the ID, such as `anthropic/claude-sonnet-5.5[1m]`, to unlock 1M context. HeyEly removes `[1m]` before catalog lookup, so the upstream provider receives the clean catalog ID.
* Claude Code is tuned around Claude models. Non-Claude catalog models still reply, though tool calling and reasoning output can vary.
* Managing a team deployment? On v2.1.285 or later, set `allowedProviders` to `["customEndpoint"]` inside Claude Code's managed settings and include `ANTHROPIC_BASE_URL` set to `https://heyely.si` in the same file's `env` block. Sessions pointed to any other host will be refused.

## Use it in other Claude clients

Both the Claude Agent SDK and the Claude Code GitHub Action honor these exact environment variables. In the VS Code extension, configure them through `claudeCode.environmentVariables` in VS Code settings rather than `settings.json`. The standalone Claude desktop app does not read `ANTHROPIC_BASE_URL`.

## Connect the MCP server

Add HeyEly's [MCP server](https://heyely.si/docs/coding-tools/mcp) so Claude Code can check your credit balance, run models inside a spend cap you pick, and create, rotate, or revoke scoped API keys after a single sign-in.

## Troubleshooting

Anthropic Messages errors return a `type` and `message` rather than an error `code`, so the table below matches on HTTP status, error type, and opening text.

| You see                                                          | Cause                                                                                        | Fix                                                                                                              |
| ---------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| Claude Code prompts for login                                    | Cached claude.ai credentials took priority, or env vars are missing                          | Run `/logout` and verify the exports in the shell launching `claude`                                             |
| Warning about two credential sources                             | Both a saved login and gateway token are active                                              | Run `/logout`, or remove one credential source                                                                   |
| `401 authentication_error`                                       | `ANTHROPIC_AUTH_TOKEN` is blank or mistyped                                                  | Re-export `ANTHROPIC_AUTH_TOKEN` from your saved key or mint a fresh one, keeping it out of logs and screenshots |
| `ANTHROPIC_API_KEY` is ignored                                   | Claude Code requires a one-time confirmation for `ANTHROPIC_API_KEY` and never prompts again | Switch to `ANTHROPIC_AUTH_TOKEN`                                                                                 |
| `404 not_found_error`, "The model ... does not exist"            | A model class variable uses a short alias instead of a catalog ID                            | Provide the full catalog ID, such as `anthropic/claude-sonnet-5.5`                                               |
| `402 billing_error`, "This account has no credit left"           | Your balance is empty                                                                        | [Add credit](https://heyely.si/credit?step=add)                                                                                   |
| `402 billing_error`, "This account has only free credit"         | Free credit cannot be spent on Claude models                                                 | [Add credit](https://heyely.si/credit?step=add), or switch to an eligible open-weight text model                                  |
| `402 billing_error`, "This API key has reached its credit limit" | Spend hit this key's configured cap                                                          | Increase the key limit in Developers or switch keys                                                              |
| Non-Claude model missing from picker                             | Gateway discovery filters to `claude` and `anthropic` IDs                                    | Pass the full ID manually via `/model`                                                                           |
| Empty model picker                                               | Discovery is disabled, or `/v1/models` timed out past 3 seconds or redirected                | Export `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`                                                            |
| `400` citing `anthropic-beta` or unknown fields                  | The target model rejects an experimental beta header                                         | Export `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`                                                                |
| Env vars appear ignored                                          | Variables were placed in a project `.env` file                                               | Move them to your shell profile or `~/.claude/settings.json`                                                     |
