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

# Create a chat completion

`POST /chat/completions`

Creates a chat completion using an OpenAI-compatible request body. Use model ids returned by `GET /models`.

## Request body

- ChatCompletionRequest
  - `audio` object, nullable
  - `frequency_penalty` number, nullable
  - `function_call` union
    - string
    - object
  - `functions` object[], nullable
  - `logit_bias` object, nullable
  - `logprobs` boolean, nullable
  - `max_completion_tokens` integer, nullable
  - `max_tokens` integer, nullable
  - `messages` ChatMessage[], required
    - `content` union
      - string, nullable
      - ChatMessageContentPart[]
        - `image_url` object
          - `url` string
        - `text` string
        - `type` string, required — Content part type.
    - `name` string
    - `role` 'system' | 'user' | 'assistant' | 'tool', required
    - `tool_call_id` string
    - `tool_calls` object[], nullable
  - `metadata` object, nullable
  - `modalities` string[], nullable
  - `model` string, required — Model id returned by `GET /models`.
  - `n` integer, nullable
  - `parallel_tool_calls` boolean, nullable
  - `prediction` object, nullable
  - `presence_penalty` number, nullable
  - `prompt_cache_key` string, nullable
  - `prompt_cache_retention` string, nullable
  - `reasoning` object, nullable
  - `reasoning_effort` string, nullable
  - `response_format` object, nullable
  - `safety_identifier` string, nullable
  - `seed` integer, nullable
  - `service_tier` string, nullable
  - `stop` union
    - string
    - string[]
  - `store` boolean, nullable
  - `stream` boolean, nullable
  - `stream_options` object, nullable
    - `include_usage` boolean
  - `temperature` number, nullable
  - `tool_choice` union
    - string
    - object
  - `tools` object[], nullable
  - `top_logprobs` integer, nullable
  - `top_p` number, nullable
  - `user` string, nullable
  - `verbosity` string, nullable
  - `web_search_options` object, nullable

## Response `200`

Chat completion response

- ChatCompletionResponse
  - `choices` ChatCompletionChoice[], required
    - `finish_reason` string, nullable
    - `index` integer
    - `message` ChatMessage
      - `content` union
        - string, nullable
        - ChatMessageContentPart[]
          - `image_url` object
            - `url` string
          - `text` string
          - `type` string, required — Content part type.
      - `name` string
      - `role` 'system' | 'user' | 'assistant' | 'tool', required
      - `tool_call_id` string
      - `tool_calls` object[], nullable
  - `created` integer, required
  - `id` string, required
  - `model` string, required
  - `object` string, required
  - `usage` ChatCompletionUsage
    - `completion_tokens` integer
    - `prompt_tokens` integer
    - `prompt_tokens_details` PromptTokensDetails
      - `cached_tokens` integer — Prompt tokens served from cache for this request.
    - `total_tokens` integer

## Other responses

- `400` — Invalid request body
- `401` — Missing or invalid API key
- `402` — Insufficient API credits
- `404` — Unknown model
- `500` — Chat completion failed

---

[API](https://skmtc.net/textcortex/apis/textcortex-api.md) · [All operations](https://skmtc.net/textcortex/apis/textcortex-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/textcortex/textcortex-api/revisions/434c9de75420/schema)
