Perform chat completion inference
- 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.
The chat_completion task type is only available within the _stream API and only supports 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.
Request body
-
messagesobjectrequired -
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. -
contentunion -
The content of the message.
String example:
{ "content": "Some string" }Object example:
{ "content": [ { "text": "Some text", "type": "text" } ] } -
rolestringrequired -
The role of the message author. Valid values are
user,assistant,system, andtool. -
tool_callsobject -
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\"}" } } ] } -
max_completion_tokensnumber -
The upper bound limit for the number of tokens that can be generated for a completion request.
-
stopstring -
A sequence of strings to control when the model should stop generating additional tokens.
-
tool_choiceunion -
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" } } } -
toolsobject -
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" } } } } } ] }
Response
Response Type: object