---
title: "Create a chat completion"
method: POST
path: "/chat/completions"
tags: ["chatCompletions"]
---

# Create a chat completion

`POST /chat/completions`

Generates a model response for a conversation. Supports streaming (`stream: true`, server-sent events) and non-streaming responses. When streaming, each frame is a `data:` line holding one JSON completion chunk, the chunk carrying `usage` has an empty `choices` array, and the stream ends with the literal `data: [DONE]`. OpenAI-compatible: the supported fields are documented here, and the wider OpenAI SDK parameter set is accepted so that existing OpenAI code runs unmodified.

## Headers

- `Authorization` string, required
- `x-session-id` string

## Request body

- ChatCompletionRequest — OpenAI-compatible chat completion request. The supported fields are documented here; the wider OpenAI SDK parameter set is accepted so that existing OpenAI code runs unmodified.
  - `model` string, required — The ASI:One model to use.
  - `messages` ChatMessage[], required — The conversation so far.
    - `role` string, required — The role of the message author (for example `system`, `user`, `assistant`, or `tool`).
    - `content` union, required — The message content. A string, an array of content parts for multimodal input, or null (for example on assistant messages that only carry tool_calls).
      - string
      - ChatMessageContentOneOf1Items[]
    - `name` string — An optional name for the participant.
    - `tool_call_id` string — For tool messages: the id of the tool call being responded to.
    - `tool_calls` ChatMessageToolCallsItems[] — For assistant messages that call tools.
    - `reasoning_content` string, nullable — The model's reasoning, when reasoning was requested. `null` otherwise. See the Reasoning guide.
  - `stream` boolean — If true, partial deltas are streamed as server-sent events.
  - `temperature` number, double — Sampling temperature.
  - `max_tokens` integer — Maximum number of tokens to generate.
  - `top_p` number, double — Nucleus sampling probability mass.
  - `stop` string[] — Up to four strings that end generation when produced.
  - `tools` FunctionTool[] — A list of tools the model may call. See the Tool Calling guide.
    - `type` 'function', required — Always `function`. Any other tool type is rejected with a 400.
    - `function` FunctionToolFunction, required
      - `name` string, required — Name of the function. The model uses this to refer to the call.
      - `description` string — What the function does and when to use it. The model selects tools from this text, so it is worth writing carefully.
      - `parameters` object — JSON Schema describing the function's arguments.
      - `strict` boolean — Whether the model must follow the parameter schema exactly. Requires `additionalProperties: false` and every property listed in `required`.
  - `tool_choice` union — Controls which (if any) tool is called.
    - 'auto' | 'none' | 'required'
    - object
  - `parallel_tool_calls` boolean — Whether the model may call several tools in one turn.
  - `response_format` union — Constrains the reply's format. See the Structured Data guide.
    - ResponseFormat0
      - `type` 'text' | 'json_object', required
    - ResponseFormat1
      - `type` 'json_schema', required
      - `json_schema` ResponseFormatOneOf1JsonSchema, required
        - `name` string, required — Name of the schema. Required when `type` is `json_schema`.
        - `description` string — What the schema is for.
        - `schema` object — The JSON Schema the reply must conform to.
        - `strict` boolean — Whether the reply must match the schema exactly.
  - `enable_thinking` boolean — ASI:One extension. Whether the model reasons before answering. See the Reasoning guide.
  - `thinking_budget` integer — ASI:One extension. Maximum tokens the model may spend reasoning. Applies on asi1.
  - `planner_mode` boolean — ASI:One extension. Routes the request to the planner, which breaks it into steps and runs them against tools and Agentverse agents. Available on asi1, asi1-ultra and asi1-mini. See the Planner Mode guide.
  - `agents` string[] — ASI:One extension. Agentverse agent addresses the planner may use without discovering them first. Used with planner_mode.

## Response `200`

A chat completion object, or an SSE stream of completion chunks when `stream` is true.

- ChatCompletionResponse
  - `id` string, required
  - `object` string, required
  - `created` integer — Unix timestamp (seconds) of creation.
  - `model` string — The model that produced the response.
  - `choices` ChatCompletionResponseChoicesItems[], required — A list of generated choices.
    - `index` integer
    - `finish_reason` 'stop' | 'tool_calls' | 'length' — Why generation stopped. `stop` is a normal completion, `tool_calls` means the model wants a tool result, `length` means a token limit was reached. Treat an unrecognised value as a finished reply.
    - `message` ChatMessage
      - `role` string, required — The role of the message author (for example `system`, `user`, `assistant`, or `tool`).
      - `content` union, required — The message content. A string, an array of content parts for multimodal input, or null (for example on assistant messages that only carry tool_calls).
        - string
        - ChatMessageContentOneOf1Items[]
      - `name` string — An optional name for the participant.
      - `tool_call_id` string — For tool messages: the id of the tool call being responded to.
      - `tool_calls` ChatMessageToolCallsItems[] — For assistant messages that call tools.
      - `reasoning_content` string, nullable — The model's reasoning, when reasoning was requested. `null` otherwise. See the Reasoning guide.
    - `delta` ChatCompletionResponseChoicesItemsDelta — Present on streaming responses.
  - `usage` ChatCompletionResponseUsage — Token usage for the request.
    - `prompt_tokens` integer
    - `completion_tokens` integer
    - `total_tokens` integer
    - `prompt_tokens_details` ChatCompletionResponseUsagePromptTokensDetails — Breakdown of the prompt tokens.
      - `cached_tokens` integer — Prompt tokens served from cache. These still count toward `prompt_tokens`.
    - `reasoning_tokens` integer — Tokens spent reasoning before answering. `0` when reasoning was not requested.

## Other responses

- `400` — The request was malformed, or a parameter was missing or invalid.
- `401` — The API key is missing or invalid.
- `402` — The organization's account is blocked.
- `403` — The API key is not permitted to perform this operation.
- `404` — The requested model or resource does not exist.
- `429` — The rate limit for your plan has been exceeded.
- `500` — An unexpected error occurred while handling the request.
- `502` — An upstream service failed while handling the request.

---

[API](https://skmtc.dev/asi1/apis/api-reference.md) · [All operations](https://skmtc.dev/asi1/apis/api-reference/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/asi1/api-reference/revisions/c3dc3d9ebb8a/schema)
