Skip to main content

Endpoint

Creates a completion for the provided prompt using the specified model.
The completions endpoint is considered legacy. Use the Chat Completions endpoint for new applications.

Request

Headers

string
required
Must be application/json
string
required
The AI provider to use
string
required
Your API key for the specified provider

Body Parameters

string
required
The model to use for completion (e.g., gpt-3.5-turbo-instruct, text-davinci-003)
string | array
required
The prompt(s) to generate completions for
integer
default:16
Maximum number of tokens to generate
number
default:1
Sampling temperature between 0 and 2
number
default:1
Nucleus sampling parameter
integer
default:1
Number of completions to generate
boolean
default:false
Whether to stream the response
string | array
Up to 4 sequences where the API will stop generating
number
default:0
Penalty for token presence (-2.0 to 2.0)
number
default:0
Penalty for token frequency (-2.0 to 2.0)
string
Text to append after the completion
boolean
default:false
Echo back the prompt in addition to the completion
integer
default:1
Generate multiple completions server-side and return the best
integer
Include log probabilities on the most likely tokens
string
Unique identifier for the end-user

Response

string
Unique identifier for the completion
string
Object type, always text_completion
integer
Unix timestamp of creation
string
The model used for completion
array
Array of completion choices
string
The generated text
integer
Choice index
object
Log probability information (if requested)
string
Reason for completion: stop, length, or content_filter
object
Token usage information
integer
Number of tokens in the prompt
integer
Number of tokens in the completion
integer
Total tokens used

Examples

Basic Completion

Response

Python SDK

JavaScript SDK

Multiple Completions

Streaming Completion

With Stop Sequences