Skip to content

Create Structured Output

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

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

Create a completion for the provided prompt and parameters

Official documentation: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses

Request Parameters

Authorization

Add the Authorization parameter to the Header, with the value being the Token concatenated after Bearer

Example: Authorization: Bearer ********************

Header Parameters

Parameter NameTypeRequiredDescriptionExample
Content-TypestringRequiredapplication/json
AcceptstringRequiredapplication/json
AuthorizationstringOptionalBearer {{YOUR_API_KEY}}

Body Parameters (application/json)

Parameter NameTypeRequiredDescription
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.
messagesarray[object]RequiredA list of messages comprising the conversation so far. Python code example.
  └ rolestringOptional
  └ contentstringOptional
temperatureintegerOptionalWhat 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_pintegerOptionalAn 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. If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Python code example.
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. Python code example for counting tokens.
presence_penaltynumberOptionalA 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_biasnullOptionalModify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value (-100 to 100). Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; and values like -100 or 100 should result in the ban or exclusive selection of the relevant token.
userstringOptionalA unique identifier representing your end-user, which can help OpenAI monitor and detect abuse. Learn more.
response_formatobjectOptionalAn object specifying the format that the model must output. Setting { "type": "json_object" } enables JSON mode, which guarantees the model will generate valid JSON. Important: when using JSON mode, you must also instruct the model to produce JSON via a system or user message. If you don't do this, the model may generate an endless stream of whitespace until the generation reaches the token limit, resulting in increased latency and a "stuck request" appearance. Also note that if finish_reason="length", the message content may be partially cut off, indicating generation exceeded max_tokens or the conversation exceeded the maximum context length. Show properties
seedintegerOptionalThis feature is in beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor backend changes.
toolsarray[string]RequiredA list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.
tool_choiceobjectRequiredControls which function (if any) the model calls. none means the model will not call a function and instead generates a message. auto means the model can choose between generating a message and calling a function. Specify the function the model must call by using {"type": "function", "function": {"name": "my_function"}}. If no functions are present, defaults to none. If functions are present, defaults to auto. Show possible types

Request Example

json
{
    "model": "gpt-4.1-2025-04-14",
    "messages": [
      {
        "role": "system",
        "content": "Determine if the user input violates specific guidelines and explain if they do."
      },
      {
        "role": "user",
        "content": "How do I prepare for a job interview?"
      }
    ],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "content_compliance",
        "description": "Determines if content is violating specific moderation rules",
        "schema": {
          "type": "object",
          "properties": {
            "is_violating": {
              "type": "boolean",
              "description": "Indicates if the content is violating guidelines"
            },
            "category": {
              "type": ["string", "null"],
              "description": "Type of violation, if the content is violating guidelines. Null otherwise.",
              "enum": ["violence", "sexual", "self_harm"]
            },
            "explanation_if_violating": {
              "type": ["string", "null"],
              "description": "Explanation of why the content is violating"
            }
          },
          "required": ["is_violating", "category", "explanation_if_violating"],
          "additionalProperties": false
        },
        "strict": true
      }
    }
  }

cURL Example

bash
curl --location --request POST 'https://www.kkiai.com/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-4.1-2025-04-14",
    "messages": [
      {
        "role": "system",
        "content": "Determine if the user input violates specific guidelines and explain if they do."
      },
      {
        "role": "user",
        "content": "How do I prepare for a job interview?"
      }
    ],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "content_compliance",
        "description": "Determines if content is violating specific moderation rules",
        "schema": {
          "type": "object",
          "properties": {
            "is_violating": {
              "type": "boolean",
              "description": "Indicates if the content is violating guidelines"
            },
            "category": {
              "type": ["string", "null"],
              "description": "Type of violation, if the content is violating guidelines. Null otherwise.",
              "enum": ["violence", "sexual", "self_harm"]
            },
            "explanation_if_violating": {
              "type": ["string", "null"],
              "description": "Explanation of why the content is violating"
            }
          },
          "required": ["is_violating", "category", "explanation_if_violating"],
          "additionalProperties": false
        },
        "strict": true
      }
    }
  }'

Response

🟢 200 OK

Response Body

Parameter NameTypeRequiredDescription
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
    }
}