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

# Track Anthropic Claude API Costs with Tokonomics Proxy

> Swap the Anthropic base URL for Tokonomics to track Claude API costs in real time — your request format and streaming stay exactly the same.

Tokonomics proxies your Anthropic requests without modifying them. You point the Anthropic SDK at `https://tokonomics.ca/proxy/anthropic`, pass your Tokonomics key as a bearer token, and every Claude call is metered and attributed automatically. Your prompts, message format, and streaming behaviour are unchanged.

## The URL change

Replace the Anthropic base URL with your Tokonomics proxy URL. Everything else — your API key, your request bodies, your headers — stays the same.

|            | URL                                     |
| ---------- | --------------------------------------- |
| **Before** | `https://api.anthropic.com`             |
| **After**  | `https://tokonomics.ca/proxy/anthropic` |

A messages request is forwarded to:

```text theme={null}
https://tokonomics.ca/proxy/anthropic/messages
```

<CodeGroup>
  ```python Python theme={null}
  import anthropic

  client = anthropic.Anthropic(
      api_key="your-anthropic-api-key",
      base_url="https://tokonomics.ca/proxy/anthropic",
      default_headers={"Authorization": "Bearer mk_your_tokonomics_key"}
  )

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

  print(message.content[0].text)
  ```

  ```typescript Node.js theme={null}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    apiKey: 'your-anthropic-api-key',
    baseURL: 'https://tokonomics.ca/proxy/anthropic',
    defaultHeaders: { 'Authorization': 'Bearer mk_your_tokonomics_key' }
  });

  const message = await client.messages.create({
    model: 'claude-opus-4-5',
    max_tokens: 1024,
    messages: [{ role: 'user', content: 'Hello!' }]
  });

  console.log(message.content[0].text);
  ```
</CodeGroup>

## Cache token tracking

Tokonomics automatically captures Anthropic's prompt caching token fields from every response. Alongside standard `input_tokens` and `output_tokens`, your usage records include:

* **`cache_read_tokens`** — tokens served from the prompt cache (billed at the reduced cache-read rate)
* **`cache_creation_tokens`** — tokens written into the prompt cache (billed at the cache-write rate)

You can view cache savings on the Usage dashboard. No additional configuration is needed — Tokonomics reads these fields from every response that includes them.

<Tip>
  Tagging works the same as OpenAI. Add an `X-Metering-Tags` header to any request — for example, `{"team":"platform","feature":"document-qa"}` — to attribute costs to teams or features. See [Tagging](/concepts/tagging) for details.
</Tip>
