Chat Completions
Chat Communications is the most commonly used dialogue entry in the text series, suitable for chat client, assistant, workflow node and text generation scenes that require streaming output.
API Path
| Methodology | Path | Returns by |
|---|---|---|
POST | /v1/chat/completions | synchronous JSON or SSE streaming returned. |
Example request
bash
curl https://moonnexai.com/v1/chat/completions \
-H "Authorization: Bearer <MOONNEXAI_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-terra",
"messages": [
{
"role": "system",
"content": "你是一个简洁的开发者助手。"
},
{
"role": "user",
"content": "写一句 API 接入成功后的欢迎语。"
}
]
}'Common field
| field | Annotations |
|---|---|
model | Model name. First, you can confirm the available model by Model Query. |
messages | Multi-cycle dialogue news array. |
temperature | Controls the randomity of the output. |
max_tokens | Limit the length of generation. |
stream | Use SSE streaming to return when setting true. |
Message Structure
| role | Purpose |
|---|---|
system | Set roles, tone and boundaries. |
user | User input. |
assistant | Historic assistant responded. |
response Processing
| scene | Treatment |
|---|---|
| Normal Return | Reads the generated text in response and saves the request model and track information. |
| streaming returns | Adds to the SSE event by paragraph, closes the connection after the event has arrived. |
| request failed | Checks the model name, API Key permission, request body format and context length. |
Access Recommendations
- Chat client gives priority to this API, Base URL set to
https://moonnexai.com/v1. - Please pass only the necessary context to avoid the inclusion of irrelevant history in request.
- Set
stream: truewhen you want to generate side displays and process incremental content by SSE events.