Skip to content

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/completions

Parameters

ParameterTypeRequiredDescription
modelstringYesModel identifier
promptstring | arrayYesPrompt text to complete
max_tokensintegerNoMax tokens to generate
temperaturenumberNoSampling temperature, default 1
top_pnumberNoNucleus sampling, default 1
streambooleanNoStream the response, default false
stopstring | arrayNoStop 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.