---
title: "Chat Completions"
method: POST
path: "/v1/chat/completions"
tags: ["chat"]
---

# Chat Completions

`POST /v1/chat/completions`

## Headers

- `Authorization` string, required
- `api-subscription-key` string, nullable

## Request body

- CreateChatCompletionRequest
  - `messages` ChatCompletionRequestMessage[], required — A list of messages comprising the conversation so far.
    - union
      - object — ChatCompletionRequestAssistantMessage variant
        - `role` 'assistant', required — Discriminator value: assistant
        - `content` string, nullable — The contents of the assistant message
        - `tool_calls` ChatCompletionMessageToolCall[], nullable — The tool calls generated by the model.
          - `id` string, required — The ID of the tool call.
          - `type` 'function', required — The type of the tool call, currently only `function`.
          - `function` FunctionCall, required
            - `name` string, required — The name of the function to call.
            - `arguments` string, required — The arguments to call the function with, as a JSON string.
      - object — ChatCompletionRequestSystemMessage variant
        - `role` 'system', required — The role of the messages author, in this case `system`.
        - `content` string, required — The contents of the system message.
      - object — ChatCompletionRequestToolMessage variant
        - `role` 'tool', required — The role of the messages author, in this case `tool`.
        - `content` string, required — The contents of the tool message.
        - `tool_call_id` string, required — Tool call that this message is responding to.
      - object — ChatCompletionRequestUserMessage variant
        - `role` 'user', required — The role of the messages author, in this case `user`.
        - `content` string, required — The contents of the user message.
  - `model` 'sarvam-105b' | 'sarvam-30b', required — Supported chat completion model IDs: `sarvam-30b`, `sarvam-105b`.
  - `temperature` number, double, nullable — What sampling temperature to use, between 0 and 2. 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, double, nullable — 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.
  - `reasoning_effort` 'low' | 'medium' | 'high'
  - `max_tokens` integer, nullable — The maximum number of tokens that can be generated in the chat completion.
  - `stream` boolean, nullable — If set to true, the model response data will be streamed to the client as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
  - `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[]
  - `n` integer, nullable — How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs.
  - `seed` integer, nullable — This feature is in Beta. If specified, our 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, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
  - `frequency_penalty` number, double, nullable — Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
  - `presence_penalty` number, double, nullable — Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
  - `wiki_grounding` boolean, nullable — If set to true, the model response will be wiki grounded.
  - `tools` ChatCompletionTool[], nullable — A list of tools the model may call. Currently, only functions are supported as a tool.
    - `type` 'function', required — The type of the tool. Currently, only `function` is supported.
    - `function` FunctionDefinition, required
      - `name` string, required — The name of the function to be called.
      - `description` string, nullable — A description of what the function does.
      - `parameters` object, nullable — The parameters the function accepts, described as a JSON Schema object.
  - `tool_choice` union
    - 'none' | 'auto' | 'required'
    - ChatCompletionNamedToolChoice
      - `type` 'function', required — The type of the tool. Currently, only `function` is supported.
      - `function` ChatCompletionNamedToolChoiceFunction, required
        - `name` string, required — The name of the function to call.
  - `response_format` union
    - object — ResponseFormatText variant
      - `type` 'text', required — The type of response format being defined. Always `text`.
    - object — ResponseFormatJsonObject variant
      - `type` 'json_object', required — The type of response format being defined. Always `json_object`.
    - object — ResponseFormatJsonSchema variant
      - `type` 'json_schema', required — The type of response format being defined. Always `json_schema`.
      - `json_schema` JsonSchemaDefinition, required
        - `name` string, required — The name of the response format. Must contain only alphanumeric characters, underscores and dashes.
        - `description` string, nullable — A description of what the response format is for, used by the model to determine how to respond in the format.
        - `schema` JsonSchemaDefinitionSchema — 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.

## Response `200`

Successful Response

- CreateChatCompletionResponse
  - `id` string, required — A unique identifier for the chat completion.
  - `choices` Choice[], required — A list of chat completion choices. Can be more than one if `n` is greater than 1.
    - `finish_reason` 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call', required
    - `index` integer, required — The index of the choice in the list of choices.
    - `logprobs` object, nullable
    - `message` ChatCompletionResponseMessage, required
      - `content` string, nullable, required — The contents of the message.
      - `refusal` string, nullable
      - `reasoning_content` string, nullable — The contents of the reasoning message.
      - `role` 'assistant', required
      - `tool_calls` ChatCompletionMessageToolCall[], nullable — The tool calls generated by the model.
        - `id` string, required — The ID of the tool call.
        - `type` 'function', required — The type of the tool call, currently only `function`.
        - `function` FunctionCall, required
          - `name` string, required — The name of the function to call.
          - `arguments` string, required — The arguments to call the function with, as a JSON string.
  - `created` integer, required — The Unix timestamp (in seconds) of when the chat completion was created.
  - `model` string, required — The model used for the chat completion.
  - `object` 'chat.completion', required — The object type, which is always `chat.completion`.
  - `service_tier` string, nullable
  - `system_fingerprint` string, nullable
  - `usage` CompletionUsage
    - `completion_tokens` integer, required — Number of tokens in the generated completion.
    - `prompt_tokens` integer, required — Number of tokens in the prompt.
    - `total_tokens` integer, required — Total number of tokens used in the request (prompt + completion).
    - `completion_tokens_details` object, nullable
    - `prompt_tokens_details` object, nullable

## Other responses

- `400` — Bad Request
- `403` — Forbidden
- `422` — Unprocessable Entity
- `429` — Quota Exceeded
- `500` — Internal Server Error

---

[API](https://skmtc.dev/sarvam/apis/endpoints.md) · [All operations](https://skmtc.dev/sarvam/apis/endpoints/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/sarvam/endpoints/revisions/2b7f7955b147/schema)
