Skip to content
SupportLogin
Create a chat completion

Create a chat completion

chat.completions.create(CompletionCreateParams**kwargs) -> ChatCompletion
POST/api/v1/chat/completions

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

ParametersExpand Collapse
model: str

A model id from GET /models.

minLength1
maxLength128
messages: Iterable[Message]
One of the following:
class MessageChatCompletionSystemMessageDto: …
role: Literal["system"]
content: Union[str, Iterable[MessageChatCompletionSystemMessageDtoContentUnionMember1]]

Text, or a list of text parts.

One of the following:
str
Iterable[MessageChatCompletionSystemMessageDtoContentUnionMember1]
type: Literal["text"]
text: str
name: Optional[str]
minLength1
maxLength64
class MessageChatCompletionDeveloperMessageDto: …
role: Literal["developer"]
content: Union[str, Iterable[MessageChatCompletionDeveloperMessageDtoContentUnionMember1]]

Text, or a list of text parts.

One of the following:
str
Iterable[MessageChatCompletionDeveloperMessageDtoContentUnionMember1]
type: Literal["text"]
text: str
name: Optional[str]
minLength1
maxLength64
class MessageChatCompletionUserMessageDto: …
role: Literal["user"]
content: Union[str, Iterable[MessageChatCompletionUserMessageDtoContentUnionMember1]]

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

One of the following:
str
Iterable[MessageChatCompletionUserMessageDtoContentUnionMember1]
One of the following:
class MessageChatCompletionUserMessageDtoContentUnionMember1ChatCompletionTextPartDto: …
type: Literal["text"]
text: str
class MessageChatCompletionUserMessageDtoContentUnionMember1ChatCompletionImagePartDto: …
type: Literal["image_url"]
image_url: MessageChatCompletionUserMessageDtoContentUnionMember1ChatCompletionImagePartDtoImageURL
url: str

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

detail: Optional[Literal["auto", "low", "high"]]
One of the following:
"auto"
"low"
"high"
class MessageChatCompletionUserMessageDtoContentUnionMember1ChatCompletionFilePartDto: …
type: Literal["file"]
file: MessageChatCompletionUserMessageDtoContentUnionMember1ChatCompletionFilePartDtoFile
file_data: str

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

filename: str
minLength1
maxLength256
name: Optional[str]
minLength1
maxLength64
class MessageChatCompletionAssistantMessageDto: …
role: Literal["assistant"]
content: Optional[Union[str, Iterable[MessageChatCompletionAssistantMessageDtoContentUnionMember1], null]]

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

One of the following:
str
Iterable[MessageChatCompletionAssistantMessageDtoContentUnionMember1]
type: Literal["text"]
text: str
name: Optional[str]
minLength1
maxLength64
refusal: Optional[str]
tool_calls: Optional[Iterable[MessageChatCompletionAssistantMessageDtoToolCall]]
id: str
type: Literal["function"]
function: MessageChatCompletionAssistantMessageDtoToolCallFunction
name: str
minLength1
maxLength64
arguments: str

The arguments as a JSON-encoded string.

reasoning_content: Optional[str]

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

reasoning: Optional[str]

Alias of reasoning_content.

class MessageChatCompletionToolMessageDto: …
role: Literal["tool"]
content: Union[str, Iterable[MessageChatCompletionToolMessageDtoContentUnionMember1]]

Text, or a list of text parts.

One of the following:
str
Iterable[MessageChatCompletionToolMessageDtoContentUnionMember1]
type: Literal["text"]
text: str
tool_call_id: str
minLength1
tools: Optional[Iterable[Tool]]
type: Literal["function"]

Only function tools are supported.

function: ToolFunction
name: str
minLength1
maxLength64
description: Optional[str]
parameters: Optional[Dict[str, object]]

The function parameters as a JSON Schema object.

strict: Optional[bool]
tool_choice: Optional[ToolChoice]

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

One of the following:
Literal["none", "auto", "required"]
One of the following:
"none"
"auto"
"required"
class ToolChoiceChatCompletionNamedToolChoiceDto: …
type: Literal["function"]
function: ToolChoiceChatCompletionNamedToolChoiceDtoFunction
name: str
minLength1
maxLength64
parallel_tool_calls: Optional[bool]
response_format: Optional[ResponseFormat]
type: Literal["text", "json_object", "json_schema"]
One of the following:
"text"
"json_object"
"json_schema"
json_schema: Optional[ResponseFormatJsonSchema]

Required when type is json_schema, and only then.

name: str
minLength1
maxLength64
description: Optional[str]
schema: Optional[Dict[str, object]]
strict: Optional[bool]
reasoning_effort: Optional[Literal["none", "minimal", "low", 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.

One of the following:
"none"
"minimal"
"low"
"medium"
"high"
"xhigh"
"max"
stream: Optional[Literal[false]]

Stream the reply as server-sent events.

stream_options: Optional[StreamOptions]

Requires stream: true.

include_usage: Optional[bool]

Send a final chunk carrying token usage.

max_tokens: Optional[int]

Do not send together with max_completion_tokens.

minimum1
maximum2147483647
max_completion_tokens: Optional[int]

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

minimum1
maximum2147483647
temperature: Optional[float]
minimum0
maximum2
top_p: Optional[float]
minimum0
maximum1
frequency_penalty: Optional[float]
minimum-2
maximum2
presence_penalty: Optional[float]
minimum-2
maximum2
seed: Optional[int]
stop: Optional[Union[str, Sequence[str]]]
One of the following:
str
Sequence[str]
metadata: Optional[Dict[str, str]]

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

user: Optional[str]

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

maxLength256
safety_identifier: Optional[str]

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

maxLength64
store: Optional[bool]

Keep the completion so it can be retrieved later.

ReturnsExpand Collapse
class ChatCompletion: …
id: str
object: Literal["chat.completion"]
created: int

Unix time in seconds.

model: str
system_fingerprint: Optional[str]
choices: List[Choice]
index: Literal[0]
finish_reason: Literal["stop", "length", "tool_calls", 2 more]
One of the following:
"stop"
"length"
"tool_calls"
"content_filter"
"function_call"
role: Literal["assistant"]
content: Optional[str]
refusal: Optional[str]
reasoning_content: Optional[str]

The model’s reasoning, for models that reason.

tool_calls: Optional[List[ToolCall]]
id: str
type: Literal["function"]
function: ToolCallFunction
name: str
minLength1
maxLength64
arguments: str

The arguments as a JSON-encoded string.

prompt_tokens: int
completion_tokens: int
total_tokens: int
prompt_tokens_details: Optional[PromptTokensDetails]
cached_tokens: Optional[int]
audio_tokens: Optional[int]
completion_tokens_details: Optional[CompletionTokensDetails]
reasoning_tokens: Optional[int]
audio_tokens: Optional[int]
accepted_prediction_tokens: Optional[int]
rejected_prediction_tokens: Optional[int]

Create a chat completion

import os
from adaption import Adaption

client = Adaption(
    api_key=os.environ.get("ADAPTION_API_KEY"),  # This is the default and can be omitted
)
for completion in client.chat.completions.create(
    model="glm-5.2",
    messages=[{
        "role": "system",
        "content": "string",
    }],
):
  print(completion)
{
  "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
    }
  }
}
Returns Examples
{
  "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
    }
  }
}