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

# Chat Completions

> POST /v1/chat/completions — OpenAI-compatible chat completions.

## Endpoint

```
POST https://dolphy.chat/api/v1/chat/completions
Authorization: Bearer dpy_live_...
```

This endpoint is fully compatible with OpenAI's chat completions API. Drop
in the official `openai` SDK by changing `baseURL`.

## Request body

```json theme={null}
{
  "model": "dolphy-chat-1",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Tell me about Mars." }
  ],
  "temperature": 0.8,
  "max_tokens": 512,
  "stream": false
}
```

| Field         | Type                | Notes                            |
| ------------- | ------------------- | -------------------------------- |
| `model`       | string              | Default `dolphy-chat-1`          |
| `messages`    | array               | Up to 200 messages, OpenAI shape |
| `temperature` | number              | 0–2                              |
| `top_p`       | number              | 0–1                              |
| `max_tokens`  | int                 | Up to 8192                       |
| `stream`      | boolean             | SSE streaming if true            |
| `stop`        | string \| string\[] | Stop sequences                   |

## Streaming

Set `stream: true` to get token-by-token SSE chunks (OpenAI format with
`data: {…}\n\n` events ending in `data: [DONE]`).

```ts theme={null}
const stream = await client.chat.completions.create({
  model: "dolphy-chat-1",
  messages: [{ role: "user", content: "Tell me a story." }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
```

## Billing

1 credit per 10,000 tokens (input + output, minimum 1 per call). For
streamed responses, the final chunk includes the `usage` block we use to
compute the bill.

## Errors

| Status | When                                   |
| ------ | -------------------------------------- |
| `401`  | Invalid or revoked API key             |
| `402`  | Insufficient credits                   |
| `422`  | Content policy rejection from upstream |
| `429`  | Rate limit (60/min per key)            |
| `502`  | Upstream provider error                |
| `503`  | Provider temporarily unavailable       |
