Model APIs
Chat Completions
Use the OpenAI-compatible chat endpoint for messages, conversation context, output controls and streaming.
Updated
/v1/chat/completionsRequest structure
POST /v1/chat/completions represents a conversation as messages. Send the history required for each request; previous calls do not automatically become context. Use system instructions for stable constraints and user messages for the current task.
| Parameter | Type / requirement | Meaning |
|---|---|---|
| model | string · required | Model id from the catalog |
| messages | array · required | Nonempty messages with role and content |
| stream | boolean · optional | Defaults to false; true requests SSE |
| temperature | number · model-dependent | Sampling parameter; some reasoning models reject it |
| max_tokens / max_completion_tokens | integer · model-dependent | Set the output budget supported by the target model |
curl --fail-with-body https://api.token4ai.cloud/v1/chat/completions \
-H "Authorization: Bearer $TOKEN4AI_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_MODEL_ID",
"messages": [
{
"role": "system",
"content": "Answer concisely."
},
{
"role": "user",
"content": "Explain an API gateway."
}
],
"stream": false
}'Read the response
Ordinary text is usually in choices[0].message.content. Tool requests are in message.tool_calls and content may be null. Inspect finish_reason to distinguish completion, truncation and tool invocation; HTTP 200 alone is not enough.
usage describes model-reported token consumption. Cache, reasoning and other optional usage fields differ by provider. Tolerate absent optional fields and reconcile charges against Usage History.
Context and compatibility
- Bound message history to avoid resending irrelevant context.
- Existing OpenAI-compatible clients usually need a new base_url and key, but model parameters still require validation.
- Test structured output, multimodal input and tools separately rather than inferring support from a successful text call.