Generate legacy text completion from prompt
Generates a legacy text completion from a raw prompt (a string or list of strings).
Use this endpoint for non-chat, prompt-in/text-out inference using the OpenAI text-completion
contract; use /v5/chat/completions when you have a structured messages array, /v5/responses for
the OpenAI Responses API, and /v5/inference for payloads that follow no OpenAI schema. The model is
selected from model given as vendor/name and routed to the matching per-vendor gateway. When
stream is set the response is delivered as server-sent events; otherwise a single text_completion
object is returned. Token usage is recorded for the account, read from the final chunk on streaming
responses.
Parameters
Generates best_of completions server-side and returns the best one. Must be greater than n when used together.
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text.
Modify the likelihood of specified tokens appearing in the completion. Maps tokens to bias values from -100 to 100.
Number between -2.0 and 2.0. Positive values penalize new tokens based on their presence in the text so far.
If specified, attempts to generate deterministic samples. Determinism is not guaranteed.
Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events.
Options for streaming response. Only set this when stream is True.
The suffix that comes after a completion of inserted text. Only supported for gpt-3.5-turbo-instruct.
Sampling temperature between 0 and 2. Higher values make output more random, lower more focused.
Generate legacy text completion from prompt
import os
from scale_gp_beta import SGPClient
client = SGPClient(
api_key=os.environ.get("SGP_API_KEY"), # This is the default and can be omitted
)
for completion in client.completions.create(
model="model",
prompt="string",
):
print(completion){
"id": "id",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"text": "text",
"logprobs": {
"text_offset": [
0
],
"token_logprobs": [
0
],
"tokens": [
"string"
],
"top_logprobs": [
{
"foo": 0
}
]
}
}
],
"created": 0,
"model": "model",
"object": "text_completion",
"system_fingerprint": "system_fingerprint",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0
}
}
}Returns Examples
{
"id": "id",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"text": "text",
"logprobs": {
"text_offset": [
0
],
"token_logprobs": [
0
],
"tokens": [
"string"
],
"top_logprobs": [
{
"foo": 0
}
]
}
}
],
"created": 0,
"model": "model",
"object": "text_completion",
"system_fingerprint": "system_fingerprint",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0
}
}
}