# Chat completions

POST /v1/chat/completions: OpenAI format for SDKs and most coding tools.

`POST https://ai.sivcloud.com/v1/chat/completions` uses the OpenAI Chat Completions format. OpenAI SDKs work unchanged apart from the base URL and the API key.

```bash
curl https://ai.sivcloud.com/v1/chat/completions \
  -H "Authorization: Bearer $SIVCLOUD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4.1-flash",
    "messages": [
      {"role": "system", "content": "Answer briefly."},
      {"role": "user", "content": "Hello"}
    ],
    "max_tokens": 256
  }'
```

## Response

```json
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "deepseek-v4.1-flash",
  "choices": [
    {"index": 0, "message": {"role": "assistant", "content": "Hello!"}, "finish_reason": "stop"}
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 3,
    "total_tokens": 23,
    "prompt_tokens_details": {"cached_tokens": 0}
  }
}
```

`usage` is the basis of the bill. `prompt_tokens_details.cached_tokens` holds the input tokens read from cache. See [Cache](https://sivcloud.com/en/docs/cache/).

## Good to know

- `model` must be a model id from the Models page or `GET /v1/models`.
- Set `max_tokens`. Before a request is forwarded, sivcloud reserves its estimated cost from the prompt and `max_tokens`. A balance too small for that reserve is rejected with `insufficient_balance`. The unused part of the reserve is returned when the request ends.
- For a step-by-step answer, send `"stream": true`. See [Streaming](https://sivcloud.com/en/docs/streaming/).
- Other parameters follow the model and its provider. A parameter the model does not support may be ignored or rejected by the provider.
