Search...
Menu

Chat Completions

Generate replies from a messages array, using either a regular JSON response or an SSE stream.

Request

Item Description
Method POST
Path /v1/chat/completions
Gateway URL https://ailink.nativex.com
Authentication Authorization: Bearer sk-xxxx; replace the placeholder with your API Key
Request format application/json

Replace MODEL_ID with a model from the Model Marketplace that supports this endpoint. Available models, parameters, and permissions depend on your account.

Parameters

Parameter Location Type Required Description
model Body string Yes A model that supports chat
messages Body object[] Yes Message array. Common roles are system, user, and assistant.
stream Body boolean No true enables SSE. Default: false.
temperature Body number No The traditional OpenAI range is 0–2. Some reasoning models do not support customization.
top_p Body number No Nucleus sampling parameter; traditional range: 0–1
max_completion_tokens Body integer No Output token limit; a positive integer supported by the model
max_tokens Body integer No Legacy output limit. Do not set it together with max_completion_tokens.
tools Body object[] No Tool definitions; requires model support
tool_choice Body string / object No Tool selection policy
response_format Body object No Output structure, such as JSON; requires model support
For multi-turn conversations, include the message history in order. Parameter ranges are model-specific; protocol compatibility does not imply support for every parameter.

Example

curl -X POST 'https://ailink.nativex.com/v1/chat/completions' \
  -H 'Authorization: Bearer sk-xxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL_ID",
  "messages": [
    {
      "role": "user",
      "content": "Introduce yourself in one sentence."
    }
  ],
  "stream": false
}'

Response

The following is a simplified response for readability. IDs, URLs, text, and usage values are illustrative.

{
  "id": "chatcmpl_example",
  "object": "chat.completion",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you?"
      },
      "finish_reason": "stop"
    }
  ]
}
Field or result Description
choices[].message Complete reply and any tool calls
choices[].finish_reason Reason generation stopped
usage Usage information returned by the model

Error handling

For unsuccessful responses, check the HTTP status and error body first. Verify the API Key, model name, account balance, and parameters. If rate limited, reduce concurrency and retry later.

Streaming

Set stream to true and add -N to curl. Read choices[].delta from each data: event instead of parsing the entire stream as one JSON object. A common end marker is data: [DONE].

Last modified: 2026-11-17