# Chat Completions

> POST /v1/chat/completions in the OpenAI format, for any model in the catalogue, with what is sent on, translated or dropped for each kind of provider.

Source: https://digitspace.ai/docs/api/chat-completions · Last checked: 2026-10-31

```http
POST https://api.digitspace.ai/v1/chat/completions
```

The OpenAI Chat Completions format. Any OpenAI SDK or OpenAI-compatible tool works by setting its base URL to `https://api.digitspace.ai/v1`.

## Request

`model` and a non-empty `messages` array are required; anything else is optional.

curl:

```bash
curl https://api.digitspace.ai/v1/chat/completions \
  -H "Authorization: Bearer $DIGITSPACE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "auto",
    "messages": [
      { "role": "system", "content": "Answer in one sentence." },
      { "role": "user", "content": "What is an AI gateway?" }
    ],
    "max_tokens": 200
  }'
```

Python:

```python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["DIGITSPACE_API_KEY"], base_url="https://api.digitspace.ai/v1")

reply = client.chat.completions.create(
    model="auto",
    messages=[
        {"role": "system", "content": "Answer in one sentence."},
        {"role": "user", "content": "What is an AI gateway?"},
    ],
    max_tokens=200,
)
```

TypeScript:

```ts
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.DIGITSPACE_API_KEY,
  baseURL: "https://api.digitspace.ai/v1",
});

const reply = await client.chat.completions.create({
  model: "auto",
  messages: [
    { role: "system", content: "Answer in one sentence." },
    { role: "user", content: "What is an AI gateway?" },
  ],
  max_tokens: 200,
});
```

| Field                                 |                                                                                                                                                               |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`                               | A model ID or alias, `provider/model` to pin a provider, or `auto`. See [Choosing a model](/docs/routing/models).                                             |
| `messages`                            | The conversation, as in OpenAI's API. Text and image parts are supported.                                                                                     |
| `stream`                              | `true` for server-sent events. See [Streaming](/docs/api/streaming).                                                                                          |
| `tools`, `tool_choice`                | Function calling. See [Tool calls](/docs/api/tools).                                                                                                          |
| `response_format`                     | JSON mode or a JSON schema. See [Structured output](/docs/api/structured-output).                                                                             |
| `reasoning_effort`                    | For reasoning models. See [Reasoning](/docs/api/reasoning).                                                                                                   |
| `max_tokens`, `max_completion_tokens` | The longest answer. Either name works; for OpenAI and Azure the gateway sends `max_completion_tokens`.                                                        |
| `temperature`, `top_p`, `stop`        | Sent to every provider.                                                                                                                                       |
| Other OpenAI fields                   | `n`, `seed`, `user`, `metadata`, `logprobs`, penalties and the rest are passed to providers that use the OpenAI format, and dropped for the rest (see below). |

## How the request reaches the provider

The gateway rewrites only `model`, to the provider's own name for it. What happens to the other fields depends on the format the chosen provider uses:

- **OpenAI-format providers** (OpenAI, Azure, Groq, DeepSeek, Mistral and most others) get the body as you sent it.
- **Anthropic** and **Claude on Vertex or Azure** get it translated to the Messages format. System messages are joined into `system`, tools and tool results are converted, `stop` becomes `stop_sequences`, and `max_tokens` defaults to 4,096 when you don't set it. `response_format`, `n`, `seed`, `user`, `metadata`, `parallel_tool_calls`, `logprobs` and the penalties have no Anthropic equivalent and are dropped.
- **AWS Bedrock** gets it translated to the Converse API. Messages, system, `max_tokens`, `temperature`, `top_p`, `stop` and function tools are kept; the rest is dropped. Images must be sent as `data:` URLs.

On DigitSpace credits, a few provider-only options are removed: `service_tier`, `web_search_options`, and tools that aren't functions. On your own provider key they're passed through.

> **Note:** If you need a field that one provider format drops, such as `response_format` with a JSON schema, either pin a provider that uses the OpenAI format with `provider/model`, or let `auto` choose: routing only picks models whose providers can do what the request asks for.

## Response

The response is in the OpenAI format whichever provider answered. Answers from Anthropic-format providers are converted: thinking becomes `reasoning_content` on the message, `tool_use` becomes `tool_calls`, and `finish_reason` is mapped (`end_turn` to `stop`, `max_tokens` to `length`, `tool_use` to `tool_calls`).

```json
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "auto",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "An AI gateway is …" },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 31,
    "completion_tokens": 24,
    "total_tokens": 55,
    "prompt_tokens_details": { "cached_tokens": 0 }
  }
}
```

- `model` repeats what you sent, so a request for `auto` answers `"model": "auto"`.
- The `x-digitspace-provider` header names the provider that answered, and `x-request-id` identifies the request. Quote it when you contact support.
- The response carries no cost. The cost of each request is in the dashboard's [Activity](/docs/dashboard/activity) page.

## Errors

Errors use OpenAI's shape, `{"error": {"message", "type", "code"}}`. [Errors](/docs/reference/errors) lists every one.
