chat/completions is the most common LLM API interface, which takes a list of messages forming a conversation as input and returns intelligent model responses.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 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, the response will be returned in chunks as 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.1",
"messages": [
{
"role": "developer",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}'{
"id": "chatcmpl-CbnYmQAVmFC6IzQTs9X0bFc3J1S7q",
"object": "chat.completion",
"created": 1763124680,
"model": "gpt-5.1-2025-11-13",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?",
"refusal": null,
"annotations": []
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 18,
"total_tokens": 36,
"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
}
},
"service_tier": "default",
"system_fingerprint": null
}