Skip to content

Completions

Create completion
Completion completions().create(CompletionCreateParamsparams, RequestOptionsrequestOptions = RequestOptions.none())
POST/completions
ModelsExpand Collapse
class Completion:

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

String id

A unique identifier for the completion.

List<CompletionChoice> choices

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

FinishReason finishReason

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:
STOP("stop")
LENGTH("length")
CONTENT_FILTER("content_filter")
long index
Optional<Logprobs> logprobs
Optional<List<Long>> textOffset
Optional<List<Double>> tokenLogprobs
Optional<List<String>> tokens
Optional<List<TopLogprob>> topLogprobs
String text
long created

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

String model

The model used for completion.

JsonValue; object_ "text_completion"constant"text_completion"constant

The object type, which is always "text_completion"

Optional<String> systemFingerprint

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.

Optional<CompletionUsage> usage

Usage statistics for the completion request.

class CompletionChoice:
FinishReason finishReason

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:
STOP("stop")
LENGTH("length")
CONTENT_FILTER("content_filter")
long index
Optional<Logprobs> logprobs
Optional<List<Long>> textOffset
Optional<List<Double>> tokenLogprobs
Optional<List<String>> tokens
Optional<List<TopLogprob>> topLogprobs
String text
class CompletionUsage:

Usage statistics for the completion request.

long completionTokens

Number of tokens in the generated completion.

long promptTokens

Number of tokens in the prompt.

long totalTokens

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

Optional<CompletionTokensDetails> completionTokensDetails

Breakdown of tokens used in a completion.

Optional<Long> acceptedPredictionTokens

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

Optional<Long> audioTokens

Audio input tokens generated by the model.

Optional<Long> reasoningTokens

Tokens generated by the model for reasoning.

Optional<Long> rejectedPredictionTokens

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.

Optional<PromptTokensDetails> promptTokensDetails

Breakdown of tokens used in the prompt.

Optional<Long> audioTokens

Audio input tokens present in the prompt.

Optional<Long> cachedTokens

Cached tokens present in the prompt.