# Completions

## Create a chat completion

**post** `/api/v1/chat/completions`

OpenAI-compatible Chat Completions. Supports streaming, function tools, structured output, and image and file input.

### Body Parameters

- `model: string`

  A model id from `GET /models`.

- `messages: array of object { role, content, name }  or object { role, content, name }  or object { role, content, name }  or 2 more`

  - `ChatCompletionSystemMessageDto object { role, content, name }`

    - `role: "system"`

      - `"system"`

    - `content: string or array of object { type, text }`

      Text, or a list of text parts.

      - `string`

      - `array of object { type, text }`

        - `type: "text"`

          - `"text"`

        - `text: string`

    - `name: optional string`

  - `ChatCompletionDeveloperMessageDto object { role, content, name }`

    - `role: "developer"`

      - `"developer"`

    - `content: string or array of object { type, text }`

      Text, or a list of text parts.

      - `string`

      - `array of object { type, text }`

        - `type: "text"`

          - `"text"`

        - `text: string`

    - `name: optional string`

  - `ChatCompletionUserMessageDto object { role, content, name }`

    - `role: "user"`

      - `"user"`

    - `content: string or array of object { type, text }  or object { type, image_url }  or object { type, file }`

      Text, or a list of text, image and file parts.

      - `string`

      - `array of object { type, text }  or object { type, image_url }  or object { type, file }`

        - `ChatCompletionTextPartDto object { type, text }`

          - `type: "text"`

            - `"text"`

          - `text: string`

        - `ChatCompletionImagePartDto object { type, image_url }`

          - `type: "image_url"`

            - `"image_url"`

          - `image_url: object { url, detail }`

            - `url: string`

              An https URL or an inline `data:image/...` URL.

            - `detail: optional "auto" or "low" or "high"`

              - `"auto"`

              - `"low"`

              - `"high"`

        - `ChatCompletionFilePartDto object { type, file }`

          - `type: "file"`

            - `"file"`

          - `file: object { file_data, filename }`

            - `file_data: string`

              The file as an inline data URL. File IDs are not supported.

            - `filename: string`

    - `name: optional string`

  - `ChatCompletionAssistantMessageDto object { role, content, name, 4 more }`

    - `role: "assistant"`

      - `"assistant"`

    - `content: optional string or array of object { type, text }`

      Null when the turn is only tool calls. A turn needs content, a refusal, reasoning or tool_calls.

      - `string`

      - `array of object { type, text }`

        - `type: "text"`

          - `"text"`

        - `text: string`

    - `name: optional string`

    - `refusal: optional string`

    - `tool_calls: optional array of object { id, type, function }`

      - `id: string`

      - `type: "function"`

        - `"function"`

      - `function: object { name, arguments }`

        - `name: string`

        - `arguments: string`

          The arguments as a JSON-encoded string.

    - `reasoning_content: optional string`

      The model's earlier reasoning, replayed so it can continue from it.

    - `reasoning: optional string`

      Alias of `reasoning_content`.

  - `ChatCompletionToolMessageDto object { role, content, tool_call_id }`

    - `role: "tool"`

      - `"tool"`

    - `content: string or array of object { type, text }`

      Text, or a list of text parts.

      - `string`

      - `array of object { type, text }`

        - `type: "text"`

          - `"text"`

        - `text: string`

    - `tool_call_id: string`

- `tools: optional array of object { type, function }`

  - `type: "function"`

    Only function tools are supported.

    - `"function"`

  - `function: object { name, description, parameters, strict }`

    - `name: string`

    - `description: optional string`

    - `parameters: optional map[unknown]`

      The function parameters as a JSON Schema object.

    - `strict: optional boolean`

- `tool_choice: optional "none" or "auto" or "required" or object { type, function }`

  Requires `tools`. A named function must be one of `tools`.

  - `"none" or "auto" or "required"`

    - `"none"`

    - `"auto"`

    - `"required"`

  - `ChatCompletionNamedToolChoiceDto object { type, function }`

    - `type: "function"`

      - `"function"`

    - `function: object { name }`

      - `name: string`

- `parallel_tool_calls: optional boolean`

- `response_format: optional object { type, json_schema }`

  - `type: "text" or "json_object" or "json_schema"`

    - `"text"`

    - `"json_object"`

    - `"json_schema"`

  - `json_schema: optional object { name, description, schema, strict }`

    Required when `type` is `json_schema`, and only then.

    - `name: string`

    - `description: optional string`

    - `schema: optional map[unknown]`

    - `strict: optional boolean`

