Skip to content

Completions

The Completions endpoint creates text given a prompt. Use it for classic instruction following and text generation when you do not need multi-turn message structures.


POST https://api.aifoundryhub.com/v1/completions

Creates a completion for the provided prompt and parameters.


Terminal window
curl -X POST "https://api.aifoundryhub.com/v1/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AI_FOUNDRY_HUB_API_KEY" \
-d '{
"model": "babbage-002",
"prompt": "Write a haiku about dawn",
"max_tokens": 64,
"temperature": 0.7
}'
  • When stream is false: a text completion object.
  • When stream is true: a Server-Sent Events stream of incremental completion chunks.

SSE snippet

data: {"id":"cmpl_...","object":"text_completion.chunk","choices":[{"index":0,"delta":{"text":"The"},"finish_reason":null}]}
data: {"id":"cmpl_...","object":"text_completion.chunk","choices":[{"index":0,"delta":{"text":" dawn"},"finish_reason":null}]}
data: [DONE]
{
"id": "cmpl-abc123",
"object": "text_completion",
"created": 1714569952,
"model": "babbage-002",
"choices": [
{
"index": 0,
"text": "Pale light spills over\nWaking earth in gentle hush\nDay breaks soft and new",
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 6,
"completion_tokens": 24,
"total_tokens": 30
}
}

Note: The stream ends with a terminal data: [DONE] line. Some providers also include a final non-chunk summary event with usage.

Terminal window
curl -N -X POST "https://api.aifoundryhub.com/v1/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AI_FOUNDRY_HUB_API_KEY" \
-d '{
"model": "babbage-002",
"prompt": "Write a haiku about dawn",
"stream": true,
"max_tokens": 64
}'