---
title: "Stream chat completions"
method: POST
path: "/dedicated/v1/chat/completions#stream"
tags: ["Dedicated.Chat"]
---

# Stream chat completions

`POST /dedicated/v1/chat/completions#stream`

## Request

- Base URL: `https://api.friendli.ai`
- URL: `https://api.friendli.ai/dedicated/v1/chat/completions#stream`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/friendli/apis/friendli-suite-api-reference/docs/dedicated/v1/chat/completions%23stream/post.ts> (a function with typed inputs; its response is checked against the schema)

Given a list of messages forming a conversation, the model generates a response.

## Headers

- `X-Friendli-Team` string, nullable: ID of team to run requests as (optional parameter).

## Request body

- DedicatedChatCompletionStreamBody
  - `model` string, required: ID of target endpoint. If you want to send request to specific adapter, use the format "YOUR_ENDPOINT_ID:YOUR_ADAPTER_ROUTE". Otherwise, you can just use "YOUR_ENDPOINT_ID" alone.
  - `messages` Message[], required: A list of messages comprising the conversation so far.
    - union
      - SystemMessage
        - `role` 'system', required: The role of the messages author.
        - `content` string, required: The content of system message.
        - `name` string, nullable: The name for the participant to distinguish between participants with the same role.
      - UserMessage
        - `role` 'user', required: The role of the message's author.
        - `content` union, required
          - string: The content of user message, which is plain text. For **multi-modal format**, use `object[]` type. Support for non-text input is currently in **Beta**.
          - UserMessageContentMultiModal[]: The content of user message. **Multi-modal format** can handle not just text, but also audio, image, and video content, allowing for more complex message structures. Support for non-text input is currently in **Beta**.
            - union
              - …
        - `name` string, nullable: The name for the participant to distinguish between participants with the same role.
      - AssistantMessage
        - `role` 'assistant', required: The role of the messages author.
        - `content` string, nullable: The content of assistant message. Required unless `tool_calls` is specified.
        - `reasoning_content` string, nullable: The intermediate reasoning content of assistant message.
        - `reasoning` string, nullable: The intermediate reasoning content of assistant message. This field is a compatible option for the 'reasoning_content' field.
        - `name` string, nullable: The name for the participant to distinguish between participants with the same role.
        - `tool_calls` AssistantMessageToolCall[], nullable
          - `id` string, required: The ID of tool call.
          - `type` 'function', required: The type of tool call.
          - `function` AssistantMessageToolCallFunction, required
            - `name` string, required: The name of function
            - `arguments` string, required: The arguments of function in JSON schema format to call the function.
      - ToolMessage
        - `role` 'tool', required: The role of the messages author.
        - `content` string, required: The content of tool message that contains the result of tool calling.
        - `tool_call_id` string, required: The ID of tool call corresponding to this message.
        - `name` string, nullable: An optional name of the tool call corresponding to this message.
  - `chat_template_kwargs` object, nullable: Additional keyword arguments supplied to the template renderer. These parameters will be available for use within the chat template.
  - `eos_token` integer[], nullable: A list of endpoint sentence tokens.
  - `frequency_penalty` number, nullable: Number between -2.0 and 2.0. Positive values penalizes tokens that have been sampled, taking into account their frequency in the preceding text. This penalization diminishes the model's tendency to reproduce identical lines verbatim.
  - `logit_bias` object, nullable: Accepts a JSON object that maps tokens to an associated bias value. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model.
  - `logprobs` boolean, nullable: Whether to return log probabilities of the output tokens or not.
  - `max_tokens` integer, nullable: The maximum number of tokens to generate. For decoder-only models like GPT, the length of your input tokens plus `max_tokens` should not exceed the model's maximum length (e.g., 2048 for OpenAI GPT-3). For encoder-decoder models like T5 or BlenderBot, `max_tokens` should not exceed the model's maximum output length. This is similar to Hugging Face's [`max_new_tokens`](https://huggingface.co/docs/transformers/v4.26.0/en/main_classes/text_generation#transformers.GenerationConfig.max_new_tokens) argument.
  - `min_p` number, nullable: A scaling factor used to determine the minimum token probability threshold. This threshold is calculated as `min_p` multiplied by the probability of the most likely token. Tokens with probabilities below this scaled threshold are excluded from sampling. Values range from 0.0 (inclusive) to 1.0 (inclusive). Higher values result in stricter filtering, while lower values allow for greater diversity. The default value of 0.0 disables filtering, allowing all tokens to be considered for sampling.
  - `n` integer, nullable: The number of independently generated results for the prompt. Defaults to 1. This is similar to Hugging Face's [`num_return_sequences`](https://huggingface.co/docs/transformers/v4.26.0/en/main_classes/text_generation#transformers.GenerationConfig.num_return_sequences) argument.
  - `parallel_tool_calls` boolean, nullable: Whether to enable parallel function calling.
  - `presence_penalty` number, nullable: Number between -2.0 and 2.0. Positive values penalizes tokens that have been sampled at least once in the existing text.
  - `repetition_penalty` number, nullable: Penalizes tokens that have already appeared in the generated result (plus the input tokens for decoder-only models). Should be positive value (1.0 means no penalty). See [keskar et al., 2019](https://arxiv.org/abs/1909.05858) for more details. This is similar to Hugging Face's [`repetition_penalty`](https://huggingface.co/docs/transformers/v4.26.0/en/main_classes/text_generation#transformers.generationconfig.repetition_penalty) argument.
  - `reasoning_effort` 'low' | 'medium' | 'high', nullable: Determines the amount of reasoning effort the model applies when generating a response. Higher values may produce more detailed and thoughtful outputs, but can increase response time. This parameter is only effective for reasoning models.
  - `reasoning_budget` integer, nullable: Specifies a positive integer that defines a limit on the number of tokens used for internal reasoning tokens. This parameter is only effective for reasoning models.
  - `seed` union: Seed to control random procedure. If nothing is given, random seed is used for sampling, and return the seed along with the generated result. When using the `n` argument, you can pass a list of seed values to control all of the independent generations.
    - integer[]
    - integer
  - `stop` string[], nullable: When one of the stop phrases appears in the generation result, the API will stop generation. The stop phrases are excluded from the result. Defaults to empty list.
  - `stream` boolean, nullable: Whether to stream the generation result. When set to `true`, each token will be sent as [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format) once generated.
  - `stream_options` StreamOptions
    - `include_usage` boolean, nullable: When set to `true`, the number of tokens used will be included at the end of the stream result in the form of `"usage": {"completion_tokens": number, "prompt_tokens": number, "total_tokens": number}`.
  - `parse_reasoning` boolean, nullable: Parses model reasoning into `reasoning_content` while keeping the answer in `content`. Default value may vary between endpoints. For more detailed information, please refer [here](https://friendli.ai/docs/guides/reasoning#reasoning-parsing-with-friendli).
  - `include_reasoning` boolean, nullable: When `parse_reasoning=true`, include parsed reasoning (`reasoning_content`). Defaults to true. For more detailed information, please refer [here](https://friendli.ai/docs/guides/reasoning#reasoning-parsing-with-friendli).
  - `temperature` number, nullable: Sampling temperature. Smaller temperature makes the generation result closer to greedy, argmax (i.e., `top_k = 1`) sampling. Defaults to 1.0. This is similar to Hugging Face's [`temperature`](https://huggingface.co/docs/transformers/v4.26.0/en/main_classes/text_generation#transformers.generationconfig.temperature) argument.
  - `tool_choice` union: Determines the tool calling behavior of the model. When set to `none`, the model will bypass tool execution and generate a response directly. In `auto` mode (the default), the model dynamically decides whether to call a tool or respond with a message. Alternatively, setting `required` ensures that the model invokes at least one tool before responding to the user. You can also specify a particular tool by `{"type": "function", "function": {"name": "my_function"}}`.
    - ChatCompleteBodyToolChoice
      - `type` 'function', required: The type of the tool. Currently, only `function` is supported.
      - `function` ChatCompleteBodyToolChoiceFunction, required
        - `name` string, required: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
    - string
  - `top_k` integer, nullable: Limits sampling to the top k tokens with the highest probabilities. Values range from 0 (no filtering) to the model's vocabulary size (inclusive). The default value of 0 applies no filtering, allowing all tokens.
  - `top_logprobs` integer, nullable: The number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to true if this parameter is used.
  - `top_p` number, nullable: Keeps only the smallest set of tokens whose cumulative probabilities reach `top_p` or higher. Values range from 0.0 (exclusive) to 1.0 (inclusive). The default value of 1.0 includes all tokens, allowing maximum diversity.
  - `xtc_threshold` number, nullable: A probability threshold used to identify “top choice” tokens for exclusion in XTC (Exclude Top Choices) sampling. Tokens with probabilities at or above this threshold are considered viable candidates, and all but the least likely viable token are excluded from sampling. This option reduces the dominance of highly probable tokens while preserving some diversity by keeping the least confident “top choice.” Values range from 0.0 (inclusive) to 1.0 (inclusive). Higher values make the filtering more selective by requiring higher probabilities to trigger exclusion, while lower values apply filtering more broadly. The default value of 0.0 disables XTC filtering entirely.
  - `xtc_probability` number, nullable: The probability that XTC (Exclude Top Choices) filtering will be applied for each sampling decision. When XTC is triggered, high-probability tokens above the `xtc_threshold` are excluded except for the least likely viable token. This stochastic activation allows for a balance between standard sampling and creativity-boosting exclusion filtering. Values range from 0.0 (inclusive) to 1.0 (inclusive), where 0.0 means XTC is never applied, 1.0 means XTC is always applied when viable tokens exist, and intermediate values provide probabilistic activation. The default value of 0.0 disables XTC filtering.
  - `tools` Tool[], nullable: A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for. **When `tools` is specified, `min_tokens` and `response_format` fields are unsupported.**
    - `type` 'function', required: The type of the tool. Currently, only `function` is supported.
    - `function` Function, required
      - `description` string, nullable: A description of what the function does, used by the model to choose when and how to call the function.
      - `name` string, required: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
      - `parameters` object, required: The parameters the functions accepts, described as a JSON Schema object. To represent a function with no parameters, use the value `{"type": "object", "properties": {}}`.
  - `min_tokens` integer, nullable: The minimum number of tokens to generate. Default value is 0. This is similar to Hugging Face's [`min_new_tokens`](https://huggingface.co/docs/transformers/v4.26.0/en/main_classes/text_generation#transformers.generationconfig.min_new_tokens) argument. **This field is unsupported when `tools` or `response_format` is specified.**
  - `response_format` union: The enforced format of the model's output. Note that the content of the output message may be truncated if it exceeds the `max_tokens`. You can check this by verifying that the `finish_reason` of the output message is `length`. For more detailed information, please refer [here](https://friendli.ai/docs/guides/structured-outputs). ***Important*** You must explicitly instruct the model to produce the desired output format using a system prompt or user message (e.g., `You are an API generating a valid JSON as output.`). Otherwise, the model may result in an unending stream of whitespace or other characters. **When `response_format` is specified, `min_tokens` field is unsupported.**
    - ResponseFormatJsonSchema
      - `type` 'json_schema', required: The type of the response format: `json_schema`
      - `json_schema` ResponseFormatJsonSchemaSchema, required
        - `schema` object, required: The schema for the response format, described as a JSON Schema object.
    - ResponseFormatJsonObject
      - `type` 'json_object', required: The type of the response format: `json_object`
    - ResponseFormatRegex
      - `type` 'regex', required: The type of the response format: `regex`
      - `schema` string, required: The schema of the output. Lookaheads or lookbehinds (e.g., `\a`, `\z`, `^`, `$`, `(?=)`, `(?!)`, `(?<=...)`, `(?<!...)`) are not supported. Group specials (e.g., `\w`, `\W`, `\d`, `\D`, `\s`, `\S`) do not support non-ASCII characters. Unicode escape patterns (e.g., `\N`, `\p`, `\P`) are not supported. Additionally, conditional matching (`(?(`) and back-references can cause inefficiency.
    - ResponseFormatText
      - `type` 'text', required: The type of the response format: `text`

## Response `200`

Successfully generated a chat response.

## Other responses

- `422`: Unprocessable Entity

---

[API](https://skmtc.dev/friendli/apis/friendli-suite-api-reference.md) - [All operations](https://skmtc.dev/friendli/apis/friendli-suite-api-reference/llms.txt) - [OpenAPI document](https://skmtc.dev/friendli/apis/friendli-suite-api-reference/revisions/38fb43993a11?raw)
