Skip to content
Dashboard

Create Chat Completion

chat.create_completion(ChatCreateCompletionParams**kwargs) -> object
POST/chat/completions

Create Chat Completion

ParametersExpand Collapse
messages: Iterable[Message]
One of the following:
class MessageChatCompletionDeveloperMessageParam:

Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, developer messages replace the previous system messages.

content: Union[str, Iterable[MessageChatCompletionDeveloperMessageParamContentUnionMember1]]
One of the following:
str
Iterable[MessageChatCompletionDeveloperMessageParamContentUnionMember1]
text: str
type: Literal["text"]
role: Literal["developer"]
name: Optional[str]
class MessageChatCompletionSystemMessageParam:

Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, use developer messages for this purpose instead.

content: Union[str, Iterable[MessageChatCompletionSystemMessageParamContentUnionMember1]]
One of the following:
str
Iterable[MessageChatCompletionSystemMessageParamContentUnionMember1]
text: str
type: Literal["text"]
role: Literal["system"]
name: Optional[str]
class MessageChatCompletionUserMessageParam:

Messages sent by an end user, containing prompts or additional context information.

content: Union[str, Iterable[MessageChatCompletionUserMessageParamContentUnionMember1]]
One of the following:
str
Iterable[MessageChatCompletionUserMessageParamContentUnionMember1]
One of the following:
class MessageChatCompletionUserMessageParamContentUnionMember1ChatCompletionContentPartTextParam:

Learn about text inputs.

text: str
type: Literal["text"]
class MessageChatCompletionUserMessageParamContentUnionMember1ChatCompletionContentPartImageParam:

Learn about image inputs.

image_url: MessageChatCompletionUserMessageParamContentUnionMember1ChatCompletionContentPartImageParamImageURL
url: str
detail: Optional[Literal["auto", "low", "high"]]
One of the following:
"auto"
"low"
"high"
type: Literal["image_url"]
class MessageChatCompletionUserMessageParamContentUnionMember1ChatCompletionContentPartInputAudioParam:

Learn about audio inputs.

input_audio: MessageChatCompletionUserMessageParamContentUnionMember1ChatCompletionContentPartInputAudioParamInputAudio
data: str
format: Literal["wav", "mp3"]
One of the following:
"wav"
"mp3"
type: Literal["input_audio"]
class MessageChatCompletionUserMessageParamContentUnionMember1File:

Learn about file inputs for text generation.

file: MessageChatCompletionUserMessageParamContentUnionMember1FileFile
file_data: Optional[str]
file_id: Optional[str]
filename: Optional[str]
type: Literal["file"]
role: Literal["user"]
name: Optional[str]
class MessageChatCompletionAssistantMessageParam:

Messages sent by the model in response to user messages.

role: Literal["assistant"]
audio: Optional[MessageChatCompletionAssistantMessageParamAudio]

Data about a previous audio response from the model. Learn more.

id: str
content: Optional[Union[str, Iterable[MessageChatCompletionAssistantMessageParamContentUnionMember1], null]]
One of the following:
str
Iterable[MessageChatCompletionAssistantMessageParamContentUnionMember1]
One of the following:
class MessageChatCompletionAssistantMessageParamContentUnionMember1ChatCompletionContentPartTextParam:

Learn about text inputs.

text: str
type: Literal["text"]
class MessageChatCompletionAssistantMessageParamContentUnionMember1ChatCompletionContentPartRefusalParam:
refusal: str
type: Literal["refusal"]
function_call: Optional[MessageChatCompletionAssistantMessageParamFunctionCall]

Deprecated and replaced by tool_calls.

The name and arguments of a function that should be called, as generated by the model.

arguments: str
name: str
name: Optional[str]
refusal: Optional[str]
tool_calls: Optional[Iterable[MessageChatCompletionAssistantMessageParamToolCall]]
One of the following:
class MessageChatCompletionAssistantMessageParamToolCallChatCompletionMessageFunctionToolCallParam:

A call to a function tool created by the model.

id: str
function: MessageChatCompletionAssistantMessageParamToolCallChatCompletionMessageFunctionToolCallParamFunction

The function that the model called.

