Skip to content

Completions

Create completion
client.Completions.New(ctx, body) (*Completion, error)
POST/completions
ModelsExpand Collapse
type Completion struct{…}

Represents a completion response from the API. Note: both the streamed and non-streamed response objects share the same shape (unlike the chat endpoint).

ID string

A unique identifier for the completion.

The list of completion choices the model generated for the input prompt.

FinishReason CompletionChoiceFinishReason

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, or content_filter if content was omitted due to a flag from our content filters.

Accepts one of the following:
const CompletionChoiceFinishReasonStop CompletionChoiceFinishReason = "stop"
const CompletionChoiceFinishReasonLength CompletionChoiceFinishReason = "length"
const CompletionChoiceFinishReasonContentFilter CompletionChoiceFinishReason = "content_filter"
Index int64
Logprobs CompletionChoiceLogprobs
TextOffset []int64optional
TokenLogprobs []float64optional
Tokens []stringoptional
TopLogprobs []map[string, float64]optional
Text string
Created int64

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

Model string

The model used for completion.

Object TextCompletion

The object type, which is always "text_completion"

SystemFingerprint 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.

type CompletionChoice struct{…}
FinishReason CompletionChoiceFinishReason

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, or content_filter if content was omitted due to a flag from our content filters.

Accepts one of the following:
const CompletionChoiceFinishReasonStop CompletionChoiceFinishReason = "stop"
const CompletionChoiceFinishReasonLength CompletionChoiceFinishReason = "length"
const CompletionChoiceFinishReasonContentFilter CompletionChoiceFinishReason = "content_filter"
Index int64
Logprobs CompletionChoiceLogprobs
TextOffset []int64optional
TokenLogprobs []float64optional
Tokens []stringoptional
TopLogprobs []map[string, float64]optional
Text string
type CompletionUsage struct{…}

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.