- `reasoning_effort: optional "none" or "minimal" or "low" or 4 more`

  How much the model reasons before answering. Levels vary by model; `max` is beyond OpenAI's set and is supported by GLM and DeepSeek V4.

  - `"none"`

  - `"minimal"`

  - `"low"`

  - `"medium"`

  - `"high"`

  - `"xhigh"`

  - `"max"`

- `stream: optional boolean`

  Stream the reply as server-sent events.

- `stream_options: optional object { include_usage }`

  Requires `stream: true`.

  - `include_usage: optional boolean`

    Send a final chunk carrying token usage.

- `max_tokens: optional number`

  Do not send together with `max_completion_tokens`.

- `max_completion_tokens: optional number`

  Output token limit, reasoning included. Do not send together with `max_tokens`.

- `temperature: optional number`

- `top_p: optional number`

- `frequency_penalty: optional number`

- `presence_penalty: optional number`

- `seed: optional number`

- `stop: optional string or array of string`

  - `string`

  - `array of string`

- `metadata: optional map[string]`

  Up to 16 string pairs (keys up to 64 characters). Kept with a stored completion; never sent to the model provider.

- `user: optional string`

  Accepted for OpenAI compatibility; not sent to the model provider.

- `safety_identifier: optional string`

  Accepted for OpenAI compatibility; not sent to the model provider.

- `store: optional boolean`

  Keep the completion so it can be retrieved later.

### Returns

- `ChatCompletion object { id, object, created, 4 more }`

  - `id: string`

  - `object: "chat.completion"`

    - `"chat.completion"`

  - `created: number`

    Unix time in seconds.

  - `model: string`

  - `system_fingerprint: optional string`

  - `choices: array of object { index, finish_reason, message }`

    - `index: 0`

      - `0`

    - `finish_reason: "stop" or "length" or "tool_calls" or 2 more`

      - `"stop"`

      - `"length"`

      - `"tool_calls"`

      - `"content_filter"`

      - `"function_call"`

    - `message: ChatCompletionMessage`

      - `role: "assistant"`

        - `"assistant"`

      - `content: string`

      - `refusal: optional string`

      - `reasoning_content: optional string`

        The model's reasoning, for models that reason.

      - `tool_calls: optional array of object { id, type, function }`

        - `id: string`

        - `type: "function"`

          - `"function"`

        - `function: object { name, arguments }`

          - `name: string`

          - `arguments: string`

            The arguments as a JSON-encoded string.

  - `usage: ChatCompletionUsage`

    - `prompt_tokens: number`

    - `completion_tokens: number`

    - `total_tokens: number`

    - `prompt_tokens_details: optional object { cached_tokens, audio_tokens }`

      - `cached_tokens: optional number`

      - `audio_tokens: optional number`

    - `completion_tokens_details: optional object { reasoning_tokens, audio_tokens, accepted_prediction_tokens, rejected_prediction_tokens }`

      - `reasoning_tokens: optional number`

      - `audio_tokens: optional number`

      - `accepted_prediction_tokens: optional number`

      - `rejected_prediction_tokens: optional number`

### Example

```http
curl https://api.prod.adaptionlabs.ai/api/v1/chat/completions \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $ADAPTION_API_KEY" \
    -d '{
          "model": "glm-5.2",
          "messages": [
            {
              "role": "system",
              "content": "string"
            }
          ]
        }'
```

#### Response

```json
{
  "id": "id",
  "object": "chat.completion",
  "created": 0,
  "model": "model",
  "system_fingerprint": "system_fingerprint",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "content",
        "refusal": "refusal",
        "reasoning_content": "reasoning_content",
        "tool_calls": [
          {
            "id": "id",
            "type": "function",
            "function": {
              "name": "name",
              "arguments": "arguments"
            }
          }
        ]
      }
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "audio_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  }
}
```

## Domain Types

### Chat Completion

