---
title: "Generates text responses based on incoming messages."
method: POST
path: "/v1/directllm/chat/completions"
---

# Generates text responses based on incoming messages.

`POST /v1/directllm/chat/completions`

This endpoint generates relevant text responses based on the content of incoming messages.

## Request body

- CompletionParameters
  - `model` string — Alias of the LLM to be used in the chat session.
  - `messages` CompletionMessage[], required — List of messages representing the chat history.
    - `role` 'system' | 'user' | 'assistant', required
    - `content` union, required — The content of the message.
      - object[]
      - string
    - `name` string, nullable — An optional name for the message.
  - `temperature` number, nullable — 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.
  - `max_completion_tokens` integer, nullable — The maximum number of tokens that can be generated in the completion.
  - `top_p` number, nullable — An 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.
  - `frequency_penalty` number, nullable — 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.
  - `presence_penalty` number, nullable — 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.
  - `stop` union — This field is not handled in the code.
    - string
    - string[]
  - `stream` boolean — Response generation in stream mode.
  - `tools` string[], nullable — This field is not handled in the code.
  - `tool_choice` string, nullable — This field is not handled in the code.
  - `n` integer, nullable — This field is not handled in the code.
  - `response_format` StructuredOutputJsonSchemaBase — Base keys which must be assigned
    - `type` 'text' | 'json_schema'
    - `json_schema` object, nullable, required
  - `search_domain_filter` string[], nullable — List of domain names to filter the search results. If not provided, all domains will be searched. Perplexity only
  - `search_mode` string, nullable — The search mode to use. Possible value is 'academic'. Perplexity only
  - `disable_search` boolean, nullable — Flag to disable search functionality. Perplexity only
  - `media_response` object, nullable — Media response configuration. Perplexity only

## Response `200`

Successful Response

- union
  - CompletionResponseSchemaOutput
    - `id` string, required — Unique identifier for the message.
    - `object` string — Type of the current schema. Only 'chat.completion' is allowed.
    - `created` integer — Timestamp of when the message was created, in UTC.
    - `model` string, required — Alias of the LLM used in the chat session.
    - `choices` CompletionResponseChoiceOutput[] — List of messages in the response.
      - `index` integer, required — Index of the response chunk.
      - `message` CompletionChoiceMessageOutput, required
        - `role` string — The role of the message sender, typically 'assistant'.
        - `content` string, required — The content of the message.
        - `tool_calls` unknown
        - `additional_kwargs` CompletionKwargs, required
          - `citations` union[], required
            - union
              - …
      - `finish_reason` 'stop' | 'length' | 'tool_calls' | 'invalid_json_schema'
    - `usage` CompletionUsageSchema, required
      - `prompt_tokens` integer, required — The number of tokens used in the prompt.
      - `completion_tokens` integer, required — The number of tokens used in the response.
      - `total_tokens` integer, required — The total number of tokens used (prompt + response).
    - `citations` string[] — List of citations related to the streaming message.
    - `search_results` SearchResult[] — List of search results related to the streaming message.
      - `title` string, required — Title of the search result
      - `url` string, required — URL of the search result
      - `date` string, nullable — Date of the search result
      - `last_updated` string, nullable — Last updated date of the search result
      - `snippet` string — Snippet of the search result
      - `source` string, nullable — Source of the search result
    - `images` ImageResult[] — List of images related to the streaming message.
      - `image_url` string, required — Image URL
      - `origin_url` string, nullable — Origin URL of the image
      - `height` integer, nullable — Height of the image
      - `width` integer, nullable — Width of the image
      - `title` string, nullable — Title of the image
    - `videos` VideoResult[] — List of videos related to the streaming message.
      - `url` string, required — Video URL
      - `thumbnail_width` integer, nullable — Thumbnail width of the video
      - `thumbnail_height` integer, nullable — Thumbnail height of the video
      - `thumbnail_url` string, nullable — Thumbnail URL of the video
  - CompletionStreamingEventOutput
    - `id` string, required — Unique identifier for the message.
    - `object` string — Type of the current schema. Only 'chat.completion.chunk' is allowed.
    - `model` string, required — Alias of the LLM used in the chat session.
    - `created` integer — Timestamp of when the message was created, in UTC.
    - `choices` CompletionStreamingChoiceOutput[] — List of events related to the streaming message.
      - `index` integer, required — Index of the response chunk.
      - `delta` CompletionChoiceContentOutput, required
        - `content` string, required — The content of the current chunk.
        - `role` string — The role of the message sender, typically 'assistant'.
        - `additional_kwargs` CompletionKwargs, required
          - `citations` union[], required
            - union
              - …
      - `finish_reason` 'stop' | 'length' | 'tool_calls' | 'invalid_json_schema'
    - `citations` string[] — List of citations related to the streaming message.
    - `search_results` SearchResult[] — List of search results related to the streaming message.
      - `title` string, required — Title of the search result
      - `url` string, required — URL of the search result
      - `date` string, nullable — Date of the search result
      - `last_updated` string, nullable — Last updated date of the search result
      - `snippet` string — Snippet of the search result
      - `source` string, nullable — Source of the search result
    - `images` ImageResult[] — List of images related to the streaming message.
      - `image_url` string, required — Image URL
      - `origin_url` string, nullable — Origin URL of the image
      - `height` integer, nullable — Height of the image
      - `width` integer, nullable — Width of the image
      - `title` string, nullable — Title of the image
    - `videos` VideoResult[] — List of videos related to the streaming message.
      - `url` string, required — Video URL
      - `thumbnail_width` integer, nullable — Thumbnail width of the video
      - `thumbnail_height` integer, nullable — Thumbnail height of the video
      - `thumbnail_url` string, nullable — Thumbnail URL of the video
  - CompletionErrorSchemaOutput
    - `error` CompletionErrorDetailSchema, required
      - `code` string, nullable, required — The error code indicating the type of error.
      - `message` string, required — A detailed message describing the error.
      - `type` 'invalid_request_error' | 'authentication_error' | 'rate_limit_error', required

## Other responses

- `401` — User token is not present in cookies or has incorrect value.
- `421` — Various errors, see examples
- `422` — Validation Error

---

[API](https://skmtc.dev/constructor-tech/apis/constructorknowledgemodel.md) · [All operations](https://skmtc.dev/constructor-tech/apis/constructorknowledgemodel/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/constructor-tech/constructorknowledgemodel/revisions/989f1fae00de/schema)
