# Create a chat completion

> `POST /v1/chat/completions` generates the next message in a conversation, as JSON or as a stream.

Source: https://www.lyber.ai/docs/api/chat-completions/ · Markdown: https://www.lyber.ai/docs/md/api/chat-completions.md

Python (`main.py`):

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://lyber-paid-acceptance-gateway-production.up.railway.app/v1",
    api_key=os.environ["LYBER_API_KEY"],
)

response = client.chat.completions.create(
    model="minimax-m3.1-flash-abliterated",
    messages=[{"role": "user", "content": "Explain abliteration in two sentences."}],
    max_tokens=1024,
)
print(response.model)
print(response.choices[0].message.content)
```

TypeScript (`main.ts`):

```ts
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://lyber-paid-acceptance-gateway-production.up.railway.app/v1",
  apiKey: process.env.LYBER_API_KEY,
});

const response = await client.chat.completions.create({
  model: "minimax-m3.1-flash-abliterated",
  messages: [{ role: "user", content: "Explain abliteration in two sentences." }],
  max_tokens: 1024,
});
console.log(response.model);
console.log(response.choices[0].message.content);
```

curl (`request.sh`):

```bash
curl https://lyber-paid-acceptance-gateway-production.up.railway.app/v1/chat/completions \
  -H "Authorization: Bearer $LYBER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "minimax-m3.1-flash-abliterated",
    "messages": [{"role": "user", "content": "Explain abliteration in two sentences."}],
    "max_tokens": 1024
  }'
```

## Request body

| Field | Type | Description |
| --- | --- | --- |
| `model` **required** | string | `minimax-m3.1-flash-abliterated` or `deepseek-v4.1-flash-1017-abliterated`. |
| `messages` **required** | array | 1–4,096 messages with `role` `system`, `user`, `assistant` or `tool`. User content is a string or an array of `text` and `image_url` parts. |
| `max_tokens` | integer | Most output tokens, reasoning included. Defaults to the model's maximum. `max_completion_tokens` is accepted as an alias. |
| `temperature` | number | 0–2. Defaults per model; see [Models](https://www.lyber.ai/docs/models/). |
| `top_p` | number | 0–1. |
| `stop` | string or array | Up to 4 sequences where generation stops. |
| `stream` | boolean | Send the reply as server-sent events. See [Streaming](https://www.lyber.ai/docs/capabilities/streaming/). |
| `stream_options` | object | Only `include_usage` (boolean). |
| `tools` | array | Up to 32 function tools. See [Tool calling](https://www.lyber.ai/docs/capabilities/tool-calling/). |
| `tool_choice` | string or object | `auto`, `none`, `required`, or a named function. |
| `reasoning_effort` | string | Per model; see [Thinking](https://www.lyber.ai/docs/capabilities/thinking/). |
| `thinking_token_budget` | integer | DeepSeek only. Cap on reasoning tokens. |
| `max_cost_micro_usdc` | integer | Lyber only. Refuse the request if its credit hold would exceed this. See [Spending controls](https://www.lyber.ai/docs/capabilities/spending-controls/). |

> **Unknown fields fail:** Any other field, including `n`, `seed`, `logprobs`, `presence_penalty`, `frequency_penalty`, `user`, `response_format` and `parallel_tool_calls`, returns `400 unsupported_parameter` instead of being silently ignored.

## Response

```json
{
  "id": "chatcmpl-6f1c…",
  "object": "chat.completion",
  "created": 1793491200,
  "model": "minimax-m3.1-flash-abliterated",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "Abliteration removes the direction in a model's activations…",
      "reasoning_content": "The user wants two sentences…"
    },
    "finish_reason": "stop"
  }],
  "usage": {"prompt_tokens": 18, "completion_tokens": 96, "total_tokens": 114}
}
```

| finish_reason | Meaning |
| --- | --- |
| `stop` | The model finished, or hit a `stop` sequence. |
| `length` | The reply reached `max_tokens`. Raise it, or continue in a new request. |
| `tool_calls` | The model is waiting for tool results. |

## Response headers

| Header | Value |
| --- | --- |
| `x-request-id` | Lyber's ID for the request. Quote it when you contact support. |
| `x-lyber-model` | The model that answered. |
| `x-lyber-revision` | The exact checkpoint revision that answered. |
