Skip to content

Chat Completions ​

POST /v1/chat/completions is used to create chat completions and is the default interface for most clients and SDKs.

Request Parameters ​

FieldTypeRequiredDescription
modelstringYesPlatform model name
messagesarrayYesList of conversation messages
streambooleanNoWhether to use streaming responses
temperaturenumberNoSampling temperature; whether it takes effect depends on the model
top_pnumberNoNucleus sampling parameter
max_tokensnumberNoMaximum output tokens; some models use other fields
max_completion_tokensnumberNoMaximum completion tokens used by some reasoning models
toolsarrayNoTool or function definitions
tool_choicestring/objectNoTool selection strategy
response_formatobjectNoJSON or structured output requirements

Message Object ​

FieldDescription
rolesystem, user, assistant, tool, etc.
contentText or an array of multimodal content parts
nameOptional name
tool_callsTool calls initiated by the model
tool_call_idID of the call associated with the tool response message

Response ​

Non-streaming responses typically contain id, object, created, model, choices, and usage. Streaming responses return incremental delta values by event.

Request Example ​

bash
curl https://api.cloudaikit.com/v1/chat/completions \
  -H "Authorization: Bearer sk-your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [{"role": "user", "content": "你好"}],
    "temperature": 0.2
  }'

Text in non-streaming responses is typically located at choices[0].message.content. When using tool calls, execute the functions in choices[0].message.tool_calls, then send the results back as messages with role: tool.

Compatibility Differences ​

Tool calls, structured output, image input, audio input, reasoning parameters, and cache billing fields depend on the model and channel. If a field is ignored or causes an error, check the actual channel in the logs and consult the capabilities of the corresponding model.