chat/completions is the most common API interface for LLMs, taking a conversation list composed of multiple messages as input to get responses from the LLM model.chat/completions interface, please refer to the OpenAI Official Documentation.model string required{
"model": "gpt-4"
}messages array requiredrole string - The role of the message, possible values:system - System message, used to set assistant behavioruser - User messageassistant - Assistant's historical repliescontent string - The specific content of the message{
"messages": [
{
"role": "system",
"content": "You are a professional AI assistant"
},
{
"role": "user",
"content": "What is machine learning?"
}
]
}stream boolean optionaltrue, responses will be returned incrementally in the form of Server-Sent Events (SSE).false{
"stream": true
}temperature number optionalmax_tokens integer optionaltop_p number optionaltemperature and top_p simultaneously.429 Too Many Requests, implement exponential backoff retry:messages array:| Value | Meaning |
|---|---|
stop | Natural completion |
length | Reached max_tokens limit |
content_filter | Triggered content filter |
function_call | Model called a function |
max_tokens to limit output lengthusage fieldcurl --location --request POST 'https://api.cometapi.com/v1/chat/completions' \
--header 'Authorization: Bearer {{api-key}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gpt-5-mini",
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"stream": false
}'{
"id": "chatcmpl-AreYSBEwmzB0kY3GxzBEhE1Olct83",
"object": "chat.completion",
"created": 1737350640,
"model": "gpt-4o-2024-08-06",
"system_fingerprint": "fp_f3927aa00d",
"choices": [
{
"index": 0,
"message": {
"content": "Hello! How can I assist you today?",
"role": "assistant"
},
"finish_reason": "stop"
}
],
"usage": {
"completion_tokens": 9,
"completion_tokens_details": {},
"prompt_tokens": 9,
"prompt_tokens_details": {},
"total_tokens": 18
}
}