Docs

Model APIs

Chat Completions

Use the OpenAI-compatible chat endpoint for messages, conversation context, output controls and streaming.

Updated

POST/v1/chat/completions

Request 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.

ParameterType / requirementMeaning
modelstring · requiredModel id from the catalog
messagesarray · requiredNonempty messages with role and content
streamboolean · optionalDefaults to false; true requests SSE
temperaturenumber · model-dependentSampling parameter; some reasoning models reject it
max_tokens / max_completion_tokensinteger · model-dependentSet the output budget supported by the target model
cURL
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.

Related guides