Skip to content

Create Chat Completion (Non-Streaming)

POST: https://www.kkiai.com/v1/chat/completions

Given a list of messages, the model returns a complete non-streaming chat completion response.

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 to the request header. The value should be your API key prefixed with Bearer.

Example: Authorization: Bearer YOUR_API_KEY

Header Parameters

Parameter NameTypeRequiredDescriptionExample
Content-TypestringRequiredRequest content type.application/json
AcceptstringOptionalResponse content type.application/json
AuthorizationstringRequiredAPI key used for authentication.Bearer YOUR_API_KEY

Body Parameters (application/json)

Parameter NameTypeRequiredDescription
modelstringRequiredThe ID of the model to use. For details on which models are available, see the model list or pricing table.
messagesarray[object]RequiredA list of messages that make up the conversation so far.
  └ rolestringRequiredThe role of the message author, such as system, user, or assistant.
  └ contentstringRequiredThe text content of the message.
temperaturenumberOptionalWhat sampling temperature to use, between 0 and 2. Higher values make the output more random, while lower values make it more focused and deterministic. We generally recommend changing either this or top_p, but not both.
top_pnumberOptionalAn alternative to sampling with temperature, called nucleus sampling. We generally recommend changing either this or temperature, but not both.
nintegerOptionalHow many chat completion choices to generate for each input message.
streambooleanOptionalDefaults to false. For non-streaming requests, omit this parameter or set it to false.
stopstring or arrayOptionalUp to 4 sequences where the API will stop generating further tokens.
max_tokensintegerOptionalThe maximum number of tokens to generate in the chat completion.
presence_penaltynumberOptionalPenalizes new tokens based on whether they already appear in the text so far.
frequency_penaltynumberOptionalPenalizes new tokens based on their existing frequency in the text so far.
logit_biasobject or nullOptionalModifies the likelihood of specified tokens appearing in the completion.
userstringOptionalA unique identifier representing your end user, which can help monitor and detect abuse.
response_formatobjectOptionalSpecifies the format that the model should output.
seedintegerOptionalIf specified, the system will make a best effort to sample deterministically.
toolsarray[object]OptionalA list of tools the model may call. Currently, only function tools are supported.
tool_choicestring or objectOptionalControls which tool, if any, the model should call. Common values include none and auto.

Request Example

json
{
  "model": "claude-sonnet-4-20250514",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Hello"
    }
  ]
}

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"
    }
  ]
}'

Response

🟢 200 OK

Response Body

Parameter NameTypeRequiredDescription
idstringRequiredUnique identifier for the chat completion.
objectstringRequiredObject type. Always chat.completion.
createdintegerRequiredUnix timestamp, in seconds, of when the chat completion was created.
modelstringRequiredThe model used to generate the completion.
choicesarray[object]RequiredA list of chat completion choices.
  └ indexintegerOptionalThe index of the generated choice.
  └ messageobjectOptionalThe message generated by the model.
  └ finish_reasonstringOptionalThe reason the model stopped generating tokens.
usageobjectRequiredToken usage statistics for the request.
  └ prompt_tokensintegerRequiredNumber of tokens in the prompt.
  └ completion_tokensintegerRequiredNumber of tokens in the generated completion.
  └ total_tokensintegerRequiredTotal number of tokens used in the request.

Response Example

json
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "claude-sonnet-4-20250514",
  "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
  }
}