Skip to content
  • Auto
  • Light
  • Dark

Create

Creates a model response for the given chat conversation.
post/chat/completions

Creates a model response for the given chat conversation.

Body ParametersExpand Collapse
messages: array of object { content, role } or object { content, role } or object { content, role } or 2 more

A list of messages comprising the conversation so far.

Accepts one of the following:
System = object { content, role }

System-provided instructions that the model should follow, regardless of messages sent by the user.

content: string or array of string

The contents of the system message.

Accepts one of the following:
TextContent = string

The contents of the system message.

ArrayOfContentParts = array of string

An array of content parts with a defined type. For system messages, only type text is supported.

role: "system"

The role of the messages author, in this case system.

Accepts one of the following:
"system"
Developer = object { content, role }

Developer-provided instructions that the model should follow, regardless of messages sent by the user.

content: string or array of string

The contents of the developer message.

Accepts one of the following:
TextContent = string

The contents of the developer message.

ArrayOfContentParts = array of string

An array of content parts with a defined type. For developer messages, only type text is supported.

role: "developer"

The role of the messages author, in this case developer.

Accepts one of the following:
"developer"
User = object { content, role }

Messages sent by an end user, containing prompts or additional context information.

content: string or array of string

The contents of the user message.

Accepts one of the following:
TextContent = string

The text contents of the message.

ArrayOfContentParts = array of string

An array of content parts with a defined type. Supported options differ based on the model being used to generate the response.

role: "user"

The role of the messages author, in this case user.

Accepts one of the following:
"user"
Assistant = object { role, content, tool_calls }

Messages sent by the model in response to user messages.

role: "assistant"

The role of the messages author, in this case assistant.

Accepts one of the following:
"assistant"
content: optional string or array of string

The contents of the assistant message.

Accepts one of the following:
TextContent = string

The contents of the assistant message.

ArrayOfContentParts = array of string

An array of content parts with a defined type. Can be one or more of type text, or exactly one of type refusal.

tool_calls: optional array of object { id, function, type }

The tool calls generated by the model, such as function calls.

id: string

The ID of the tool call.

function: object { arguments, name }

The function that the model called.

arguments: string

The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.

name: string

The name of the function to call.

type: "function"

The type of the tool. Currently, only function is supported.

Accepts one of the following:
"function"
Tool = object { content, role, tool_call_id }
content: string

The contents of the tool message.

role: "tool"

The role of the messages author, in this case tool.

Accepts one of the following:
"tool"
tool_call_id: string

Tool call that this message is responding to.

model: string

Model ID used to generate the response.

frequency_penalty: optional number

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.

minimum-2
maximum2
logit_bias: optional map[number]

Modify the likelihood of specified tokens appearing in the completion.

Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.

logprobs: optional boolean

Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message.

max_completion_tokens: optional number

The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run.

minimum256
max_tokens: optional number

The maximum number of tokens that can be generated in the completion.

The token count of your prompt plus max_tokens cannot exceed the model's context length.

minimum0
metadata: optional map[string]

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

n: optional number

How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.

minimum1
maximum128
presence_penalty: optional number

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.

minimum-2
maximum2
stop: optional string or array of string

Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.

Accepts one of the following:
UnionMember0 = string
UnionMember1 = array of string
stream: optional boolean

If set to true, the model response data will be streamed to the client as it is generated using server-sent events.

stream_options: optional object { include_usage }

Options for streaming response. Only set this when you set stream: true.

include_usage: optional boolean

If set, an additional chunk will be streamed before the data: [DONE] message. The usage field on this chunk shows the token usage statistics for the entire request, and the choices field will always be an empty array.

All other chunks will also include a usage field, but with a null value. NOTE: If the stream is interrupted, you may not receive the final usage chunk which contains the total token usage for the request.

temperature: optional number

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. We generally recommend altering this or top_p but not both.

