---
title: "Create Chat Completion"
method: POST
path: "/chat/completions"
tags: ["Chat"]
---

# Create Chat Completion

`POST /chat/completions`

## Request

- Base URL: `https://platform.qubrid.com/v1`
- URL: `https://platform.qubrid.com/v1/chat/completions`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/qubrid/apis/qubrid-chat-api/docs/chat/completions/post.ts> (a function with typed inputs; its response is checked against the schema)

Generate text responses using a large language model.

## Request body

- ChatRequest
  - `model` string, required: The language model to use.
  - `messages` object[], required: Conversation messages in chat format.
    - `role` string, required: Role of the message sender (system, user, assistant).
    - `content` string, required
  - `max_tokens` integer: Maximum number of tokens to generate.
  - `temperature` number: Controls randomness in output.
  - `top_p` number: Nucleus sampling parameter.
  - `stream` boolean: Whether to stream responses incrementally.

## Response `200`

Chat completion generated successfully

- ChatResponse: Standard OpenAI-compatible chat completion response or streamed chunks.
  - `id` string
  - `object` string
  - `created` integer
  - `model` string
  - `choices` object[]
    - `index` integer
    - `message` object
      - `role` string
      - `content` string
    - `finish_reason` string
  - `usage` object
    - `prompt_tokens` integer
    - `completion_tokens` integer
    - `total_tokens` integer
  - `x_metrics` object: Performance metrics for the request.
    - `ttft_seconds` number
    - `tps` number
    - `total_time_seconds` number

## Other responses

- `400`: Bad request - missing required fields, invalid values, or malformed JSON
- `401`: Unauthorized - missing or invalid API key
- `402`: Insufficient credits to process the request
- `403`: Forbidden - authenticated but not allowed to access this model or resource
- `404`: Model not found - the specified model does not exist or is not available
- `413`: Payload too large - input exceeds the model context window
- `429`: Rate limit exceeded
- `500`: Internal server error
- `502`: Bad gateway - upstream AI provider is unavailable or returned an error
- `504`: Gateway timeout - upstream AI provider took too long to respond

## Changes

- **2026-04-13** `39262b48ef68`: 8 breaking, 6 warning, 44 info
  - the request property `messages/items/content` became required
  - the request property `messages/items/role` became required
  - the `error` response's property type changed from `string` to `object` for status `400`
  - the `error` response's property type changed from `string` to `object` for status `401`
  - …54 more

[Operation history](https://skmtc.dev/qubrid/apis/qubrid-chat-api/changes/chat/completions/post.md)

---

[API](https://skmtc.dev/qubrid/apis/qubrid-chat-api.md) - [All operations](https://skmtc.dev/qubrid/apis/qubrid-chat-api/llms.txt) - [OpenAPI document](https://skmtc.dev/qubrid/apis/qubrid-chat-api/revisions/39262b48ef68?raw)
