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

# Chat Completions

> Create OpenAI-compatible text, tool-call, and structured-output completions.

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
POST https://api.prisminference.com/v1/chat/completions
```

Use this endpoint with the OpenAI SDK or any client that supports the Chat
Completions wire format.

## Request

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.prisminference.com/v1/chat/completions" \
  -H "Authorization: Bearer $PRISM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "prism-glm53",
    "messages": [
      {"role": "system", "content": "You are a senior TypeScript engineer."},
      {"role": "user", "content": "Explain the bug in this function: ..."}
    ],
    "temperature": 0.2
  }'
```

### Body parameters

| Field              | Type                | Required | Description                                                           |
| ------------------ | ------------------- | -------- | --------------------------------------------------------------------- |
| `model`            | string              | Yes      | A [Prism model ID](/models).                                          |
| `messages`         | array               | Yes      | Conversation messages in chronological order.                         |
| `stream`           | boolean             | No       | Return Server-Sent Events when `true`. Defaults to `false`.           |
| `max_tokens`       | integer             | No       | Maximum number of generated tokens.                                   |
| `temperature`      | number              | No       | Sampling temperature. Lower values are more deterministic.            |
| `top_p`            | number              | No       | Nucleus sampling probability.                                         |
| `stop`             | string or string\[] | No       | Stop generation when any supplied sequence is produced.               |
| `tools`            | array               | No       | OpenAI function definitions available to the model.                   |
| `tool_choice`      | string or object    | No       | Control whether and which tool the model calls.                       |
| `response_format`  | object              | No       | Request JSON mode or output that matches a JSON Schema.               |
| `reasoning`        | object              | No       | Enable reasoning with `effort: "low"`, `"medium"`, or `"high"`.       |
| `prompt_cache_key` | string              | No       | Stable conversation identifier used for cache affinity.               |
| `cache_ttl`        | string              | No       | Cache lifetime: `5m`, `30m`, `1h`, `6h`, or `24h`.                    |
| `stream_options`   | object              | No       | Set `include_usage: true` to receive usage in the final stream chunk. |

Each message has a `role` and content:

| Role        | Purpose                                        |
| ----------- | ---------------------------------------------- |
| `system`    | Set behavior and instructions for the model.   |
| `user`      | Supply a user request or a tool result.        |
| `assistant` | Include earlier assistant text or tool calls.  |
| `tool`      | Return a tool result using its `tool_call_id`. |

## Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "chatcmpl_01J...",
  "object": "chat.completion",
  "created": 1788926400,
  "model": "prism-glm53",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The shared counter is updated without synchronization..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 42,
    "completion_tokens": 88,
    "total_tokens": 130
  }
}
```

`finish_reason` is commonly:

| Value            | Meaning                                                  |
| ---------------- | -------------------------------------------------------- |
| `stop`           | The model completed normally or reached a stop sequence. |
| `length`         | Generation reached the configured token limit.           |
| `tool_calls`     | The model requested one or more tools.                   |
| `content_filter` | Generation stopped because of a safety policy.           |

## Streaming

Set `stream: true`. The response uses `text/event-stream` and ends with
`data: [DONE]`.

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
data: {"id":"chatcmpl_01J...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl_01J...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"The race"},"finish_reason":null}]}

data: {"id":"chatcmpl_01J...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]
```

Tool-call arguments may span multiple chunks. Concatenate deltas by choice and
tool-call index before parsing the JSON arguments.

## Errors

Errors use the OpenAI-compatible envelope:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "error": {
    "message": "The requested model does not exist.",
    "code": "model_not_found"
  }
}
```

See [Errors and retries](/errors) for status codes and retry guidance.
