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

# Openai Chat Completions

`POST /v1/chat/completions`

## Headers

- `x-deepinfra-source` string, nullable
- `xi-api-key` string, nullable
- `x-api-key` string, nullable

## Request body

- OpenAIChatCompletionsIn
  - `service_tier` 'default' | 'priority' | 'flex'
  - `fail_fast` boolean — If true, the request is rejected immediately with HTTP 429 when the model has no spare capacity, instead of waiting in the queue. Opt-in; the default (false) keeps standard queueing behavior.
  - `models` string[], nullable — Ordered list of up to 4 fallback models. The request is attempted on each model in order: when a model rejects it for lack of capacity (HTTP 429 model-busy / flex no-capacity), the next model is tried server-side. The first model that accepts serves the request; the response's model field and billing reflect that model, at that model's pricing. Models before the last are attempted without queueing (as if fail_fast were set); the last model honors the request's own fail_fast value. When models is set, the model field is ignored. Entries must be plain model names (no deploy_id:, custom_hostport, or :revision specifiers); duplicate entries are ignored, keeping the first occurrence.
  - `model` string, required — model name
  - `messages` union[], required — conversation messages: (user,assistant,tool)*,user including one system message anywhere
    - union
      - ChatCompletionToolMessage
        - `cache_control` object, nullable — Cache control for prompt caching
        - `role` 'tool' — the role of the author of this message
        - `content` union, required — the message content
          - string
          - ChatCompletionContentPartText[]
            - `type` 'text', required
            - `text` string, required
            - `prompt_cache_breakpoint` PromptCacheBreakpoint
              - …
        - `tool_call_id` string, required
      - ChatCompletionAssistantMessage
        - `cache_control` object, nullable — Cache control for prompt caching
        - `role` 'assistant' — the role of the author of this message
        - `content` union — the message content
          - string
          - ChatCompletionContentPartText[]
            - `type` 'text', required
            - `text` string, required
            - `prompt_cache_breakpoint` PromptCacheBreakpoint
              - …
        - `reasoning_content` string, nullable — the reasoning content
        - `name` string, nullable
        - `tool_calls` ChatCompletionMessageToolCall[], nullable — the tool calls generated by the mode
          - `id` string, required — the id of the tool call
          - `type` string, required — the type of the tool call. only function is supported currently
          - `function` Function, required
            - `name` string, required — the name of the function to call
            - `arguments` string, required — the function arguments, generated by the model in JSON format. the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema
      - ChatCompletionUserMessage
        - `cache_control` object, nullable — Cache control for prompt caching
        - `role` 'user' — the role of the author of this message
        - `content` union, required — the message content
          - string
          - union[]
            - union
              - …
        - `name` string, nullable
      - ChatCompletionSystemMessage
        - `cache_control` object, nullable — Cache control for prompt caching
        - `role` 'system' — the role of the author of this message
        - `content` union, required — the message content
          - string
          - ChatCompletionContentPartText[]
            - `type` 'text', required
            - `text` string, required
            - `prompt_cache_breakpoint` PromptCacheBreakpoint
              - …
        - `name` string, nullable
  - `stream` boolean — whether to stream the output via SSE or return the full response
  - `temperature` number — 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
  - `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.
  - `min_p` number — Float that represents the minimum probability for a token to be considered, relative to the probability of the most likely token. Must be in [0, 1]. Set to 0 to disable this.
  - `top_k` integer — Sample from the best k (number of) tokens. 0 means off
  - `max_tokens` integer, nullable — The maximum number of tokens to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. If explicitly set to None it will be the model's max context length minus input length or 65536, whichever is smaller.
  - `stop` union — up to 16 sequences where the API will stop generating further tokens
    - string
    - string[]
  - `stop_token_ids` integer[], nullable — Up to 16 token IDs where the API will stop generating further tokens. Merged with the model's built-in stop tokens. Intended for private deployments.
  - `n` integer — number of sequences to return
  - `presence_penalty` number — 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.
  - `frequency_penalty` number — Positive values penalize new tokens based on how many times they appear in the text so far, increasing the model's likelihood to talk about new topics.
  - `tools` FunctionTool[], nullable — A list of tools the model may call. Currently, only functions are supported as a tool.
    - `cache_control` object, nullable — Cache control for prompt caching
    - `type` string
    - `function` FunctionDefinition, required
      - `name` string, required
      - `description` string, nullable
      - `parameters` object, nullable
  - `tool_choice` union — Controls which (if any) function is called by the model. none means the model will not call a function and instead generates a message. auto means the model can pick between generating a message or calling a function. required means the model must call a function. defined tool means the model must call that specific tool. none is the default when no functions are present. auto is the default if functions are present.
    - 'none' | 'auto' | 'required'
    - FunctionTool
      - `cache_control` object, nullable — Cache control for prompt caching
      - `type` string
      - `function` FunctionDefinition, required
        - `name` string, required
        - `description` string, nullable
        - `parameters` object, nullable
  - `response_format` union — The format of the response. Currently, only json is supported.
    - TextResponseFormat
      - `type` 'text'
    - JsonObjectResponseFormat
      - `type` 'json_object'
    - JsonSchemaResponseFormat
      - `type` 'json_schema'
      - `json_schema` JsonSchema, required
        - `name` string, required — Name identifier for the JSON schema
        - `schema` object, required — The actual JSON schema definition
    - RegexResponseFormat
      - `type` 'regex'
      - `regex` string, required — Regex pattern for structured output when type is 'regex'
  - `repetition_penalty` number — Alternative penalty for repetition, but multiplicative instead of additive (> 1 penalize, < 1 encourage)
  - `user` string, nullable — A unique identifier representing your end-user, which can help monitor and detect abuse. Avoid sending us any identifying information. We recommend hashing user identifiers.
  - `seed` integer, nullable — Seed for random number generator. If not provided, a random seed is used. Determinism is not guaranteed.
  - `logprobs` boolean, nullable — Whether to return log probabilities of the output tokens or not.If true, returns the log probabilities of each output token returned in the `content` of `message`.
  - `stream_options` StreamOptions
    - `include_usage` boolean — whether to include usage data
    - `continuous_usage_stats` boolean — whether to include usage stats continuously with each streaming event
  - `reasoning_effort` 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max', nullable — Constrains effort on reasoning for reasoning models. Currently supported values are none, minimal, low, medium, high, xhigh, and max. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response. Setting to none disables reasoning entirely if the model supports.
  - `reasoning` ChatReasoningSettings
    - `effort` 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max', nullable — Constrains effort on reasoning for reasoning models. Set to none to disable reasoning entirely if the model supports it.
    - `enabled` boolean, nullable — Enable or disable reasoning with default parameters.
  - `prompt_cache_key` string, nullable — A key to identify prompt cache for reuse across requests. If provided, the prompt will be cached and can be reused in subsequent requests with the same key.
  - `prompt_cache_options` PromptCacheOptions
    - `mode` 'explicit' | 'implicit', nullable — Prompt caching mode; 'explicit' requests explicit caching.
    - `ttl` '5m' | '1h', nullable — Requested cache retention for this request's prefix.
  - `chat_template_kwargs` object, nullable — Chat template kwargs.
  - `continue_final_message` boolean, nullable — If set, the final assistant message is used as a prefix for the model to continue generating from, rather than starting a new turn. Only applicable when the last message in the conversation is an assistant message.
  - `ignore_eos` boolean, nullable — Keep generating until max_tokens instead of stopping at the end-of-sequence token. Only honoured on models tagged with the allow_ignore_eos feature flag; ignored otherwise. Intended for benchmarking, where a fixed output length is needed.

## Response `200`

Successful Response

- unknown

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/deepinfra/apis/deepinfra-api.md) · [All operations](https://skmtc.net/deepinfra/apis/deepinfra-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/deepinfra/deepinfra-api/revisions/6b75203534bb/schema)