arguments: str
name: str
type: Literal["function"]
class MessageChatCompletionAssistantMessageParamToolCallChatCompletionMessageCustomToolCallParam:

A call to a custom tool created by the model.

id: str
custom: MessageChatCompletionAssistantMessageParamToolCallChatCompletionMessageCustomToolCallParamCustom

The custom tool that the model called.

input: str
name: str
type: Literal["custom"]
class MessageChatCompletionToolMessageParam:
content: Union[str, Iterable[MessageChatCompletionToolMessageParamContentUnionMember1]]
One of the following:
str
Iterable[MessageChatCompletionToolMessageParamContentUnionMember1]
text: str
type: Literal["text"]
role: Literal["tool"]
tool_call_id: str
class MessageChatCompletionFunctionMessageParam:
content: Optional[str]
name: str
role: Literal["function"]
class MessageCustomChatCompletionMessageParam:

Enables custom roles in the Chat Completion API.

role: str
content: Optional[Union[str, SequenceNotStr[MessageCustomChatCompletionMessageParamContentUnionMember1]]]
One of the following:
str
SequenceNotStr[MessageCustomChatCompletionMessageParamContentUnionMember1]
One of the following:
class MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartTextParam:

Learn about text inputs.

text: str
type: Literal["text"]
class MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartImageParam:

Learn about image inputs.

image_url: MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartImageParamImageURL
url: str
detail: Optional[Literal["auto", "low", "high"]]
One of the following:
"auto"
"low"
"high"
type: Literal["image_url"]
class MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartInputAudioParam:

Learn about audio inputs.

input_audio: MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartInputAudioParamInputAudio
data: str
format: Literal["wav", "mp3"]
One of the following:
"wav"
"mp3"
type: Literal["input_audio"]
class MessageCustomChatCompletionMessageParamContentUnionMember1File:

Learn about file inputs for text generation.

file: MessageCustomChatCompletionMessageParamContentUnionMember1FileFile
file_data: Optional[str]
file_id: Optional[str]
filename: Optional[str]
type: Literal["file"]
class MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartAudioParam:
audio_url: MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartAudioParamAudioURL
url: str
type: Literal["audio_url"]
class MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartVideoParam:
type: Literal["video_url"]
video_url: MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartVideoParamVideoURL
url: str
class MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartRefusalParam:
refusal: str
type: Literal["refusal"]
class MessageCustomChatCompletionMessageParamContentUnionMember1CustomChatCompletionContentSimpleImageParam:

A simpler version of the param that only accepts a plain image_url. This is supported by OpenAI API, although it is not documented.

Example: { "image_url": "https://example.com/image.jpg" }

image_url: Optional[str]
uuid: Optional[str]
class MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartImageEmbedsParam:
type: Literal["image_embeds"]
image_embeds: Optional[Union[str, Dict[str, str], null]]
One of the following:
str
Dict[str, str]
uuid: Optional[str]
class MessageCustomChatCompletionMessageParamContentUnionMember1ChatCompletionContentPartAudioEmbedsParam:
type: Literal["audio_embeds"]
audio_embeds: Optional[Union[str, Dict[str, str], null]]
One of the following:
str
Dict[str, str]
uuid: Optional[str]
class MessageCustomChatCompletionMessageParamContentUnionMember1CustomChatCompletionContentSimpleAudioParam:

A simpler version of the param that only accepts a plain audio_url.

Example: { "audio_url": "https://example.com/audio.mp3" }

audio_url: Optional[str]
class MessageCustomChatCompletionMessageParamContentUnionMember1CustomChatCompletionContentSimpleVideoParam:

A simpler version of the param that only accepts a plain audio_url.

Example: { "video_url": "https://example.com/video.mp4" }

uuid: Optional[str]
video_url: Optional[str]
str
class MessageCustomChatCompletionMessageParamContentUnionMember1CustomThinkCompletionContentParam:

A Think Completion Content Param that accepts a plain text and a boolean.

Example: { "thinking": "I am thinking about the answer", "closed": True, "type": "thinking" }

