Creates a model response for the given chat conversation.
Creates a model response for the given chat conversation.
ParametersExpand Collapse
body ChatCompletionNewParams
Messages param.Field[[]ChatCompletionNewParamsMessage]A list of messages comprising the conversation so far.
A list of messages comprising the conversation so far.
ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessage
Content ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentUnionThe contents of the system message.
The contents of the system message.
ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentArrayOfContentParts
ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentArrayOfContentPartsChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
Role ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRoleThe role of the messages author, in this case system.
The role of the messages author, in this case system.
ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessage
Content ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentUnionThe contents of the developer message.
The contents of the developer message.
ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentArrayOfContentParts
ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentArrayOfContentPartsChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
Role ChatCompletionNewParamsMessagesChatCompletionRequestDeveloperMessageRoleThe role of the messages author, in this case developer.
The role of the messages author, in this case developer.
ChatCompletionNewParamsMessagesChatCompletionRequestUserMessage
Content ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentUnionThe contents of the user message.
The contents of the user message.
ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartImageURL
ImageURL ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartImageURLImageURLImage URL settings.
Image URL settings.
A URL or data URL containing image content.
Detail ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartImageURLImageURLDetailoptionalOptional detail level for image understanding.
Optional detail level for image understanding.
Type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartImageURLTypeThe type of content part
The type of content part
ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartVideoURL
Type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartVideoURLTypeThe type of content part
The type of content part
VideoURL ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentChatCompletionRequestContentPartVideoURLVideoURLVideo URL settings.
Video URL settings.
A URL or data URL containing video content.
ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentParts
ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartImageURL
ImageURL ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartImageURLImageURLImage URL settings.
Image URL settings.
A URL or data URL containing image content.
Detail ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartImageURLImageURLDetailoptionalOptional detail level for image understanding.
Optional detail level for image understanding.
Type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartImageURLTypeThe type of content part
The type of content part
ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartVideoURL
Type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartVideoURLTypeThe type of content part
The type of content part
VideoURL ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestContentPartVideoURLVideoURLVideo URL settings.
Video URL settings.
A URL or data URL containing video content.
Role ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageRoleThe role of the messages author, in this case user.
The role of the messages author, in this case user.
ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessage
Role ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageRoleThe role of the messages author, in this case assistant.
The role of the messages author, in this case assistant.
Content ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentUnionoptionalThe contents of the assistant message.
The contents of the assistant message.
ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentArrayOfContentParts
ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentArrayOfContentPartsChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
ToolCalls []ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCalloptionalThe tool calls generated by the model, such as function calls.
The tool calls generated by the model, such as function calls.
The ID of the tool call.
Function ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsFunctionThe function that the model called.
The function that the model called.
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.
The name of the function to call.
Type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsTypeThe type of the tool. Currently, only function is supported.
The type of the tool. Currently, only function is supported.
ChatCompletionNewParamsMessagesChatCompletionRequestToolMessage
Content ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentUnionThe contents of the tool message.
The contents of the tool message.
ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentArrayOfContentParts
ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentArrayOfContentPartsChatCompletionRequestContentPartText
The text content
Type ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextTypeThe type of content part
The type of content part
CacheControl ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControloptionalCache control settings for the content part.
Cache control settings for the content part.
Type ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTypeThe cache control type.
The cache control type.
Ttl ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageContentArrayOfContentPartsChatCompletionRequestContentPartTextCacheControlTtloptionalThe cache TTL.
The cache TTL.
Role ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageRoleThe role of the messages author, in this case tool.
The role of the messages author, in this case tool.
Tool call that this message is responding to.
Model ID used to generate the response.
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.
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.
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.
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.
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.
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.
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.
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.
Constrains effort on reasoning for reasoning models. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
Constrains effort on reasoning for reasoning models. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
Up to 4 sequences where the API will stop generating further tokens. The
returned text will not contain the stop sequence.
Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
Options for streaming response. Only set this when you set stream: true.
Options for streaming response. Only set this when you set stream: true.
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.
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.
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.
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.
ChatCompletionNewParamsToolChoiceString
ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoice
Function ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceFunction
The name of the function to call.
Type ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceTypeThe type of the tool. Currently, only function is supported.
The type of the tool. Currently, only function is supported.
Tools param.Field[[]ChatCompletionNewParamsTool]optionalA list of tools the model may call. Currently, only functions are supported as a tool.
A list of tools the model may call. Currently, only functions are supported as a tool.
Function ChatCompletionNewParamsToolsFunction
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.
A description of what the function does, used by the model to choose when and how to call the function.
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 ChatCompletionNewParamsToolsTypeThe type of the tool. Currently, only function is supported.
The type of the tool. Currently, only function is supported.
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.
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.
A unique identifier representing your end-user, which can help DigitalOcean to monitor and detect abuse.
ReturnsExpand Collapse
type ChatCompletionNewResponse struct{…}Represents a chat completion response returned by model, based on the provided input.
Represents a chat completion response returned by model, based on the provided input.
A unique identifier for the chat completion.
Choices []ChatCompletionNewResponseChoiceA list of chat completion choices. Can be more than one if n is greater than 1.
A list of chat completion choices. Can be more than one if n is greater than 1.
FinishReason ChatCompletionNewResponseChoicesFinishReasonThe 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.
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.
The index of the choice in the list of choices.
Logprobs ChatCompletionNewResponseChoicesLogprobsLog probability information for the choice.
Log probability information for the choice.
Content []ChatCompletionTokenLogprobA list of message content tokens with log probability information.
A list of message content tokens with log probability information.
The token.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
TopLogprobs []ChatCompletionTokenLogprobTopLogprobList of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
The token.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
Refusal []ChatCompletionTokenLogprobA list of message refusal tokens with log probability information.
A list of message refusal tokens with log probability information.
The token.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
TopLogprobs []ChatCompletionTokenLogprobTopLogprobList of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
The token.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
Message ChatCompletionNewResponseChoicesMessageA chat completion message generated by the model.
A chat completion message generated by the model.
The contents of the message.
The reasoning content generated by the model.
The refusal message generated by the model.
Role ChatCompletionNewResponseChoicesMessageRoleThe role of the author of this message.
The role of the author of this message.
ToolCalls []ChatCompletionNewResponseChoicesMessageToolCalloptionalThe tool calls generated by the model, such as function calls.
The tool calls generated by the model, such as function calls.
The ID of the tool call.
Function ChatCompletionNewResponseChoicesMessageToolCallsFunctionThe function that the model called.
The function that the model called.
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.
The name of the function to call.
Type ChatCompletionNewResponseChoicesMessageToolCallsTypeThe type of the tool. Currently, only function is supported.
The type of the tool. Currently, only function is supported.
The Unix timestamp (in seconds) of when the chat completion was created.
The model used for the chat completion.
Object ChatCompletionNewResponseObjectThe object type, which is always chat.completion.
The object type, which is always chat.completion.
Usage statistics for the completion request.
Usage statistics for the completion request.
Number of prompt tokens written to cache.
CacheCreation CompletionUsageCacheCreationBreakdown of prompt tokens written to cache.
Breakdown of prompt tokens written to cache.
Number of prompt tokens written to 1h cache.
Number of prompt tokens written to 5m cache.
Number of prompt tokens read from cache.
Number of tokens in the generated completion.
Number of tokens in the prompt.
Total number of tokens used in the request (prompt + completion).
Creates a model response for the given chat conversation.
package main
import (
"context"
"fmt"
"github.com/stainless-sdks/-go"
"github.com/stainless-sdks/-go/option"
"github.com/stainless-sdks/-go/shared"
)
func main() {
client := gradient.NewClient(
option.WithModelAccessKey("My Model Access Key"),
)
completion, err := client.Chat.Completions.New(context.TODO(), gradient.ChatCompletionNewParams{
Messages: gradient.F([]gradient.ChatCompletionNewParamsMessageUnion{gradient.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessage{
Content: gradient.F[gradient.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageContentUnion](shared.UnionString("string")),
Role: gradient.F(gradient.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRoleSystem),
}}),
Model: gradient.F("llama3-8b-instruct"),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", completion.ID)
}
{
"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",
"reasoning_content": "reasoning_content",
"refusal": "refusal",
"role": "assistant",
"tool_calls": [
{
"id": "id",
"function": {
"arguments": "arguments",
"name": "name"
},
"type": "function"
}
]
}
}
],
"created": 0,
"model": "model",
"object": "chat.completion",
"usage": {
"cache_created_input_tokens": 0,
"cache_creation": {
"ephemeral_1h_input_tokens": 0,
"ephemeral_5m_input_tokens": 0
},
"cache_read_input_tokens": 0,
"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",
"reasoning_content": "reasoning_content",
"refusal": "refusal",
"role": "assistant",
"tool_calls": [
{
"id": "id",
"function": {
"arguments": "arguments",
"name": "name"
},
"type": "function"
}
]
}
}
],
"created": 0,
"model": "model",
"object": "chat.completion",
"usage": {
"cache_created_input_tokens": 0,
"cache_creation": {
"ephemeral_1h_input_tokens": 0,
"ephemeral_5m_input_tokens": 0
},
"cache_read_input_tokens": 0,
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0
}
}