Completions
The legacy text completion endpoint completes text from a given prompt. For new projects, prefer Chat Completions; this endpoint mainly exists for compatibility with older completion-style models and clients.
Create a completion
POST /v1/completionsParameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model identifier |
prompt | string | array | Yes | Prompt text to complete |
max_tokens | integer | No | Max tokens to generate |
temperature | number | No | Sampling temperature, default 1 |
top_p | number | No | Nucleus sampling, default 1 |
stream | boolean | No | Stream the response, default false |
stop | string | array | No | Stop sequences |
Request
bash
curl https://ai.youqi.tech/v1/completions \
-H "Authorization: Bearer sk-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Write a line of poetry about the sea:",
"max_tokens": 32
}'Response
json
{
"id": "cmpl-abc123",
"object": "text_completion",
"created": 1715367049,
"model": "gpt-3.5-turbo-instruct",
"choices": [
{
"index": 0,
"text": "The sea meets the sky, and the sky meets the heart's desire.",
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 20,
"total_tokens": 32
}
}WARNING
Completions is a legacy endpoint that is less capable than chat, and not all models support it. Unless you have a specific compatibility need, use Chat Completions.