Skip to main content
DocumentationDevelopers

Chat completions

Generate text with OpenAI's Chat Completions API: one answer, a stream of tokens, or calls to your own tools.

Documentation menu

Send a conversation

curl "$CCSIO_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $CCSIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.8-flash-next",
    "messages": [{"role": "user", "content": "Say hello in one sentence."}]
  }'

The API keeps no conversation between calls: send the whole history in messages every time, oldest first, with the roles system, user, assistant and tool.

Parameters

ParameterNotes
model, messagesRequired.
streamtrue streams the answer as server-sent events; false or absent answers one JSON object.
temperature, top_p, seedSampling, passed to the model.
max_tokens, max_completion_tokens, stopWhere the answer ends, passed to the model.
n, presence_penalty, frequency_penaltyPassed to the model.
response_formatJSON output, when the model supports it.
tools, tool_choiceFunction calling, see below.
userYour own end-user label, passed to the model.

A parameter the model does not support is refused by the model, and you receive its refusal as a 400.

Streaming

With "stream": true the answer is a text/event-stream. Each data: line carries one chat.completion.chunk; the stream ends with data: [DONE]. The platform always asks the model for the token counts, so the last chunk before [DONE] has empty choices and a usage object.

curl -N "$CCSIO_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $CCSIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.8-flash-next",
    "stream": true,
    "messages": [{"role": "user", "content": "Write a haiku about the sea."}]
  }'
SSE
data: {"id":"chatcmpl-9b1c4e7f2a6d","object":"chat.completion.chunk","created":1792406148,"model":"qwen3.8-flash-next","choices":[{"index":0,"delta":{"role":"assistant","content":"Waves"},"finish_reason":null}]}

data: {"id":"chatcmpl-9b1c4e7f2a6d","object":"chat.completion.chunk","created":1792406148,"model":"qwen3.8-flash-next","choices":[{"index":0,"delta":{"content":" fold into foam"},"finish_reason":null}]}

data: {"id":"chatcmpl-9b1c4e7f2a6d","object":"chat.completion.chunk","created":1792406148,"model":"qwen3.8-flash-next","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: {"id":"chatcmpl-9b1c4e7f2a6d","object":"chat.completion.chunk","created":1792406148,"model":"qwen3.8-flash-next","choices":[],"usage":{"prompt_tokens":16,"completion_tokens":17,"total_tokens":33}}

data: [DONE]
What arrives on the wire.

Tools (function calling)

Describe your functions in tools. When the model decides to call one, the answer carries the calls in choices[0].message.tool_calls; run them and send the results back as tool messages.

import os
from openai import OpenAI

client = OpenAI(
    base_url=os.environ["CCSIO_BASE_URL"],
    api_key=os.environ["CCSIO_API_KEY"],
)

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "The current weather of a city.",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

completion = client.chat.completions.create(
    model="qwen3.8-flash-next",
    messages=[{"role": "user", "content": "What is the weather in Bogotá?"}],
    tools=tools,
)
for call in completion.choices[0].message.tool_calls or []:
    print(call.function.name, call.function.arguments)  # get_weather {"city": "Bogotá"}

Grouping requests

Send X-Session-Id with a label of your own (a conversation, a job, a ticket) to find all its requests together in the request log.

Explore the platform

Get your first API key

Registration is open. Four steps to your first call: create your account, create your organization, create your API key, and start using it.

  1. 01Create your account
  2. 02Create your organization
  3. 03Create your API key
  4. 04Start using it