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

# API Reference

> BetterToken endpoints, authentication, and protocol-specific setup.

## Endpoints

BetterToken now uses two different endpoints by protocol:

| Scenario                                   | Base URL                        | Protocol                        |
| ------------------------------------------ | ------------------------------- | ------------------------------- |
| Claude Code / `ANTHROPIC_BASE_URL`         | `https://www.bettertoken.ai`    | Anthropic                       |
| Codex / `OPENAI_BASE_URL` / external tools | `https://www.bettertoken.ai/v1` | OpenAI-style / OpenAI Responses |

<Warning>
  Do not keep using one shared endpoint for every protocol.
</Warning>

## Authentication and examples

Pass your BetterToken API Key with the request:

<Tabs>
  <Tab title="Claude Code / Anthropic">
    ```python theme={null}
    import anthropic

    client = anthropic.Anthropic(
        base_url="https://www.bettertoken.ai",
        api_key="YOUR_API_KEY",
    )

    message = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Hello"}],
    )
    ```

    ```bash theme={null}
    curl https://www.bettertoken.ai/messages       -H "x-api-key: YOUR_API_KEY"       -H "anthropic-version: 2023-06-01"       -H "content-type: application/json"       -d '{ ... }'
    ```
  </Tab>

  <Tab title="Codex / OpenAI Responses">
    ```python theme={null}
    from openai import OpenAI

    client = OpenAI(
        base_url="https://www.bettertoken.ai/v1",
        api_key="YOUR_API_KEY",
    )

    response = client.responses.create(
        model="Codex group model ID copied from https://www.bettertoken.ai/pricing",
        input="Hello",
    )
    ```

    ```bash theme={null}
    curl https://www.bettertoken.ai/v1/chat/completions       -H "Authorization: Bearer YOUR_API_KEY"       -H "content-type: application/json"       -d '{ ... }'
    ```
  </Tab>
</Tabs>

## Model selection rules

* **Claude Code + `Claude_*` keys**: do not set model variables manually; only configure `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN`
* **Claude Code + `Codex_*` keys**: add model mappings through `ANTHROPIC_DEFAULT_HAIKU_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, and `ANTHROPIC_DEFAULT_OPUS_MODEL`
* **Codex**: use a model ID copied from the **Codex group** in the model plaza (`https://www.bettertoken.ai/pricing`)
* **External tools**: also use **Codex group** model IDs instead of fixed Claude model names

<Note>
  For external tools, you usually only need the `Base URL`, API key, and model specified by that tool's official docs. Only add extra headers when the tool itself or your upstream gateway explicitly requires them.
</Note>

## Environment variable reference

| Variable                                   | Value                           | Usage                              |
| ------------------------------------------ | ------------------------------- | ---------------------------------- |
| `ANTHROPIC_BASE_URL`                       | `https://www.bettertoken.ai`    | Claude Code                        |
| `ANTHROPIC_AUTH_TOKEN`                     | Your API Key                    | Claude Code auth                   |
| `OPENAI_BASE_URL`                          | `https://www.bettertoken.ai/v1` | Codex and other OpenAI-style tools |
| `OPENAI_API_KEY`                           | Your API Key                    | OpenAI-style tool auth             |
| `API_TIMEOUT_MS`                           | `3000000`                       | Recommended for long tasks         |
| `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` | `1`                             | Claude Code only                   |
