> ## 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.

# Connect OpenAI to Tokonomics for Automatic Cost Metering

> Replace the OpenAI base URL with Tokonomics to start tracking GPT-4o, o1, and other OpenAI model costs automatically — no other code changes needed.

Tokonomics acts as a transparent proxy between your application and OpenAI. You change one URL, add your Tokonomics key as an `Authorization` header, and every call you make to GPT-4o, o1, or any other OpenAI model is automatically metered, tagged, and attributed to your budget — no SDK wrappers, no middleware, no refactoring required.

## The URL change

Swap the OpenAI base URL for your Tokonomics proxy URL. That is the only code change you need to make.

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

The upstream path stays exactly the same. For example, a chat completion request hits:

```text theme={null}
https://tokonomics.ca/proxy/openai/chat/completions
```

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

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

  response = client.chat.completions.create(
      model="gpt-4o",
      messages=[{"role": "user", "content": "Hello!"}]
  )

  print(response.choices[0].message.content)
  ```

  ```typescript Node.js theme={null}
  import OpenAI from 'openai';

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

  const response = await client.chat.completions.create({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: 'Hello!' }]
  });

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

## Supported OpenAI paths

Tokonomics forwards requests to any path under `https://api.openai.com/v1`. The most commonly used paths are:

* `chat/completions` — chat models including GPT-4o, GPT-4o mini, and the o-series
* `embeddings` — text embedding models such as `text-embedding-3-small`
* `completions` — legacy text completion endpoint

## Tagging your calls

Add the `X-Metering-Tags` header to any request to attach structured metadata. Tokonomics stores these tags and lets you query spend broken down by any key.

<CodeGroup>
  ```python Python theme={null}
  response = client.chat.completions.create(
      model="gpt-4o",
      messages=[{"role": "user", "content": "Summarise this report."}],
      extra_headers={
          "X-Metering-Tags": '{"team":"growth","feature":"chatbot"}'
      }
  )
  ```

  ```typescript Node.js theme={null}
  const response = await client.chat.completions.create(
    {
      model: 'gpt-4o',
      messages: [{ role: 'user', content: 'Summarise this report.' }]
    },
    {
      headers: { 'X-Metering-Tags': '{"team":"growth","feature":"chatbot"}' }
    }
  );
  ```
</CodeGroup>

See [Tagging](/concepts/tagging) for the full list of supported headers and querying options.

<Tip>
  Streaming works natively. Tokonomics forwards the SSE response back to your client chunk by chunk without buffering, so your time-to-first-token is unaffected.
</Tip>
