Chat completions

Request/response structure, streaming, and the equivalent endpoints in the Anthropic and Gemini protocols.

Chat completion is the most-used endpoint: send a list of messages to the model and get the generated reply back. The platform's primary entry is the OpenAI-compatible protocol; the Anthropic and Gemini protocols are isomorphic equivalents.

Request shape (OpenAI-compatible)

POST {base}/chat/completions — authentication in Authentication:

{
  "model": "your-model",
  "messages": [
    {"role": "system", "content": "You are a support assistant."},
    {"role": "user", "content": "Where is my order?"},
    {"role": "assistant", "content": "Sure, may I have the order number?"},
    {"role": "user", "content": "A1024"}
  ],
  "temperature": 0.7,
  "max_tokens": 1024,
  "stream": false
}
  • messages is the ordered conversation history; role is system / user / assistant. For multi-turn chats the client concatenates the full history and resends it each time;
  • Higher temperature means more varied output (commonly 0–1); max_tokens caps the reply length;
  • Streaming: with "stream": true the response is pushed incrementally over SSE (choices[0].delta) — ideal for showing text as it is generated. Official SDKs: pass stream=True and iterate.

Response shape

Key fields of a non-streaming response:

{
  "choices": [
    {
      "message": {"role": "assistant", "content": "..."},
      "finish_reason": "stop"
    }
  ],
  "usage": {"prompt_tokens": 58, "completion_tokens": 132, "total_tokens": 190}
}
  • choices[0].message.content holds the reply; finish_reason stop means it finished naturally, length means it was cut off by max_tokens;
  • usage is the token consumption of this call — billing and the "Usage" page are both based on it.

Equivalent endpoints in other protocols

  • Anthropic: POST {base}/v1/messages — field names differ (max_tokens is required, the reply lives in the content array), semantics otherwise identical;
  • Gemini: POST {base}/v1beta/models/{model}:generateContent — messages go in the contents array.

The three protocols are isomorphic; migration is mostly field renaming. The practical move is to use the corresponding official SDK (openai / @anthropic-ai/sdk / @google/genai) with base_url pointed at the platform.