Generate legacy text completion from prompt
client.Completions.New(ctx, body) (*Completion, error)
POST/v5/completions
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.
Generate legacy text completion from prompt
package main
import (
"context"
"fmt"
"github.com/scaleapi/sgp-dev-go"
"github.com/scaleapi/sgp-dev-go/option"
)
func main() {
client := sgpdev.NewClient(
option.WithAPIKey("My API Key"),
option.WithAccountID("My Account ID"),
)
completion, err := client.Completions.New(context.TODO(), sgpdev.CompletionNewParams{
Model: "model",
Prompt: sgpdev.CompletionNewParamsPromptUnion{
OfString: sgpdev.String("string"),
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", completion.ID)
}
{
"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
}
}
}