> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.singularityapi.dev/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.singularityapi.dev/_mcp/server.

# Chat Completions

`POST /v1/chat/completions` speaks the OpenAI chat completions wire format. Authenticate with `Authorization: Bearer sapi_...`. For everything not called out below — message formats, tool calling, response shape — see [OpenAI Compatibility](/get-started/openai-compatibility); this page only covers what's specific to SingularityAPI.

## Request notes

* **`model`** — required. A catalog slug (e.g. `deepseek-v4-flash`) or `contract/{slug}` for a [contract](/platform/contracts). Must match exactly; see [Models & Pricing](/get-started/models-pricing) for the catalog.
* **Output limit field** — `max_tokens` and `max_completion_tokens` are interchangeable; either caps output tokens on any chat model. Sending both in one request is a 400. The value must be a positive integer, no larger than the model's max output. Omit it and the per-model default is injected server-side — check the receipt's `transformed_fields` to see when the default (or a spelling rewrite) was applied.
* **`stream`** — boolean. See [Streaming](/platform/streaming) for the SSE details.
* **`reasoning_effort`** — optional; the accepted values differ per model, see the [reasoning effort table](/get-started/models-pricing#reasoning-effort-by-model). A value the model does not accept is rejected with a 400 and never charged.
* Unsupported or reserved parameters are rejected with a 400, not silently dropped.

> **Note**
>
> **Reasoning effort and function tools on GPT models (`gpt-5.6-*`, `gpt-6-*`).** On this endpoint `reasoning_effort` accepts `none`, `low`, `medium`, `high`, and `xhigh` — except that `gpt-6-astra` does not accept `none`. `minimal` and `max` are rejected here on every GPT model (`max` is accepted on [`/v1/responses`](/api/responses)). OpenAI's chat surface only serves function tools when reasoning is off (`reasoning_effort: "none"`); the platform serves every other tools request — an explicit `low`/`medium`/`high`/`xhigh`, or no `reasoning_effort` at all — through the provider's tools-compatible path automatically, so both shapes succeed with the normal chat-completions response. Provider rejections pass straight through as a 400, and failed requests are never charged.

## Example

**`cURL`**

```bash title="cURL"
curl https://api.singularityapi.dev/v1/chat/completions \
  -H "Authorization: Bearer $SINGULARITY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [{"role": "user", "content": "Say hello."}]
  }'
```

**`Python`**

```python title="Python"
from openai import OpenAI

client = OpenAI(
    base_url="https://api.singularityapi.dev/v1",
    api_key="YOUR_API_KEY",
)

response = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[{"role": "user", "content": "Say hello."}],
)
print(response.choices[0].message.content)
```

**`JavaScript`**

```javascript title="JavaScript"
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.singularityapi.dev/v1",
  apiKey: "YOUR_API_KEY",
});

const response = await client.chat.completions.create({
  model: "deepseek-v4-flash",
  messages: [{ role: "user", content: "Say hello." }],
});
console.log(response.choices[0].message.content);
```

A response looks like this:

```json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1690000000,
  "model": "deepseek-v4-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 10,
    "total_tokens": 19
  }
}
```

`model` in the response is the served model — the catalog model that actually ran the request. On a direct catalog call this matches what you sent; on a [contract](/platform/contracts) call it's the contract's current target.

## Response headers

Every response carries:

* `x-singularity-request-id`
* `x-singularity-receipt-id`
* `x-singularity-contract-revision` — present on contract calls only

Use the receipt ID to pull the exact cost and token usage from [`GET /v1/receipts/{id}`](/api/models-receipts).

## Limits

* A request may run up to \~230 seconds. Exceeding it returns 504 `request_timeout`.
* Request bodies over the size cap are rejected with 413 `request_too_large`.

> **Note**
>
> See [Errors & Rate Limits](/api/errors-rate-limits) for the full error envelope and status table.