- `ChatCompletion object { id, object, created, 4 more }`

  - `id: string`

  - `object: "chat.completion"`

    - `"chat.completion"`

  - `created: number`

    Unix time in seconds.

  - `model: string`

  - `system_fingerprint: optional string`

  - `choices: array of object { index, finish_reason, message }`

    - `index: 0`

      - `0`

    - `finish_reason: "stop" or "length" or "tool_calls" or 2 more`

      - `"stop"`

      - `"length"`

      - `"tool_calls"`

      - `"content_filter"`

      - `"function_call"`

    - `message: ChatCompletionMessage`

      - `role: "assistant"`

        - `"assistant"`

      - `content: string`

      - `refusal: optional string`

      - `reasoning_content: optional string`

        The model's reasoning, for models that reason.

      - `tool_calls: optional array of object { id, type, function }`

        - `id: string`

        - `type: "function"`

          - `"function"`

        - `function: object { name, arguments }`

          - `name: string`

          - `arguments: string`

            The arguments as a JSON-encoded string.

  - `usage: ChatCompletionUsage`

    - `prompt_tokens: number`

    - `completion_tokens: number`

    - `total_tokens: number`

    - `prompt_tokens_details: optional object { cached_tokens, audio_tokens }`

      - `cached_tokens: optional number`

      - `audio_tokens: optional number`

    - `completion_tokens_details: optional object { reasoning_tokens, audio_tokens, accepted_prediction_tokens, rejected_prediction_tokens }`

      - `reasoning_tokens: optional number`

      - `audio_tokens: optional number`

      - `accepted_prediction_tokens: optional number`

      - `rejected_prediction_tokens: optional number`

### Chat Completion Chunk

- `ChatCompletionChunk object { id, object, created, 4 more }`

  - `id: string`

  - `object: "chat.completion.chunk"`

    - `"chat.completion.chunk"`

  - `created: number`

    Unix time in seconds.

  - `model: string`

  - `system_fingerprint: optional string`

  - `choices: array of object { index, finish_reason, delta }`

    Empty on the final usage chunk.

    - `index: 0`

      - `0`

    - `finish_reason: "stop" or "length" or "tool_calls" or 2 more`

      - `"stop"`

      - `"length"`

      - `"tool_calls"`

      - `"content_filter"`

      - `"function_call"`

    - `delta: object { role, content, refusal, 2 more }`

      - `role: optional "assistant"`

        - `"assistant"`

      - `content: optional string`

      - `refusal: optional string`

      - `reasoning_content: optional string`

      - `tool_calls: optional array of object { index, id, type, function }`

        - `index: number`

        - `id: optional string`

        - `type: optional "function"`

          - `"function"`

        - `function: optional object { name, arguments }`

          - `name: optional string`

          - `arguments: optional string`

            The next piece of the arguments.

  - `usage: optional ChatCompletionUsage`

    Set on the final chunk when `stream_options.include_usage` is true.

    - `prompt_tokens: number`

    - `completion_tokens: number`

    - `total_tokens: number`

    - `prompt_tokens_details: optional object { cached_tokens, audio_tokens }`

      - `cached_tokens: optional number`

      - `audio_tokens: optional number`

    - `completion_tokens_details: optional object { reasoning_tokens, audio_tokens, accepted_prediction_tokens, rejected_prediction_tokens }`

      - `reasoning_tokens: optional number`

      - `audio_tokens: optional number`

      - `accepted_prediction_tokens: optional number`

      - `rejected_prediction_tokens: optional number`

### Chat Completion Error

- `ChatCompletionError object { error }`

  - `error: object { message, type, code, param }`

    - `message: string`

    - `type: string`

    - `code: string`

    - `param: string`

### Chat Completion Message

- `ChatCompletionMessage object { role, content, refusal, 2 more }`

  - `role: "assistant"`

    - `"assistant"`

  - `content: string`

  - `refusal: optional string`

  - `reasoning_content: optional string`

    The model's reasoning, for models that reason.

  - `tool_calls: optional array of object { id, type, function }`

    - `id: string`

    - `type: "function"`

      - `"function"`

    - `function: object { name, arguments }`

      - `name: string`

      - `arguments: string`

        The arguments as a JSON-encoded string.

### Chat Completion Usage

- `ChatCompletionUsage object { prompt_tokens, completion_tokens, total_tokens, 2 more }`

  - `prompt_tokens: number`

  - `completion_tokens: number`

  - `total_tokens: number`

  - `prompt_tokens_details: optional object { cached_tokens, audio_tokens }`

    - `cached_tokens: optional number`

    - `audio_tokens: optional number`

  - `completion_tokens_details: optional object { reasoning_tokens, audio_tokens, accepted_prediction_tokens, rejected_prediction_tokens }`

    - `reasoning_tokens: optional number`

    - `audio_tokens: optional number`

    - `accepted_prediction_tokens: optional number`

    - `rejected_prediction_tokens: optional number`
