Skip to content

Completions

The legacy text completion endpoint. For most use cases, prefer Chat Completions instead.

Endpoint

POST /v1/completions

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

curl https://ai.moducompia.com/v1/completions \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Write a haiku about programming:",
    "max_tokens": 50,
    "temperature": 0.8
  }'
response = client.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt="Write a haiku about programming:",
    max_tokens=50,
    temperature=0.8
)
print(response.choices[0].text)

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
  }
}