Create chat completion
/v1/chat/completionsCreate a chat completion response for the given conversation.
Authentication
Authorization Bearer
API key as bearer token in Authorization header.
Request Body
messagesarrayrequiredConversation messages.
messages.rolestringrequiredMessage role, such as system, user, assistant, or tool.
messages.contentstring | object[]requiredMessage content. Multimodal models may accept structured content parts.
messages.namestringOptional participant name.
messages.tool_call_idstringTool call ID for tool messages.
modelstringrequiredModel ID.
temperaturenumberControls randomness in generated output. Higher values make responses more varied; lower values make responses more deterministic.
top_pnumberControls nucleus sampling by limiting token choices to a cumulative probability mass. Lower values make output more focused; higher values allow more variety.
max_completion_tokensintegerMaximum number of tokens the model may generate in the response.
top_kintegerTop-k sampling cutoff.
frequency_penaltynumberFrequency-based repetition penalty.
presence_penaltynumberPresence-based novelty penalty.
context_lengthintegerContext window length.
streambooleanStreaming response flag.
stream_optionsobjectStreaming response configuration.
stream_options.include_usagebooleanInclude usage information in the streaming response.
toolsarrayTool definitions.
tools.typestringTool type, usually function.
tools.functionobjectFunction definition.
tool_choiceobjectTool selection policy.
tool_choice.typestringTool choice type, such as function.
tool_choice.functionobjectFunction selection payload.
parallel_tool_callsbooleanParallel tool-call flag.
previous_response_idstringPrevious response ID.
conversationobjectConversation state object or ID.
prompt_cache_keystringPrompt cache key.
storebooleanResponse storage flag.
truncationstringInput truncation strategy.
includearrayAdditional response fields to include.
metadataobjectApplication metadata.
extra_bodyobjectAdditional request body fields.
provider_optionsobjectUpstream configuration.
schema_paramsobjectStructured output schema parameters.
network_searchbooleanNetwork search flag.
reasoningobjectCanonical reasoning/thinking control configuration.
reasoning.enabledbooleanEnable reasoning when the selected model supports it.
reasoning.effortstringReasoning effort. Supports xhigh, high, medium, low, minimal, and none.
reasoning.max_tokensintegerMaximum reasoning tokens. Used for execution when supplied with effort.
reasoning.excludebooleanReason internally without returning reasoning text.
response_formatobjectRequested response format for structured model output.
logprobsbooleanWhether to return log probabilities for generated output tokens.
top_logprobsintegerNumber of most likely tokens to return at each generated token position; requires logprobs=true.
stoparrayStop sequences that terminate generation; the verified contract uses an array of up to four strings.
verbositystringControls the level of detail in the model response.
seedintegerBest-effort sampling seed for reproducible outputs.
nintegerNumber of response choices to generate.
logit_biasobjectAdjusts the likelihood of specified token IDs.
Response format
response_format controls the assistant output format:
{"type":"text"}returns regular text.{"type":"json_object"}returns a valid JSON object.{"type":"json_schema","json_schema":{...}}returns JSON that follows the supplied schema. Thejson_schemaobject containsname, optionalstrict, andschemafields.
When a structured response is refused, choices[].message.refusal contains the refusal and choices[].message.content may be null.
Response
idstringUnique completion ID.
objectstringAlways chat.completion for non-streaming responses.
createdintegerUnix timestamp.
modelstringModel used for the request.
choicesobject[]Generated choices.
choices.indexintegerChoice index.
choices.messageobjectAssistant message.
choices.logprobsobject | nullLog probabilities for generated tokens. Null when log probabilities were not requested.
choices.finish_reasonstringstop, length, or tool_calls.
usageobjectToken usage and cost details.
usage.prompt_tokensintegerInput token count when returned.
usage.completion_tokensintegerOutput token count when returned.
usage.total_tokensintegerTotal token count when returned.
usage.input_tokensintegerInput token count for providers that use input/output names.
usage.output_tokensintegerOutput token count for providers that use input/output names.
usage.generated_imagesintegerGenerated image count when returned.
usage.audio_duration_secondsnumberAudio duration used for billing when returned.
usage.video_duration_secondsnumberVideo duration used for billing when returned.
usage.provider_request_idstringProvider request ID used for upstream correlation.