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

# POST /chat/completions

`POST /chat/completions`

Gets chat completions for the provided chat messages.
Completions support a wide variety of tasks and generate text that continues from or "completes"
provided prompt data. The method makes a REST API call to the `/chat/completions` route
on the given endpoint.

**Deprecated**: This API is deprecated. Use the OpenAI API instead.
See [migration guide](https://learn.microsoft.com/azure/foundry/how-to/model-inference-to-openai-migration).

## Query parameters

- `api-version` string, required

## Headers

- `extra-parameters` 'error' | 'drop' | 'pass-through'

## Request body

- ChatCompletionsOptions — The configuration information for a chat completions request. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
  - `messages` ChatRequestMessage[], required — The collection of context messages associated with this chat completions request. Typical usage begins with a chat message for the System role that provides instructions for the behavior of the assistant, followed by alternating messages between the User and Assistant roles.
    - `role` 'system' | 'developer' | 'user' | 'assistant' | 'tool', required — A description of the intended purpose of a message within a chat completions interaction.
  - `frequency_penalty` number, float — A value that influences the probability of generated tokens appearing based on their cumulative frequency in generated text. Positive values will make tokens less likely to appear as their frequency increases and decrease the likelihood of the model repeating the same statements verbatim. Supported range is [-2, 2].
  - `stream` boolean — A value indicating whether chat completions should be streamed for this request.
  - `presence_penalty` number, float — A value that influences the probability of generated tokens appearing based on their existing presence in generated text. Positive values will make tokens less likely to appear when they already exist and increase the model's likelihood to output new topics. Supported range is [-2, 2].
  - `temperature` number, float — The sampling temperature to use that controls the apparent creativity of generated completions. Higher values will make output more random while lower values will make results more focused and deterministic. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict. Supported range is [0, 1].
  - `top_p` number, float — An alternative to sampling with temperature called nucleus sampling. This value causes the model to consider the results of tokens with the provided probability mass. As an example, a value of 0.15 will cause only the tokens comprising the top 15% of probability mass to be considered. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict. Supported range is [0, 1].
  - `max_tokens` integer — The maximum number of tokens to generate.
  - `response_format` ChatCompletionsResponseFormat — Represents the format that the model must output. Use this to enable JSON mode instead of the default text mode. Note that to enable JSON mode, some AI models may also require you to instruct the model to produce JSON via a system or user message.
    - `type` string, required — The response format type to use for chat completions.
  - `stop` string[] — A collection of textual sequences that will end completions generation.
  - `tools` ChatCompletionsToolDefinition[] — A list of tools the model may request to call. Currently, only functions are supported as a tool. The model may respond with a function call request and provide the input arguments in JSON format for that function.
    - `type` 'function', required — The type of the tool. Currently, only `function` is supported.
    - `function` FunctionDefinition, required — The definition of a caller-specified function that chat completions may invoke in response to matching user input.
      - `name` string, required — The name of the function to be called.
      - `description` string — A description of what the function does. The model will use this description when selecting the function and interpreting its parameters.
      - `parameters` object — The parameters the function accepts, described as a JSON Schema object.
  - `tool_choice` unknown
  - `seed` integer — If specified, the system will make a best effort to sample deterministically such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed.
  - `model` string — ID of the specific AI model to use, if more than one model is available on the endpoint.
  - `modalities` ChatCompletionsModality[] — The modalities that the model is allowed to use for the chat completions response. The default modality is `text`. Indicating an unsupported modality combination results in a 422 error.

## Response `200`

The request has succeeded.

- ChatCompletions — Representation of the response data from a chat completions request. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
  - `id` string, required — A unique identifier associated with this chat completions response.
  - `object` 'chat.completion', required — The response object type, which is always `chat.completion`.
  - `created` integer, required — The first timestamp associated with generation activity for this completions response, represented as seconds since the beginning of the Unix epoch of 00:00 on 1 Jan 1970.
  - `model` string, required — The model used for the chat completion.
  - `choices` ChatChoice[], required — The collection of completions choices associated with this completions response. Generally, `n` choices are generated per provided prompt with a default value of 1. Token limits and other settings may limit the number of choices generated.
    - `index` integer, required — The ordered index associated with this chat completions choice.
    - `finish_reason` 'stop' | 'length' | 'content_filter' | 'tool_calls', required — Representation of the manner in which a completions response concluded.
    - `message` ChatResponseMessage, required — A representation of a chat message as received in a response.
      - `role` 'system' | 'developer' | 'user' | 'assistant' | 'tool', required — A description of the intended purpose of a message within a chat completions interaction.
      - `content` string, nullable, required — The content of the message.
      - `tool_calls` ChatCompletionsToolCall[] — The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat completions request to resolve as configured.
        - `id` string, required — The ID of the tool call.
        - `type` 'function', required — The type of tool call. Currently, only `function` is supported.
        - `function` FunctionCall, required — The name and arguments of a function that should be called, as generated by the model.
          - `name` string, required — The name of the function to call.
          - `arguments` string, required — The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
      - `audio` ChatCompletionsAudio — A representation of the audio generated by the model.
        - `id` string, required — Unique identifier for the audio response. This value can be used in chat history messages instead of passing the full audio object.
        - `expires_at` integer, required — The Unix timestamp (in seconds) at which the audio piece expires and can't be any longer referenced by its ID in multi-turn conversations.
        - `data` string, required — Base64 encoded audio data
        - `format` 'wav' | 'mp3' — A representation of the possible audio formats for audio.
        - `transcript` string, required — The transcript of the audio file.
  - `usage` CompletionsUsage, required — Representation of the token counts processed for a completions request. Counts consider all tokens across prompts, choices, choice alternates, best_of generations, and other consumers.
    - `completion_tokens` integer, required — The number of tokens generated across all completions emissions.
    - `prompt_tokens` integer, required — The number of tokens in the provided prompts for the completions request.
    - `total_tokens` integer, required — The total number of tokens processed for the completions request and response.
    - `completion_tokens_details` CompletionsUsageDetails — A breakdown of tokens used in a completion.
      - `audio_tokens` integer, required — The number of tokens corresponding to audio input.
      - `total_tokens` integer, required — The total number of tokens processed for the completions request and response.
    - `prompt_tokens_details` PromptUsageDetails — A breakdown of tokens used in the prompt/chat history.
      - `audio_tokens` integer, required — The number of tokens corresponding to audio input.
      - `cached_tokens` integer, required — The total number of tokens cached.

## Other responses

- `default` — An unexpected error response.

---

[API](https://skmtc.dev/azure/apis/ai-model-inference.md) · [All operations](https://skmtc.dev/azure/apis/ai-model-inference/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/azure/ai-model-inference/revisions/6a2cfd0ca1ff/schema)
