Skip to content

List Chat Completions

client.Chat.Completions.List(ctx, query) (*CursorPage[ChatCompletion], error)
GET/chat/completions

List stored Chat Completions. Only Chat Completions that have been stored with the store parameter set to true will be returned.

ParametersExpand Collapse
query ChatCompletionListParams
After param.Field[string]optional

Identifier for the last chat completion from the previous pagination request.

Limit param.Field[int64]optional

Number of Chat Completions to retrieve.

Metadata param.Field[Metadata]optional

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.

Model param.Field[string]optional

The model used to generate the Chat Completions.

Order param.Field[ChatCompletionListParamsOrder]optional

Sort order for Chat Completions by timestamp. Use asc for ascending order or desc for descending order. Defaults to asc.

const ChatCompletionListParamsOrderAsc ChatCompletionListParamsOrder = "asc"
const ChatCompletionListParamsOrderDesc ChatCompletionListParamsOrder = "desc"
ReturnsExpand Collapse
type ChatCompletion struct{…}

Represents a chat completion response returned by model, based on the provided input.

ID string

A unique identifier for the chat completion.

Choices []ChatCompletionChoice

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

FinishReason string

The reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence, length if the maximum number of tokens specified in the request was reached, content_filter if content was omitted due to a flag from our content filters, tool_calls if the model called a tool, or function_call (deprecated) if the model called a function.

Accepts one of the following:
const ChatCompletionChoiceFinishReasonStop ChatCompletionChoiceFinishReason = "stop"
const ChatCompletionChoiceFinishReasonLength ChatCompletionChoiceFinishReason = "length"
const ChatCompletionChoiceFinishReasonToolCalls ChatCompletionChoiceFinishReason = "tool_calls"
const ChatCompletionChoiceFinishReasonContentFilter ChatCompletionChoiceFinishReason = "content_filter"
const ChatCompletionChoiceFinishReasonFunctionCall ChatCompletionChoiceFinishReason = "function_call"
Index int64

The index of the choice in the list of choices.

Logprobs ChatCompletionChoiceLogprobs

Log probability information for the choice.

A list of message content tokens with log probability information.

Token string

The token.

Bytes []int64

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.

Logprob float64

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 []ChatCompletionTokenLogprobTopLogprob

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.

Token string

The token.

Bytes []int64

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.

Logprob float64

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.

A list of message refusal tokens with log probability information.

Token string

The token.

Bytes []int64

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.

Logprob float64

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 []ChatCompletionTokenLogprobTopLogprob

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.

Token string

The token.

Bytes []int64

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.

Logprob float64

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.

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.

Annotations []ChatCompletionMessageAnnotationoptional

Annotations for the message, when applicable, as when using the web search tool.

Type URLCitation

The type of the URL citation. Always url_citation.

URLCitation ChatCompletionMessageAnnotationURLCitation

A URL citation when using web search.

EndIndex int64

The index of the last character of the URL citation in the message.

StartIndex int64

The index of the first character of the URL citation in the message.

Title string

The title of the web resource.

URL string

The URL of the web resource.

Audio ChatCompletionAudiooptional

If the audio output modality is requested, this object contains data about the audio response from the model. Learn more.

ID string

Unique identifier for this audio response.

Data string

Base64 encoded audio bytes generated by the model, in the format specified in the request.

ExpiresAt int64

The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.

Transcript string

Transcript of the audio generated by the model.

DeprecatedFunctionCall ChatCompletionMessageFunctionCalloptional

Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.

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.

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

Accepts one of the following:
type ChatCompletionMessageFunctionToolCall struct{…}

A call to a function tool created by the model.

ID string

The ID of the tool call.

Function ChatCompletionMessageFunctionToolCallFunction

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.

type ChatCompletionMessageCustomToolCall struct{…}

A call to a custom tool created by the model.

ID string

The ID of the tool call.

Custom ChatCompletionMessageCustomToolCallCustom

The custom tool that the model called.

Input string

The input for the custom tool call generated by the model.

Name string

The name of the custom tool to call.

Type Custom

The type of the tool. Always custom.

Created int64

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

Model string

The model used for the chat completion.

Object ChatCompletion

The object type, which is always chat.completion.

ServiceTier ChatCompletionServiceTieroptional

Specifies the processing type used for serving the request.

  • If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
  • If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
  • If set to 'flex' or 'priority', then the request will be processed with the corresponding service tier.
  • When not set, the default behavior is 'auto'.

When the service_tier parameter is set, the response body will include the service_tier value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.

