# Create Chat Completion

`POST /v1/chat/completions`

OpenAI-compatible uncensored chat, with streaming.

Drop-in compatible with the OpenAI SDK: point `baseURL` at `https://api.spicyapi.com/v1` and pass your SpicyAPI key. Billed on total tokens.

Base URL: `https://api.spicyapi.com`

## Authorizations

- `Authorization` (string, header, required): Bearer authentication header of the form `Bearer <token>`, where `<token>` is your SpicyAPI key (`sk-spicy-…`). Create one in the dashboard under API Keys.

## Body (application/json)

- `model` (string, required): A chat model id, e.g. `spicy-chat-1`.
- `messages` (Message · object[], required): The conversation so far.
  - `role` (string, required): `system`, `user`, or `assistant`.
  - `content` (string, required): Message text.
- `temperature` (number, optional): Sampling temperature, 0 to 2.
- `max_tokens` (integer, optional): Cap on generated tokens.
- `stream` (boolean, optional): Stream back server-sent events. Usage arrives in the final chunk.

## Request

```bash
curl --request POST \
  --url https://api.spicyapi.com/v1/chat/completions \
  --header 'Authorization: Bearer $SPICYAPI_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "spicy-chat-1",
    "messages": [
      { "role": "user", "content": "Hey, how was your day?" }
    ],
    "temperature": 0.9
  }'
```

## Response: 200 application/json

Successful Response

- `id` (string, required): Completion id.
- `choices` (Choice · object[], required): Generated replies.
  - `index` (integer, required): Position in the list.
  - `message` (object, required): The reply.
    - `role` (string, required): Always `assistant`.
    - `content` (string, required): Reply text.
  - `finish_reason` (string, optional): Why generation stopped.
- `usage` (object, optional): Token counts.
  - `prompt_tokens` (integer, required): Tokens in the request.
  - `completion_tokens` (integer, required): Tokens generated.
  - `total_tokens` (integer, required): Sum, what you are billed on.
- `cost_usd` (number, required): What this request cost, in US dollars, already debited from your balance.

```json
{
  "id": "chatcmpl_7b3f",
  "object": "chat.completion",
  "model": "spicy-chat-1",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "<string>" },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 12, "completion_tokens": 84, "total_tokens": 96 },
  "cost_usd": 0.000055
}
```
