Perform streaming chat completion inference on the service
- POST /_inference/chat_completion/{inference_id}/_stream
The chat completion inference API enables real-time responses for chat completion tasks by delivering answers incrementally, reducing response times during computation.
It only works with the chat_completion task type.
NOTE: The chat_completion task type supports both streaming and non-streaming.
The Chat completion inference API and the Stream inference API differ in their response structure and capabilities.
The Chat completion inference API provides more comprehensive customization options through more fields and function calling support.
To determine whether a given inference service supports this task type, please see the page for that service.
Path Parameters
-
inference_idstring Idrequired -
The inference Id
Query Parameters
-
timeoutstring Duration · default: 120s Specifies the amount of time to wait for the inference request to complete.
Request
-
messagesMessagerequired -
A list of objects representing the conversation. Requests should generally only add new messages from the user (role
user). The other message roles (assistant,system, ortool) should generally only be copied from the response to a previous completion request, such that the messages array is built up throughout a conversation. -
contentMessageContent -
The content of the message.
String example:
{ "content": "Some string" }Text example:
{ "content": [ { "text": "Some text", "type": "text" } ] }Image example:
{ "content": [ { "image_url": { "url": "data:image/jpeg;base64,..." }, "type": "image_url" } ] }File example:
{ "content": [ { "file": { "file_data": "data:application/pdf;base64,...", "filename": "somePDF" }, "type": "file" } ] } -
rolestringrequired -
The role of the message author. Valid values are
user,assistant,system, andtool. -
tool_call_idstring Id -
Only for
toolrole messages. The tool call that this message is responding to. -
tool_callsToolCall -
Only for
assistantrole messages. The tool calls generated by the model. If it's specified, thecontentfield is optional. Example:{ "tool_calls": [ { "id": "call_KcAjWtAww20AihPHphUh46Gd", "type": "function", "function": { "name": "get_current_weather", "arguments": "{\"location\":\"Boston, MA\"}" } } ] } -
reasoningstring -
Only for
assistantrole messages. The reasoning details generated by the model as plaintext. Currently supported only forelasticprovider. -
reasoning_detailsReasoningDetail -
Only for
assistantrole messages. The reasoning details generated by the model as structured data. Currently supported only forelasticprovider. -
formatstring -
The format of the reasoning detail.
-
idstring -
The identifier of the reasoning detail.
-
indexnumber -
The index of the reasoning detail, which indicates its position in the sequence of reasoning details generated by the model.
-
typerequired -
Values:
reasoning.encrypted -
datastringrequired -
The encrypted reasoning data generated by the model, which may be redacted or protected based on the model's configuration and the nature of the reasoning information.
-
formatstring -
The format of the reasoning detail.
-
idstring -
The identifier of the reasoning detail.
-
indexnumber -
The index of the reasoning detail, which indicates its position in the sequence of reasoning details generated by the model.
-
typerequired -
Values:
reasoning.summary -
summarystringrequired -
The summary of the reasoning process generated by the model, which provides an overview of the key points and conclusions reached during the reasoning process.
-
formatstring -
The format of the reasoning detail.
-
idstring -
The identifier of the reasoning detail.
-
indexnumber -
The index of the reasoning detail, which indicates its position in the sequence of reasoning details generated by the model.
-
typerequired -
Values:
reasoning.text -
signaturestring -
The signature of the reasoning text, which can be used to verify the authenticity and integrity of the reasoning information provided by the model.
-
textstring -
The plaintext reasoning generated by the model, which provides a detailed explanation of the model's reasoning process in human-readable form.
-
modelstring -
The ID of the model to use. By default, the model ID is set to the value included when creating the inference endpoint.
-
max_completion_tokensnumber -
The upper bound limit for the number of tokens that can be generated for a completion request.
-
reasoningReasoning -
The reasoning configuration for the completion request. This controls the model's reasoning process in one of two ways:
- By specifying the model’s reasoning effort level with the
effortfield. - By enabling reasoning with default settings by setting
enabledfield totrue.
It also includes optional settings to control:
- The level of detail in the summary returned in the response with the
summaryfield. - Whether reasoning details are included in the response at all with the
excludefield.
Example (effort):
{ "reasoning": { "effort": "high", "summary": "concise", "exclude": false } }Example (enabled):
{ "reasoning": { "enabled": true, "summary": "concise", "exclude": false } }Currently supported only for
elasticprovider. - By specifying the model’s reasoning effort level with the
-
effortReasoningEffort -
The level of effort the model should put into reasoning. This is a hint that guides the model in how much effort to put into reasoning, with
xhighbeing the most effort andnonebeing no effort. -
Values:
xhighhighmediumlowminimalnone -
enabledboolean -
Whether to enable reasoning with default settings. This is a shortcut for enabling reasoning without having to specify the other parameters. If
enabledis set totrue, then reasoning at themediumeffort level is enabled. Ignored ifeffortis specified, in which case that parameter will control the reasoning process instead. -
excludeboolean -
Whether to exclude reasoning information from the response. If
true, the response will not include any reasoning details. -
summaryReasoningSummary -
The level of detail included in the reasoning summary returned in the response. This is a hint on how much detail to include in the summary of the reasoning that is returned in the response, with
autobeing the default level of detail,concisebeing less detail, anddetailedbeing more detail. -
Values:
autoconcisedetailed -
stopstring -
A sequence of strings to control when the model should stop generating additional tokens.
-
temperaturenumber -
The sampling temperature to use.
-
tool_choiceCompletionToolType -
Controls which tool is called by the model. String representation: One of
auto,none, orrequrired.autoallows the model to choose between calling tools and generating a message.nonecauses the model to not call any tools.requiredforces the model to call one or more tools. Example (object representation):{ "tool_choice": { "type": "function", "function": { "name": "get_current_weather" } } } -
toolsCompletionTool -
A list of tools that the model can call. Example:
{ "tools": [ { "type": "function", "function": { "name": "get_price_of_item", "description": "Get the current price of an item", "parameters": { "type": "object", "properties": { "item": { "id": "12345" }, "unit": { "type": "currency" } } } } } ] } -
typestringrequired -
The type of tool.
-
functionCompletionToolFunctionrequired -
The function definition.
-
descriptionstring -
A description of what the function does. This is used by the model to choose when and how to call the function.
-
namestringrequired -
The name of the function.
-
parametersobject -
The parameters the functional accepts. This should be formatted as a JSON object.
-
strictboolean -
Whether to enable schema adherence when generating the function call.
-
top_pnumber -
Nucleus sampling, an alternative to sampling with temperature.
The reasoning detail with encrypted reasoning data that may be redacted or protected.
The reasoning summary detail includes a high-level summary of the model's reasoning process.
The reasoning text detail includes plaintext reasoning with optional signature verification.
Response
Response Type: StreamResult