---
title: "POST /api/internal/chat/completions"
method: POST
path: "/api/internal/chat/completions"
tags: ["Chat"]
---

# POST /api/internal/chat/completions

`POST /api/internal/chat/completions`

Create a chat completion (OpenAI compatible).

## Request body

- object
  - `messages` object[], required — An array of messages comprising the conversation so far. Must contain at least one message. System messages are only allowed as the first message.
    - `role` 'system' | 'user' | 'assistant' | 'tool', required — The role of the message sender. "system" is for system-level instructions, "user" represents the end user, and "assistant" represents the AI model's responses.
    - `content` string, nullable — The actual text content of the message. Note that this can be null in certain cases, such as when the message contains tool calls or when specific roles don't require content.
    - `name` string — The name of the function to call, if any.
    - `tool_calls` object[] — Tool calls to be made by the assistant
      - `id` string, required — A unique identifier for this tool call
      - `type` 'function', required — The type of tool call
      - `function` object, required
        - `name` string, required — The name of the function to call
        - `arguments` string, required — The arguments to pass to the function as a JSON string
    - `tool_call_id` string — The ID of the tool call that this message is a response to (only for tool role messages)
  - `model` string, required — The identifier of the model to use for generating completions. This can be a model ID or an alias.
  - `frequency_penalty` number — A value between -2.0 and 2.0 that penalizes new tokens based on their frequency in the text so far. Higher values decrease the likelihood of the model repeating the same tokens.
  - `max_completion_tokens` integer, nullable — The maximum number of tokens to generate in the completion. If null, will use the model's maximum context length. This is the maximum number of tokens that will be generated.
  - `presence_penalty` number — A value between -2.0 and 2.0 that penalizes new tokens based on whether they appear in the text so far. Higher values increase the likelihood of the model talking about new topics.
  - `seed` integer — A seed value for deterministic sampling. Using the same seed with the same parameters will generate the same completion.
  - `stop` union — One or more sequences where the API will stop generating further tokens. Can be a single string or an array of strings.
    - string
    - string[]
  - `stream` boolean — If true, partial message deltas will be sent as server-sent events. Useful for showing progressive generation in real-time.
  - `temperature` number, nullable — Controls randomness in the model's output. Values between 0 and 2. Lower values make the output more focused and deterministic, higher values make it more random and creative.
  - `top_p` number, nullable — An alternative to temperature for controlling randomness. Controls the cumulative probability of tokens to consider. Lower values make output more focused.
  - `response_format` object — Specifies the format of the model's output. Use "json_schema" to constrain responses to valid JSON matching the provided schema.
    - `type` 'text' | 'json_schema', required
    - `json_schema` object, required
  - `tools` unknown[] — A list of tools the model may call. Each tool has a specific function the model can use to achieve specific tasks.
    - unknown
  - `tool_choice` union — Controls how the model uses tools. "none" disables tools, "auto" lets the model decide, or specify a particular tool configuration.
    - 'none'
    - 'auto'
    - object

## Response `200`

chat completion response

- object
  - `id` string, required — A unique identifier for this chat completion response. Can be used for tracking or debugging.
  - `choices` object[], required — An array of completion choices. Each choice represents a possible completion for the input prompt, though currently only one choice is typically returned.
    - `finish_reason` 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call', required
    - `index` integer, required
    - `message` object, required
      - `content` string, nullable, required
      - `role` 'assistant' | 'tool', required
      - `name` string
      - `tool_calls` object[]
        - `id` string, required
        - `type` 'function', required
        - `function` object, required
          - `name` string, required
          - `arguments` string, required
      - `tool_call_id` string
  - `created` integer, required — The Unix timestamp (in seconds) indicating when this completion was generated by the API.
  - `model` string, required — The specific model used to generate this completion. This will be the model's full identifier string.
  - `system_fingerprint` string, nullable — A unique identifier for the system state that generated this response. Useful for tracking model behavior across requests.
  - `object` 'chat.completion', required — The type of object returned, always "chat.completion" for chat completion responses.
  - `usage` object — Statistics about token usage for this request and response. May be omitted in error cases or when not available.
    - `completion_tokens` integer, required — The number of tokens generated in the completion response. This counts only the tokens in the assistant's reply.
    - `prompt_tokens` integer, required — The number of tokens in the prompt/input. This includes all messages sent to the API in the conversation history.
    - `total_tokens` integer, required

---

[API](https://skmtc.net/premai-io/apis/prem-studio-api.md) · [All operations](https://skmtc.net/premai-io/apis/prem-studio-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/premai-io/prem-studio-api/revisions/2cb1f5df1b89/schema)
