Completions¶
The legacy text completion endpoint. For most use cases, prefer Chat Completions instead.
Endpoint¶
Request Body¶
| Parameter | Type | Required | Description |
|---|---|---|---|
model |
string | ✅ | Model ID |
prompt |
string/array | ✅ | Text prompt(s) to complete |
max_tokens |
integer | Maximum tokens to generate. Default: 16 | |
temperature |
number | Sampling temperature (0–2). Default: 1 | |
top_p |
number | Nucleus sampling. Default: 1 | |
stream |
boolean | Enable SSE streaming. Default: false | |
stop |
string/array | Stop sequences | |
n |
integer | Number of completions. Default: 1 | |
echo |
boolean | Echo the prompt in the response. Default: false |
Example¶
Response¶
{
"id": "cmpl-abc123",
"object": "text_completion",
"created": 1723456789,
"model": "gpt-3.5-turbo-instruct",
"choices": [
{
"text": "\nSilicon whispers\nLogic flows through circuits bright\nBugs hide in the night",
"index": 0,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 7,
"completion_tokens": 19,
"total_tokens": 26
}
}