minimum0
maximum2
tool_choice: optional "none" or "auto" or "required" or object { function, type }

Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools. Specifying a particular tool via {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool.

none is the default when no tools are present. auto is the default if tools are present.

Accepts one of the following:
UnionMember0 = "none" or "auto" or "required"

none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools.

"none"
"auto"
"required"
ChatCompletionNamedToolChoice = object { function, type }

Specifies a tool the model should use. Use to force the model to call a specific function.

function: object { name }
name: string

The name of the function to call.

type: "function"

The type of the tool. Currently, only function is supported.

Accepts one of the following:
"function"
tools: optional array of object { function, type }

A list of tools the model may call. Currently, only functions are supported as a tool.

function: object { name, description, parameters }
name: string

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.

description: optional string

A description of what the function does, used by the model to choose when and how to call the function.

parameters: optional map[unknown]

The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.

Omitting parameters defines a function with an empty parameter list.

type: "function"

The type of the tool. Currently, only function is supported.

Accepts one of the following:
"function"
top_logprobs: optional number

An integer between 0 and 20 specifying 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.

minimum0
maximum20
top_p: optional number

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.

We generally recommend altering this or temperature but not both.

minimum0
maximum1
user: optional string

A unique identifier representing your end-user, which can help DigitalOcean to monitor and detect abuse.

ReturnsExpand Collapse
id: string

A unique identifier for the chat completion.

choices: array of object { finish_reason, index, logprobs, message }

A list of chat completion choices. Can be more than one if n is greater than 1.

finish_reason: "stop" or "length" or "tool_calls"

The reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence, or length if the maximum number of tokens specified in the request was reached, tool_calls if the model called a tool.

Accepts one of the following:
"stop"
"length"
"tool_calls"
index: number

The index of the choice in the list of choices.

logprobs: object { content, refusal }

Log probability information for the choice.

content: array of ChatCompletionTokenLogprob

A list of message content tokens with log probability information.

refusal: array of ChatCompletionTokenLogprob

A list of message refusal tokens with log probability information.

message: object { content, refusal, role, tool_calls }

A chat completion message generated by the model.

content: string

The contents of the message.

refusal: string

The refusal message generated by the model.

role: "assistant"

The role of the author of this message.

Accepts one of the following:
"assistant"
tool_calls: optional array of object { id, function, type }

The tool calls generated by the model, such as function calls.

id: string

The ID of the tool call.

function: object { arguments, name }

The function that the model called.

arguments: string

The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.

name: string

The name of the function to call.

type: "function"

The type of the tool. Currently, only function is supported.

Accepts one of the following:
"function"
created: number

The Unix timestamp (in seconds) of when the chat completion was created.

model: string

The model used for the chat completion.

object: "chat.completion"

The object type, which is always chat.completion.

Accepts one of the following:
"chat.completion"
usage: optional CompletionUsage

Usage statistics for the completion request.

curl $GRADIENT_INFERENCE_ENDPOINT/v1/chat/completions \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $DIGITALOCEAN_ACCESS_TOKEN" \
    -d '{
          "messages": [
            {
              "content": "string",
              "role": "system"
            }
          ],
          "model": "llama3-8b-instruct",
          "n": 1,
          "temperature": 1,
          "top_p": 1,
          "user": "user-1234"
        }'
{
  "id": "id",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": {
        "content": [
          {
            "token": "token",
            "bytes": [
              0
            ],
            "logprob": 0,
            "top_logprobs": [
              {
                "token": "token",
                "bytes": [
                  0
                ],
                "logprob": 0
              }
            ]
          }
        ],
        "refusal": [
          {
            "token": "token",
            "bytes": [
              0
            ],
            "logprob": 0,
            "top_logprobs": [
              {
                "token": "token",
                "bytes": [
                  0
                ],
                "logprob": 0
              }
            ]
          }
        ]
      },
      "message": {
        "content": "content",
        "refusal": "refusal",
        "role": "assistant",
        "tool_calls": [
          {
            "id": "id",
            "function": {
              "arguments": "arguments",
              "name": "name"
            },
            "type": "function"
          }
        ]
      }
    }
  ],
  "created": 0,
  "model": "model",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 0,
    "prompt_tokens": 0,
    "total_tokens": 0
  }
}
Returns Examples
{
  "id": "id",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": {
        "content": [
          {
            "token": "token",
            "bytes": [
              0
            ],
            "logprob": 0,
            "top_logprobs": [
              {
                "token": "token",
                "bytes": [
                  0
                ],
                "logprob": 0
              }
            ]
          }
        ],
        "refusal": [
          {
            "token": "token",
            "bytes": [
              0
            ],
            "logprob": 0,
            "top_logprobs": [
              {
                "token": "token",
                "bytes": [
                  0
                ],
                "logprob": 0
              }
            ]
          }
        ]
      },
      "message": {
        "content": "content",
        "refusal": "refusal",
        "role": "assistant",
        "tool_calls": [
          {
            "id": "id",
            "function": {
              "arguments": "arguments",
              "name": "name"
            },
            "type": "function"
          }
        ]
      }
    }
  ],
  "created": 0,
  "model": "model",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 0,
    "prompt_tokens": 0,
    "total_tokens": 0
  }
}