thinking: str
type: Literal["thinking"]
closed: Optional[bool]
name: Optional[str]
reasoning: Optional[str]
tool_call_id: Optional[str]
tool_calls: Optional[Iterable[MessageCustomChatCompletionMessageParamToolCall]]
id: str
function: MessageCustomChatCompletionMessageParamToolCallFunction

The function that the model called.

arguments: str
name: str
type: Literal["function"]
tools: Optional[Iterable[MessageCustomChatCompletionMessageParamTool]]
function: MessageCustomChatCompletionMessageParamToolFunction
name: str
description: Optional[str]
parameters: Optional[Dict[str, object]]
strict: Optional[bool]
type: Literal["function"]
class MessageMessage:
author: MessageMessageAuthor
role: Literal["user", "assistant", "system", 2 more]

The role of a message author (mirrors chat::Role).

One of the following:
"user"
"assistant"
"system"
"developer"
"tool"
name: Optional[str]
channel: Optional[str]
content: Optional[Iterable[object]]
content_type: Optional[str]
recipient: Optional[str]
add_generation_prompt: Optional[bool]

If true, the generation prompt will be added to the chat template. This is a parameter used by chat template in tokenizer config of the model.

add_special_tokens: Optional[bool]

If true, special tokens (e.g. BOS) will be added to the prompt on top of what is added by the chat template. For most models, the chat template takes care of adding the special tokens so this should be set to false (as is the default).

allowed_token_ids: Optional[Iterable[int]]
bad_words: Optional[SequenceNotStr[str]]
cache_salt: Optional[str]

If specified, the prefix cache will be salted with the provided string to prevent an attacker to guess prompts in multi-user environments. The salt should be random, protected from access by 3rd parties, and long enough to be unpredictable (e.g., 43 characters base64-encoded, corresponding to 256 bit).

chat_template: Optional[str]

A Jinja template to use for this conversion. As of transformers v4.44, default chat template is no longer allowed, so you must provide a chat template if the tokenizer does not define one.

chat_template_kwargs: Optional[Dict[str, object]]

Additional keyword args to pass to the template renderer. Will be accessible by the chat template.

continue_final_message: Optional[bool]

If this is set, the chat will be formatted so that the final message in the chat is open-ended, without any EOS tokens. The model will continue this message rather than starting a new one. This allows you to "prefill" part of the model's response for it. Cannot be used at the same time as add_generation_prompt.

documents: Optional[Iterable[Dict[str, str]]]

A list of dicts representing documents that will be accessible to the model if it is performing RAG (retrieval-augmented generation). If the template does not support RAG, this argument will have no effect. We recommend that each document should be a dict containing "title" and "text" keys.

echo: Optional[bool]

If true, the new message will be prepended with the last message if they belong to the same role.

frequency_penalty: Optional[float]
ignore_eos: Optional[bool]
include_reasoning: Optional[bool]
include_stop_str_in_output: Optional[bool]
kv_transfer_params: Optional[Dict[str, object]]

KVTransfer parameters used for disaggregated serving.

length_penalty: Optional[float]
logit_bias: Optional[Dict[str, float]]
logits_processors: Optional[SequenceNotStr[LogitsProcessor]]

A list of either qualified names of logits processors, or constructor objects, to apply when sampling. A constructor is a JSON object with a required 'qualname' field specifying the qualified name of the processor class/factory, and optional 'args' and 'kwargs' fields containing positional and keyword arguments. For example: {'qualname': 'my_module.MyLogitsProcessor', 'args': [1, 2], 'kwargs': {'param': 'value'}}.

One of the following:
str
class LogitsProcessorLogitsProcessorConstructor:
qualname: str
args: Optional[Iterable[object]]
kwargs: Optional[Dict[str, object]]
logprobs: Optional[bool]
max_completion_tokens: Optional[int]
Deprecatedmax_tokens: Optional[int]
min_p: Optional[float]
min_tokens: Optional[int]
mm_processor_kwargs: Optional[Dict[str, object]]

Additional kwargs to pass to the HF processor.

model: Optional[str]
n: Optional[int]
parallel_tool_calls: Optional[bool]
presence_penalty: Optional[float]
priority: Optional[int]

The priority of the request (lower means earlier handling; default: 0). Any priority other than 0 will raise an error if the served model does not use priority scheduling.

