Skip to content

Create Chat Completion (Streaming)

POST: https://www.kkiai.com/v1/messages

Given a prompt,, the model will return one or more predicted completions, and can also return the probability of alternative tokens at each position.

Create a completion for the provided messages and parameters.

Official documentation: https://docs.anthropic.com/en/api/messages

Request Parameters

Authorization

Add the Authorization parameter in the Header. The value should be your API key prefixed with Bearer.

Example: Authorization: Bearer YOUR_API_KEY

Header Parameters

ParameterTypeRequiredDescriptionExample
Content-TypestringRequiredapplication/json
AcceptstringRequiredapplication/json
AuthorizationstringRequiredAPI key used for authentication.Bearer YOUR_API_KEY

Body Parameters (application/json)

ParameterTypeRequiredDescription
modelstringRequiredThe ID of the model to use. For details on which models can be used with the Chat API, see the model endpoint compatibility table.
systemstringOptionalSystem prompt used to provide high-level instructions to the model.
messagesarray[object]RequiredA list of messages comprising the conversation so far.
  └ rolestringRequiredThe role of the message author, such as user or assistant.
  └ contentstringRequiredThe text content of the message.
temperaturenumberOptionalWhat 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_pnumberOptionalAn alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature, but not both.
nintegerOptionalDefaults to 1. How many chat completion choices to generate for each input message.
streambooleanOptionalDefaults to false. Set this to true to receive a streaming response.
stopstringOptionalDefaults to null. Up to 4 sequences where the API will stop generating further tokens.
max_tokensintegerOptionalDefaults to inf. The maximum number of tokens to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length.
presence_penaltynumberOptionalDefaults 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, increasing the model's likelihood to talk about new topics. See more information about frequency and presence penalties.
frequency_penaltynumberOptionalDefaults 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, decreasing the model's likelihood to repeat the same line verbatim. See more information about frequency and presence penalties.
logit_biasobject or nullOptionalModify the likelihood of specified tokens appearing in the completion.
userstringOptionalA unique identifier representing your end-user, which can help monitor and detect abuse. Learn more.
response_formatobjectOptionalAn object specifying the format that the model must output.
seedintegerOptionalThis feature is in beta. If specified, our system will make a best effort to sample deterministically.
toolsarray[object]OptionalA list of tools the model may call. Currently, only functions are supported as a tool.
tool_choicestring or objectOptionalControls which function, if any, the model calls.

Request Example

json
{
  "model": "claude-sonnet-4-20250514",
  "system": "You are a helpful AI assistant named Alex.",
  "messages": [
    {
      "role": "user",
      "content": "Who are you?"
    }
  ],
  "stream": true
}

cURL Example

bash
curl --location --request POST 'https://www.kkiai.com/v1/messages' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "model": "claude-sonnet-4-20250514",
  "system": "You are a helpful AI assistant named Alex.",
  "messages": [
    {
      "role": "user",
      "content": "Who are you?"
    }
  ],
  "stream": true
}'

Response

🟢 200 OK

Response Body

ParameterTypeRequiredDescription
idstringRequired
objectstringRequired
createdintegerRequired
choicesarray[object]Required
  └ indexintegerOptional
  └ messageobjectOptional
  └ finish_reasonstringOptional
usageobjectRequired
  └ prompt_tokensintegerRequired
  └ completion_tokensintegerRequired
  └ total_tokensintegerRequired

Response Example

json
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "\n\nHello there, how may I assist you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21
  }
}