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

# Inference API overview

> Call TokenChange models through an OpenAI-compatible API at inference.tokenchange.io: base URL, authentication, SDK setup and how it differs from OpenAI.

The inference API is OpenAI-compatible. Point an OpenAI SDK or any OpenAI-compatible client at TokenChange and use an inference key.

## Base URL

```text theme={null}
https://inference.tokenchange.io/v1
```

| Method | Path | Description |
| - | - | - |
| `POST` | [`/v1/chat/completions`](https://docs.tokenchange.io/inference/chat-completions) | Stream a chat completion |
| `POST` | [`/v1/completions`](https://docs.tokenchange.io/inference/completions) | Stream a text completion |
| `GET` | [`/v1/models`](https://docs.tokenchange.io/inference/models) | List the models your key can call |

## Authentication

Send an [inference key](https://docs.tokenchange.io/guides/api-keys.md) as a Bearer token:

```bash theme={null}
Authorization: Bearer ask_...
```

API tokens (`tcg_...`) for the REST API don't work here and return `401 invalid_api_key`.

## Use an OpenAI SDK

```python Python theme={null}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://inference.tokenchange.io/v1",
    api_key=os.environ["TOKENCHANGE_API_KEY"],
)
```

```javascript JavaScript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://inference.tokenchange.io/v1",
  apiKey: process.env.TOKENCHANGE_API_KEY,
});
```

## Differences from the OpenAI API

* **Streaming only.** Completion requests must set `"stream": true`. Requests without it, or with `"stream": false`, fail with `400`.
* **Models are catalog slugs.** Pass a slug from the [catalog](https://tokenchange.io/models), or [pin an endpoint](https://docs.tokenchange.io/guides/models-and-endpoints.md#pin-a-request-to-one-endpoint) with `<model-slug>/ep/<endpoint>`.
* **Price options.** An optional `provider` object filters and orders endpoints by price. See [Price options](https://docs.tokenchange.io/guides/routing.md#price-options).
* **Fields are passed through.** Other request fields, such as `tools`, `response_format` or `top_p`, go to the endpoint unchanged. Whether they're honored depends on the endpoint; check its [capabilities](https://docs.tokenchange.io/guides/models-and-endpoints.md#capabilities).
* **Request size.** Request bodies can be up to 32 MiB.

## Errors

Errors use the OpenAI error format. See [Errors](https://docs.tokenchange.io/inference/errors.md).

```json theme={null}
{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.