---
title: "POST /ai/v1/chat/completions"
method: POST
path: "/ai/v1/chat/completions"
tags: ["AI Gateway"]
---

# POST /ai/v1/chat/completions

`POST /ai/v1/chat/completions`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/ai/v1/chat/completions`
- Auth: HTTP bearer

## Request body

- ChatCompletionRequest, nullable: OpenAI-compatible chat completion request. Uses `deny_unknown_fields = false` (serde default) so that SDK-specific fields like `stream_options`, `logprobs`, `top_logprobs`, `logit_bias`, `parallel_tool_calls`, etc. are silently accepted without breaking.
  - `frequency_penalty` number, double, nullable
  - `max_tokens` integer, nullable
  - `messages` ChatMessage[], required
    - `content` union
      - string
      - ContentPart[]
        - `cache_control` unknown
        - `image_url` unknown
        - `text` string, nullable
        - `type` string, required
    - `name` string, nullable
    - `role` string, required
    - `tool_call_id` string, nullable
    - `tool_calls` unknown[], nullable
      - unknown
  - `model` string, required
  - `n` integer, nullable
  - `presence_penalty` number, double, nullable
  - `response_format` unknown
  - `seed` integer, nullable
  - `stop` union
    - string
    - string[]
  - `stream` boolean
  - `temperature` number, double, nullable
  - `tool_choice` unknown
  - `tools` unknown[], nullable
    - unknown
  - `top_p` number, double, nullable
  - `user` string, nullable

## Response `200`

Chat completion response

- ChatCompletionResponse
  - `choices` ChatCompletionChoice[], required
    - `finish_reason` string, nullable
    - `index` integer, required
    - `message` ChatMessage, required
      - `content` union
        - string
        - ContentPart[]
          - `cache_control` unknown
          - `image_url` unknown
          - `text` string, nullable
          - `type` string, required
      - `name` string, nullable
      - `role` string, required
      - `tool_call_id` string, nullable
      - `tool_calls` unknown[], nullable
        - unknown
  - `created` integer, required
  - `id` string, required
  - `model` string, required
  - `object` string, required
  - `usage` UsageInfo, nullable
    - `completion_tokens` integer, required
    - `prompt_tokens` integer, required: The whole prompt, including any part served from the provider's cache.
    - `prompt_tokens_details` PromptTokensDetails, nullable: The cached share of a prompt. Both counts are parts of `prompt_tokens`.
      - `cache_write_tokens` integer: Tokens written to the provider's prompt cache by this request.
      - `cached_tokens` integer: Tokens read from the provider's prompt cache.
    - `total_tokens` integer, required

## Other responses

- `400`: Invalid request
- `401`: Unauthorized
- `404`: Model not found
- `500`: Internal error

## Changes

- **2026-10-23** `7d41b820a372`: 3 info
  - added the new optional request property `allOf[subschema #2]/messages/items/content/oneOf[#/components/schemas/MessageContent]/oneOf[subschema #2]/items/cache_control`
  - added the optional property `choices/items/message/content/oneOf[#/components/schemas/MessageContent]/oneOf[subschema #2]/items/cache_control` to the response with the `200` status
  - added the optional property `usage/oneOf[#/components/schemas/UsageInfo]/prompt_tokens_details` to the response with the `200` status
- **2026-10-23** `24af93ff5379`: 3 warning
  - removed the request property `allOf[subschema #2]/messages/items/content/oneOf[#/components/schemas/MessageContent]/oneOf[subschema #2]/items/cache_control`
  - removed the optional property `choices/items/message/content/oneOf[#/components/schemas/MessageContent]/oneOf[subschema #2]/items/cache_control` from the response with the `200` status
  - removed the optional property `usage/oneOf[#/components/schemas/UsageInfo]/prompt_tokens_details` from the response with the `200` status
- …earlier changes not shown

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/ai/v1/chat/completions/post.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
