Chat Completions API
The OpenAI-compatible request and response contract for POST /v1/chat/completions.
The body requires a model and at least one message. Valid roles are system, user, assistant, and tool; content must be a non-empty string or a non-empty content-parts array.
When present, temperature must be between 0 and 2 and max_tokens must be positive. stream=false returns complete JSON; stream=true returns SSE data events ending with [DONE].
Key points
- Headers: Bearer Authorization and Content-Type application/json.
- model: a public model ID returned by GET /v1/models.
- messages: an ordered array of conversation messages.
- Successful responses preserve OpenAI-compatible choices, model, and usage fields.
- For SSE, append choices[].delta.content in order and treat the response as complete only after data: [DONE].
- If a terminal error arrives after any delta, preserve partial output and do not retry automatically to avoid duplicate content.
- The x-routing-request-id response header identifies the internal request trace.
Example request
curl --no-buffer --request POST 'https://api.xpncore.com/v1/chat/completions' \
--max-time 35 \
--header "Accept: text/event-stream" \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "MODEL_ID_FROM_GET_V1_MODELS",
"messages": [
{
"role": "user",
"content": "Hello from the gateway"
}
],
"temperature": 0.7,
"max_tokens": 512,
"stream": true
}'