Skip to main content
The Chat Completions API allows you to generate text responses based on a list of messages. This is the primary interface for building chatbots, virtual assistants, and text generation tools.

Endpoint

POST https://api.llm.kiwi/v1/chat/completions

Request Parameters

ParameterTypeRequiredDescription
modelstringYesThe model to use: pro, fast, or default.
messagesarrayYesA list of message objects representing the conversation.
streambooleanNoIf true, tokens will be sent as data-only server-sent events. Default: false.
temperaturenumberNoSampling temperature between 0 and 2. Default: 1.
max_tokensintegerNoThe maximum number of tokens to generate in the completion.
response_formatobjectNoSet to { "type": "json_object" } to enable JSON mode.

Message Format

Each message object consists of a role and content.
RoleDescription
systemSets the behavior or persona of the assistant.
userThe input message from the end user.
assistantPrevious responses from the model used for context.

Example Message Array

[
  {"role": "system", "content": "You are a helpful coding assistant."},
  {"role": "user", "content": "How do I reverse a string in Python?"}
]

Streaming Responses

For low-latency applications, enable streaming to receive tokens as they are generated.
Python
from openai import OpenAI

client = OpenAI(base_url="https://api.llm.kiwi/v1", api_key="YOUR_KEY")

stream = client.chat.completions.create(
    model="fast",
    messages=[{"role": "user", "content": "Tell me a story about a kiwi."}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Response Object

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "To reverse a string in Python, you can use slicing: `mystring[::-1]`."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 20,
    "total_tokens": 32
  }
}