Theme
Create Chat Completion (Streaming)
POST: https://www.kkiai.com/v1/chat/completions
Given a list of messages, the model returns one or more predicted completions, and streams the response incrementally.
Create a completion for the provided messages and parameters.
Official documentation: https://docs.anthropic.com/en/docs/build-with-claude/streaming#basic-streaming-request
Request Parameters
Authorization
Add the Authorization parameter to the Header, with its value being the Token concatenated after Bearer.
Example: Authorization: Bearer YOUR_API_KEY
Header Parameters
| Parameter Name | Type | Required | Description | Example |
|---|---|---|---|---|
Content-Type | string | Required | Request content type. | application/json |
Accept | string | Required | Response content type. | application/json |
Authorization | string | Required | API key used for authentication. | Bearer YOUR_API_KEY |
Body Parameters (application/json)
| Parameter Name | Type | Required | Description |
|---|---|---|---|
model | string | Required | The ID of the model to use. For details on which models are compatible with the Chat API, see the model endpoint compatibility table. |
messages | array[object] | Required | A list of messages comprising the conversation so far. |
└ role | string | Required | The role of the message author, such as system, user, or assistant. |
└ content | string | Required | The text content of the message. |
temperature | number | Optional | What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p, but not both. |
top_p | number | Optional | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. We generally recommend altering this or temperature, but not both. |
n | integer | Optional | Defaults to 1. How many chat completion choices to generate for each input message. |
stream | boolean | Required | Set this to true to receive partial message deltas as data-only server-sent events. The stream is terminated by a data: [DONE] message. |
stop | string or array | Optional | Defaults to null. Up to 4 sequences where the API will stop generating further tokens. |
max_tokens | integer | Optional | Defaults to inf. The maximum number of tokens to generate in the chat completion. |
presence_penalty | number | Optional | Defaults to 0. A number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far. |
frequency_penalty | number | Optional | Defaults to 0. A number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far. |
logit_bias | object or null | Optional | Modifies the likelihood of specified tokens appearing in the completion. |
user | string | Optional | A unique identifier representing your end user, which can help monitor and detect abuse. |
response_format | object | Optional | An object specifying the format that the model must output. |
seed | integer | Optional | If specified, the system will make a best effort to sample deterministically. |
tools | array[object] | Optional | A list of tools the model may call. Currently, only functions are supported as a tool. |
tool_choice | string or object | Optional | Controls which function, if any, the model calls. |
Request Example
json
{
"model": "claude-sonnet-4-20250514",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello"
}
],
"stream": true
}cURL Example
bash
curl --location --request POST 'https://www.kkiai.com/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "claude-sonnet-4-20250514",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello"
}
],
"stream": true
}'Response
🟢 200 OK
Response Body
| Parameter Name | Type | Required | Description |
|---|---|---|---|
id | string | Required | Unique identifier for the chat completion. Chunks from the same streaming response share the same ID. |
object | string | Required | Object type. Always chat.completion.chunk. |
created | integer | Required | Unix timestamp, in seconds, of when the chat completion was created. |
model | string | Required | The model used to generate the completion. |
system_fingerprint | string | Optional | Fingerprint of the backend configuration that processed the request. |
choices | array[object] | Required | A list of chat completion choices. |
└ index | integer | Optional | The index of the generated choice. |
└ delta | object | Optional | The incremental message content returned in the current chunk. |
└ finish_reason | string or null | Optional | The reason generation stopped. Usually null for intermediate chunks and stop in the final chunk. |
Response Example
text
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"claude-sonnet-4-20250514","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"claude-sonnet-4-20250514","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"claude-sonnet-4-20250514","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
...
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"claude-sonnet-4-20250514","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{"content":" today"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"claude-sonnet-4-20250514","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{"content":"?"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"claude-sonnet-4-20250514","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}