LLM.kiwi LogoLLM.kiwi

Chat Completions

Generate text responses from our powerful language models.

Endpoint

POST/v1/chat/completions

Request Body

ParameterTypeRequiredDescription
modelstringYesModel to use: pro, fast, or default
messagesarrayYesArray of message objects with role and content
streambooleanNoEnable streaming responses. Default: false
temperaturenumberNoSampling temperature (0-2). Default: 1
max_tokensintegerNoMaximum tokens to generate
response_formatobjectNoSet to { "type": "json_object" } for JSON mode

Message Format

Each message in the array must have a role and content:

{
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "What is the capital of France?"
        },
        {
            "role": "assistant",
            "content": "The capital of France is Paris."
        },
        {
            "role": "user",
            "content": "What about Germany?"
        }
    ]
} 
system

Sets the behavior and context for the assistant

user

Messages from the user/human

assistant

Previous responses (for conversation context)

Code Examples

curl https://api.llm.kiwi/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "pro",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ]
  }'

Streaming

Set stream: true to receive responses as Server-Sent Events (SSE):

from openai import OpenAI

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

stream = client.chat.completions.create(
    model = "pro",
    messages = [{ "role": "user", "content": "Write a poem" }],
    stream = True
)

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

Response

{
    "id": "chatcmpl-abc123",
        "object": "chat.completion",
            "created": 1703456789,
                "model": "pro",
                    "choices": [
                        {
                            "index": 0,
                            "message": {
                                "role": "assistant",
                                "content": "The capital of France is Paris."
                            },
                            "finish_reason": "stop"
                        }
                    ],
                        "usage": {
        "prompt_tokens": 15,
            "completion_tokens": 8,
                "total_tokens": 23
    }
}