---
title: "POST /v1/chat/completions"
method: POST
path: "/v1/chat/completions"
---

# POST /v1/chat/completions

`POST /v1/chat/completions`

## Request body

- object
  - `model` 'alibaba/glm-5.2', required
  - `provider` string — Provider routing override. Use a source key such as `openai`, `openrouter`, `xai`, `google`, `alibaba`, `minimax`, `moonshot`, `baidu`, or `togetherai` to run that provider with no fallback; `auto` (default) uses the full fallback chain. Case-insensitive.
  - `messages` union[], required — A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text, documents (txt, pdf), images, and audio.
    - union
      - object
        - `role` 'user', required — The role of the author of the message — in this case, the user
        - `content` union, required — The contents of the user message.
          - string
          - object[]
            - `type` 'text', required — The type of the content part.
            - `text` string, required — The text content.
            - `cache_control` object
              - …
        - `name` string — An optional name for the participant. Provides the model information to differentiate between participants of the same role.
      - object
        - `content` union, required — The contents of the developer message.
          - string
          - object[]
            - `type` 'text', required — The type of the content part.
            - `text` string, required — The text content.
            - `cache_control` object
              - …
        - `role` 'developer', required — The role of the author of the message — in this case, the developer.
        - `name` string — An optional name for the participant. Provides the model information to differentiate between participants of the same role.
      - object
        - `role` 'system', required — The role of the author of the message — in this case, the system.
        - `content` union, required — The contents of the system message.
          - string
          - object[]
            - `type` 'text', required — The type of the content part.
            - `text` string, required — The text content.
            - `cache_control` object
              - …
        - `name` string — An optional name for the participant. Provides the model information to differentiate between participants of the same role.
      - object
        - `role` 'tool', required — The role of the author of the message — in this case, the tool.
        - `content` union, required — The contents of the tool message.
          - string
          - object[]
            - `type` 'text', required — The type of the content part.
            - `text` string, required — The text content.
            - `cache_control` object
              - …
        - `tool_call_id` string, required — Tool call that this message is responding to.
        - `name` string, nullable — An optional name for the participant. Provides the model information to differentiate between participants of the same role.
      - object
        - `role` 'assistant', required — The role of the author of the message — in this case, the Assistant.
        - `content` union — The contents of the Assistant message. Required unless tool_calls or function_call is specified.
          - string — The contents of the Assistant message.
          - object[] — An array of content parts with a defined type. Can be one or more of type text, or exactly one of type refusal.
            - `type` 'text', required — The type of the content part.
            - `text` string, required — The text content.
            - `cache_control` object
              - …
          - unknown
        - `name` string — An optional name for the participant. Provides the model information to differentiate between participants of the same role.
        - `tool_calls` union[] — The tool calls generated by the model, such as function calls.
          - union
            - object
              - …
            - object
              - …
        - `refusal` string, nullable — The refusal message by the Assistant.
  - `max_completion_tokens` integer — An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
  - `max_tokens` number — The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API.
  - `stream` boolean — If set to True, the model response data will be streamed to the client as it is generated using server-sent events.
  - `stream_options` object
    - `include_usage` boolean, required
  - `tools` union[] — A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.
    - union
      - union
        - object
          - `type` 'function', required — The type of the tool. Currently, only function is supported.
          - `function` object, required
            - `description` string — A description of what the function does, used by the model to choose when and how to call the function.
            - `name` string, required — The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
            - `parameters` object
            - `strict` boolean, nullable — Whether to enable strict schema adherence when generating the function call. If set to True, the model will follow the exact schema defined in the parameters field. Only a subset of JSON Schema is supported when strict is True.
          - `cache_control` object
            - `type` 'ephemeral', required
            - `ttl` '5m' | '1h'
        - object
          - `type` 'custom', required — The type of the tool. Currently, only function is supported.
          - `custom` object, required
            - `name` string, required — The name of the custom tool, used to identify it in tool calls.
            - `description` string — Optional description of the custom tool, used to provide more context.
            - `format` union, required — The input format for the custom tool. Default is unconstrained text.
              - …
          - `cache_control` object
            - `type` 'ephemeral', required
            - `ttl` '5m' | '1h'
      - object
        - `type` string, required
  - `tool_choice` union — Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools. Specifying a particular tool via {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool. none is the default when no tools are present. auto is the default if tools are present.
    - 'none' | 'auto' | 'required' — none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools.
    - object — Specifies a tool the model should use. Use to force the model to call a specific function.
      - `type` 'function', required — The type of the tool. Currently, only function is supported.
      - `function` object, required
        - `name` string, required — The name of the function to call.
    - object — Constrains the tools available to the model to a pre-defined set.
      - `type` 'allowed_tools', required — The type of the tool. Currently, only function is supported.
      - `allowed_tools` object, required
        - `mode` 'auto' | 'required', required — Constrains the tools available to the model to a pre-defined set. - auto allows the model to pick from among the allowed tools and generate a message. - required requires the model to call one or more of the allowed tools.
        - `tools` object[], required — A list of tool definitions that the model should be allowed to call.
    - object — Specifies a tool the model should use. Use to force the model to call a specific function.
      - `type` 'function', required — The type of the tool. Currently, only function is supported.
      - `function` 'name', required — The name of the function to call.
    - object — Specifies a tool the model should use. Use to force the model to call a specific custom tool.
      - `type` 'custom', required — The type of the tool. Currently, only function is supported.
      - `custom` 'name', required — The name of the custom tool to call.
  - `normalize_tool_schemas` boolean — Enable provider compatibility normalization for tool function JSON schemas.
  - `parallel_tool_calls` boolean — Whether to enable parallel function calling during tool use.
  - `temperature` number — What sampling temperature to use. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.
  - `top_p` number — An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
  - `stop` union — Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
    - string
    - string[]
    - unknown
  - `response_format` union — An object specifying the format that the model must output.
    - object — Default response format. Used to generate text responses.
      - `type` 'text', required — The type of response format being defined. Always text.
    - object — An older method of generating JSON responses. Using json_schema is recommended for models that support it. Note that the model will not generate JSON without a system or user message instructing it to do so.
      - `type` 'json_object', required — The type of response format being defined. Always json_object.
    - object — JSON Schema response format. Used to generate structured JSON responses.
      - `type` 'json_schema', required — The type of response format being defined. Always json_schema.
      - `json_schema` object, required — JSON Schema response format. Used to generate structured JSON responses.
        - `name` string, required — The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
        - `schema` object — The schema for the response format, described as a JSON Schema object.
        - `strict` boolean, nullable — Whether to enable strict schema adherence when generating the output. If set to True, the model will always follow the exact schema defined in the schema field. Only a subset of JSON Schema is supported when strict is True.
        - `description` string — A description of what the response format is for, used by the model to determine how to respond in the format.
  - `enable_thinking` boolean — Specifies whether to use the thinking mode.
  - `thinking_budget` integer — The maximum reasoning length, effective only when enable_thinking is set to true.

## Response `200`

Successful response.

- object
  - `id` string, required — A unique identifier for the chat completion.
  - `object` 'chat.completion', required — The object type.
  - `created` number, required — The Unix timestamp (in seconds) of when the chat completion was created.
  - `choices` object[], required
    - `index` number, required — The index of the choice in the list of choices.
    - `message` object, required — A chat completion message generated by the model.
      - `role` string, required — The role of the author of this message.
      - `content` string, required — The contents of the message.
      - `refusal` string, nullable — The refusal message generated by the model.
      - `annotations` object[], nullable — Annotations for the message, when applicable, as when using the web search tool.
        - `type` 'url_citation', required — The type of the URL citation. Always url_citation.
        - `url_citation` object, required — A URL citation when using web search.
          - `end_index` integer, required — The index of the last character of the URL citation in the message.
          - `start_index` integer, required — The index of the first character of the URL citation in the message.
          - `title` string, required — The title of the web resource.
          - `url` string, required — The URL of the web resource.
      - `audio` object, nullable — A chat completion message generated by the model.
        - `id` string, required — Unique identifier for this audio response.
        - `data` string, required — Base64 encoded audio bytes generated by the model, in the format specified in the request.
        - `transcript` string, required — Transcript of the audio generated by the model.
        - `expires_at` integer, required — The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.
      - `tool_calls` union[], nullable — The tool calls generated by the model, such as function calls.
        - union
          - object
            - `id` string, required — The ID of the tool call.
            - `type` 'function', required — The type of the tool.
            - `function` object, required — The function that the model called.
              - …
          - object
            - `id` string, required — The ID of the tool call.
            - `type` 'custom', required — The type of the tool.
            - `custom` object, required — The custom tool that the model called.
              - …
    - `finish_reason` 'stop' | 'length' | 'content_filter' | 'tool_calls', required — The reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence, length if the maximum number of tokens specified in the request was reached, content_filter if content was omitted due to a flag from our content filters, tool_calls if the model called a tool
    - `logprobs` object, nullable — Log probability information for the choice.
      - `content` object[], required — A list of message content tokens with log probability information.
        - `bytes` integer[], required — A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
        - `logprob` number, required — The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
        - `token` string, required — The token.
        - `top_logprobs` object[], nullable — List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
          - `bytes` integer[], nullable — A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
          - `logprob` number, required — The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
          - `token` string, required — The token.
      - `refusal` object[], required — A list of message refusal tokens with log probability information.
        - `bytes` integer[], required — A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
        - `logprob` number, required — The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
        - `token` string, required — The token.
        - `top_logprobs` object[], nullable — List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
          - `bytes` integer[], nullable — A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
          - `logprob` number, required — The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
          - `token` string, required — The token.
  - `model` string, required — The model used for the chat completion.
  - `usage` object, required — Usage statistics for the completion request.
    - `prompt_tokens` number, required — Number of tokens in the prompt.
    - `completion_tokens` number, required — Number of tokens in the generated completion.
    - `total_tokens` number, required — Total number of tokens used in the request (prompt + completion).
    - `completion_tokens_details` object, nullable — Breakdown of tokens used in a completion.
      - `accepted_prediction_tokens` integer, nullable — When using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.
      - `audio_tokens` integer, nullable — Audio input tokens generated by the model.
      - `reasoning_tokens` integer, nullable — Tokens generated by the model for reasoning.
      - `rejected_prediction_tokens` integer, nullable — When using Predicted Outputs, the number of tokens in the prediction that did not appear in the completion. However, like reasoning tokens, these tokens are still counted in the total completion tokens for purposes of billing, output, and context window limits.
    - `prompt_tokens_details` object, nullable — Breakdown of tokens used in the prompt.
      - `audio_tokens` integer, nullable — Audio input tokens present in the prompt.
      - `cached_tokens` integer, nullable — Cached tokens present in the prompt.
  - `meta` object, nullable — Additional details about the generation.
    - `usage` object, nullable
      - `credits_used` number, required — The number of tokens consumed during generation.
      - `usd_spent` number, required — The total amount of money spent by the user in USD.

---

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