> For the complete documentation index, see [llms.txt](https://anyint.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anyint.gitbook.io/docs/api-reference/openai-compatible.md).

# openai compatible

Use this route when you want the fastest path to production or when your application already speaks the OpenAI Chat Completions format.

## Base URL

`https://gateway.api.anyint.ai/openai/v1`

## Published route

`POST /chat/completions`

Full URL:

```
https://gateway.api.anyint.ai/openai/v1/chat/completions
```

## Authentication

```http
Authorization: Bearer <ANYINT_API_KEY>
Content-Type: application/json
```

## When to use this route

* You already use the OpenAI Python or JavaScript SDK
* You want one stable chat entrypoint for multiple model families
* You want SSE streaming with minimal integration work

If you need Gemini-native request bodies or Anthropic-specific features such as token counting, use those provider-compatible pages directly.

## Core request shape

| Field      | Type    | Notes                                                                   |
| ---------- | ------- | ----------------------------------------------------------------------- |
| `model`    | string  | Use a model ID available to your account                                |
| `stream`   | boolean | Set `true` for SSE chunk streaming, `false` for a regular JSON response |
| `messages` | array   | Standard chat message list                                              |

The current published schema documents the minimum request body needed to get a completion working. If your client already uses other OpenAI-compatible fields, validate them against the target model before relying on them in production.

## cURL example

```bash
curl https://gateway.api.anyint.ai/openai/v1/chat/completions \
  -H "Authorization: Bearer $ANYINT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o",
    "stream": true,
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Explain AnyInt in one sentence."}
    ]
  }'
```

## Python example

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.api.anyint.ai/openai/v1",
    api_key="your-anyint-api-key",
)

response = client.chat.completions.create(
    model="openai/gpt-4o",
    stream=True,
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Explain AnyInt in one sentence."},
    ],
)

for chunk in response:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="")
```

## JavaScript example

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://gateway.api.anyint.ai/openai/v1",
  apiKey: process.env.ANYINT_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "openai/gpt-4o",
  stream: true,
  messages: [
    { role: "system", content: "You are a concise assistant." },
    { role: "user", content: "Explain AnyInt in one sentence." },
  ],
});

for await (const chunk of stream) {
  const delta = chunk.choices?.[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
}
```

## Response behavior

* With `stream: true`, the route returns SSE chunks
* The published schema uses `chat.completion.chunk` style objects
* Each chunk can contain `choices[0].delta.content`
* The stream ends with `[DONE]`
* Final usage data can arrive near the end of the stream

## Common mistakes

* Using `x-api-key` instead of `Authorization: Bearer`
* Hardcoding a model ID before checking [Models API](/docs/models-and-modalities/models.md)
* Treating a partial stream chunk as the final answer
* Mixing provider-native request fields into the OpenAI payload without validation

## Related pages

* [Models API](/docs/api-reference/models-api.md)
* [Streaming](/docs/features/streaming.md)
* [Tool Calling](/docs/features/tool-calling.md)
* [Structured Outputs](/docs/features/structured-outputs.md)
