---
title: "Create chat completion"
method: POST
path: "/v1/chat/completions"
tags: ["Inference"]
---

# Create chat completion

`POST /v1/chat/completions`

## Request

- Base URL: `http://localhost:9998`
- URL: `http://localhost:9998/v1/chat/completions`
- Auth: HTTP bearer

OpenAI-compatible chat completion. Supports streaming via `stream: true`
(returns SSE with `data: {...}` lines). The `model` field must match a stem
from `/v1/models`.

## Request body

- ChatCompletionRequest
  - `model` string, required: Model stem from /v1/models
  - `messages` object[], required
    - `role` 'system' | 'user' | 'assistant', required
    - `content` string, required
  - `stream` boolean
  - `temperature` number
  - `top_p` number
  - `max_tokens` integer
  - `stop` union
    - string
    - string[]

## Response `200`

Chat completion response. When `stream: false`, returns a single JSON object.
When `stream: true`, returns `text/event-stream` with `data: {...}` lines
ending with `data: [DONE]`.

- ChatCompletionResponse
  - `id` string, required
  - `object` 'chat.completion', required
  - `created` integer, required
  - `model` string, required
  - `choices` object[], required
    - `index` integer, required
    - `message` object, required
      - `role` string
      - `content` string
    - `finish_reason` string, required
  - `usage` object
    - `prompt_tokens` integer
    - `completion_tokens` integer
    - `total_tokens` integer

## Other responses

- `400`: Invalid request
- `404`: Model not found

---

[API](https://skmtc.dev/modelpiper/apis/toolpiper-api.md) · [All operations](https://skmtc.dev/modelpiper/apis/toolpiper-api/llms.txt) · [OpenAPI document](https://skmtc.dev/modelpiper/apis/toolpiper-api/revisions/6722bf56385c?raw)
