Completions
The Completions API allows you to generate text continuations from a prompt. For conversational AI, we recommend using the Chat Completions API instead.
The Chat Completions API is generally preferred for most use cases as it provides better control over the conversation context and system instructions.
The completion model
The completion model takes a text prompt and generates a continuation.
Properties
- Name
model- Type
- string
- Description
The ID of the model to use for completion.
- Name
prompt- Type
- string
- Description
The text prompt to generate a completion for.
- Name
max_tokens- Type
- integer
- Description
The maximum number of tokens to generate.
- Name
temperature- Type
- number
- Description
Controls randomness. Higher values make output more random. Range: 0-2, default: 1.
- Name
stream- Type
- boolean
- Description
If set to
true, partial completions will be sent as server-sent events. Default:false.
Create completion
Generate a text completion based on a prompt.
Required attributes
- Name
model- Type
- string
- Description
The model ID to use for completion.
- Name
prompt- Type
- string
- Description
The text prompt to complete.
Optional attributes
- Name
max_tokens- Type
- integer
- Description
Maximum tokens to generate. Default: 16.
- Name
temperature- Type
- number
- Description
Sampling temperature (0-2). Default: 1.
- Name
stream- Type
- boolean
- Description
Enable streaming responses. Default: false.
Request
from openai import OpenAI
client = OpenAI(
base_url="https://api.nextbit256.com/v1",
api_key="your-api-key"
)
response = client.completions.create(
model="llama3.3:70b",
prompt="Once upon a time",
max_tokens=50
)
print(response.choices[0].text)
Response
{
"id": "cmpl-6ff64705f50d43cbbab7cd03250e9382",
"object": "text_completion",
"created": 1742470129,
"model": "llama3.3:70b",
"choices": [
{
"text": ", in a land far away, there lived a wise old wizard...",
"index": 0,
"logprobs": null,
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 4,
"completion_tokens": 50,
"total_tokens": 54
}
}