prompt_logprobs: Optional[int]
reasoning_effort: Optional[Literal["low", "medium", "high"]]
One of the following:
"low"
"medium"
"high"
repetition_penalty: Optional[float]
request_id: Optional[str]

The request_id related to this request. If the caller does not set it, a random_uuid will be generated. This id is used through out the inference process and return in response.

response_format: Optional[ResponseFormat]
One of the following:
class ResponseFormatResponseFormat:
type: Literal["text", "json_object", "json_schema"]
One of the following:
"text"
"json_object"
"json_schema"
json_schema: Optional[ResponseFormatResponseFormatJsonSchema]
name: str
description: Optional[str]
schema: Optional[Dict[str, object]]
strict: Optional[bool]
class ResponseFormatStructuralTagResponseFormat:
format: object
type: Literal["structural_tag"]
class ResponseFormatLegacyStructuralTagResponseFormat:
structures: Iterable[ResponseFormatLegacyStructuralTagResponseFormatStructure]
begin: str
end: str
schema: Optional[Dict[str, object]]
triggers: SequenceNotStr[str]
type: Literal["structural_tag"]
return_token_ids: Optional[bool]

If specified, the result will include token IDs alongside the generated text. In streaming mode, prompt_token_ids is included only in the first chunk, and token_ids contains the delta tokens for each chunk. This is useful for debugging or when you need to map generated text back to input tokens.

return_tokens_as_token_ids: Optional[bool]

If specified with 'logprobs', tokens are represented as strings of the form 'token_id:{token_id}' so that tokens that are not JSON-encodable can be identified.

seed: Optional[int]
maximum9223372036854776000
minimum-9223372036854776000
skip_special_tokens: Optional[bool]
spaces_between_special_tokens: Optional[bool]
stop: Optional[Union[str, SequenceNotStr[str], null]]
One of the following:
str
SequenceNotStr[str]
stop_token_ids: Optional[Iterable[int]]
stream: Optional[bool]
stream_options: Optional[StreamOptions]
continuous_usage_stats: Optional[bool]
include_usage: Optional[bool]
structured_outputs: Optional[StructuredOutputs]

Additional kwargs for structured outputs

_backend: Optional[str]
_backend_was_auto: Optional[bool]
choice: Optional[SequenceNotStr[str]]
disable_additional_properties: Optional[bool]
disable_any_whitespace: Optional[bool]
disable_fallback: Optional[bool]
grammar: Optional[str]
json: Optional[Union[str, Dict[str, object], null]]
One of the following:
str
Dict[str, object]
json_object: Optional[bool]
regex: Optional[str]
structural_tag: Optional[str]
whitespace_pattern: Optional[str]
temperature: Optional[float]
tool_choice: Optional[ToolChoice]
One of the following:
Literal["none", "auto", "required"]
One of the following:
"none"
"auto"
"required"
class ToolChoiceChatCompletionNamedToolChoiceParam:
function: ToolChoiceChatCompletionNamedToolChoiceParamFunction
name: str
type: Optional[Literal["function"]]
tools: Optional[Iterable[Tool]]
function: ToolFunction
name: str
description: Optional[str]
parameters: Optional[Dict[str, object]]
type: Optional[Literal["function"]]
top_k: Optional[int]
top_logprobs: Optional[int]
top_p: Optional[float]
truncate_prompt_tokens: Optional[int]
maximum9223372036854776000
minimum-1
user: Optional[str]
vllm_xargs: Optional[Dict[str, Union[str, float, SequenceNotStr[Union[str, float]]]]]

Additional request parameters with (list of) string or numeric values, used by custom extensions.

One of the following:
str
float
SequenceNotStr[Union[str, float]]
One of the following:
str
float
ReturnsExpand Collapse
object

Create Chat Completion

import os
from tzafon import Lightcone

client = Lightcone(
    api_key=os.environ.get("TZAFON_API_KEY"),  # This is the default and can be omitted
)
response = client.chat.create_completion(
    messages=[{
        "content": "string",
        "role": "developer",
    }],
)
print(response)
{}
Returns Examples
{}