Accepts one of the following:
const ChatCompletionServiceTierAuto ChatCompletionServiceTier = "auto"
const ChatCompletionServiceTierDefault ChatCompletionServiceTier = "default"
const ChatCompletionServiceTierFlex ChatCompletionServiceTier = "flex"
const ChatCompletionServiceTierScale ChatCompletionServiceTier = "scale"
const ChatCompletionServiceTierPriority ChatCompletionServiceTier = "priority"
DeprecatedSystemFingerprint stringoptional

This fingerprint represents the backend configuration that the model runs with.

Can be used in conjunction with the seed request parameter to understand when backend changes have been made that might impact determinism.

Usage CompletionUsageoptional

Usage statistics for the completion request.

CompletionTokens int64

Number of tokens in the generated completion.

PromptTokens int64

Number of tokens in the prompt.

TotalTokens int64

Total number of tokens used in the request (prompt + completion).

CompletionTokensDetails CompletionUsageCompletionTokensDetailsoptional

Breakdown of tokens used in a completion.

AcceptedPredictionTokens int64optional

When using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.

AudioTokens int64optional

Audio input tokens generated by the model.

ReasoningTokens int64optional

Tokens generated by the model for reasoning.

RejectedPredictionTokens int64optional

When using Predicted Outputs, the number of tokens in the prediction that did not appear in the completion. However, like reasoning tokens, these tokens are still counted in the total completion tokens for purposes of billing, output, and context window limits.

PromptTokensDetails CompletionUsagePromptTokensDetailsoptional

Breakdown of tokens used in the prompt.

AudioTokens int64optional

Audio input tokens present in the prompt.

CachedTokens int64optional

Cached tokens present in the prompt.

List Chat Completions

package main

import (
  "context"
  "fmt"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/option"
)

func main() {
  client := openai.NewClient(
    option.WithAPIKey("My API Key"),
  )
  page, err := client.Chat.Completions.List(context.TODO(), openai.ChatCompletionListParams{

  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
{
  "data": [
    {
      "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",
            "annotations": [
              {
                "type": "url_citation",
                "url_citation": {
                  "end_index": 0,
                  "start_index": 0,
                  "title": "title",
                  "url": "url"
                }
              }
            ],
            "audio": {
              "id": "id",
              "data": "data",
              "expires_at": 0,
              "transcript": "transcript"
            },
            "function_call": {
              "arguments": "arguments",
              "name": "name"
            },
            "tool_calls": [
              {
                "id": "id",
                "function": {
                  "arguments": "arguments",
                  "name": "name"
                },
                "type": "function"
              }
            ]
          }
        }
      ],
      "created": 0,
      "model": "model",
      "object": "chat.completion",
      "service_tier": "auto",
      "system_fingerprint": "system_fingerprint",
      "usage": {
        "completion_tokens": 0,
        "prompt_tokens": 0,
        "total_tokens": 0,
        "completion_tokens_details": {
          "accepted_prediction_tokens": 0,
          "audio_tokens": 0,
          "reasoning_tokens": 0,
          "rejected_prediction_tokens": 0
        },
        "prompt_tokens_details": {
          "audio_tokens": 0,
          "cached_tokens": 0
        }
      }
    }
  ],
  "first_id": "first_id",
  "has_more": true,
  "last_id": "last_id",
  "object": "list"
}
Returns Examples
{
  "data": [
    {
      "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",
            "annotations": [
              {
                "type": "url_citation",
                "url_citation": {
                  "end_index": 0,
                  "start_index": 0,
                  "title": "title",
                  "url": "url"
                }
              }
            ],
            "audio": {
              "id": "id",
              "data": "data",
              "expires_at": 0,
              "transcript": "transcript"
            },
            "function_call": {
              "arguments": "arguments",
              "name": "name"
            },
            "tool_calls": [
              {
                "id": "id",
                "function": {
                  "arguments": "arguments",
                  "name": "name"
                },
                "type": "function"
              }
            ]
          }
        }
      ],
      "created": 0,
      "model": "model",
      "object": "chat.completion",
      "service_tier": "auto",
      "system_fingerprint": "system_fingerprint",
      "usage": {
        "completion_tokens": 0,
        "prompt_tokens": 0,
        "total_tokens": 0,
        "completion_tokens_details": {
          "accepted_prediction_tokens": 0,
          "audio_tokens": 0,
          "reasoning_tokens": 0,
          "rejected_prediction_tokens": 0
        },
        "prompt_tokens_details": {
          "audio_tokens": 0,
          "cached_tokens": 0
        }
      }
    }
  ],
  "first_id": "first_id",
  "has_more": true,
  "last_id": "last_id",
  "object": "list"
}