## 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.

### Parameters

- `body CompletionNewParams`

  - `Model param.Field[string]`

    model specified as `model_vendor/model`, for example `openai/gpt-4o`

  - `Prompt param.Field[CompletionNewParamsPromptUnion]`

    The prompt to generate completions for, encoded as a string

    - `string`

    - `[]string`

  - `BestOf param.Field[int64]`

    Generates best_of completions server-side and returns the best one. Must be greater than n when used together.

  - `Echo param.Field[bool]`

    Echo back the prompt in addition to the completion

  - `FrequencyPenalty param.Field[float64]`

    Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text.

  - `LogitBias param.Field[map[string, int64]]`

    Modify the likelihood of specified tokens appearing in the completion. Maps tokens to bias values from -100 to 100.

  - `Logprobs param.Field[int64]`

    Include log probabilities of the most likely tokens. Maximum value is 5.

  - `MaxTokens param.Field[int64]`

    The maximum number of tokens that can be generated in the completion.

  - `N param.Field[int64]`

    How many completions to generate for each prompt.

  - `PresencePenalty param.Field[float64]`

    Number between -2.0 and 2.0. Positive values penalize new tokens based on their presence in the text so far.

  - `Seed param.Field[int64]`

    If specified, attempts to generate deterministic samples. Determinism is not guaranteed.

  - `Stop param.Field[CompletionNewParamsStopUnion]`

    Up to 4 sequences where the API will stop generating further tokens.

    - `string`

    - `[]string`

  - ``

  - `StreamOptions param.Field[map[string, any]]`

    Options for streaming response. Only set this when stream is True.

  - `Suffix param.Field[string]`

    The suffix that comes after a completion of inserted text. Only supported for gpt-3.5-turbo-instruct.

  - `Temperature param.Field[float64]`

    Sampling temperature between 0 and 2. Higher values make output more random, lower more focused.

  - `TopP param.Field[float64]`

    Alternative to temperature. Consider only tokens with top_p probability mass. Range 0-1.

  - `User param.Field[string]`

    A unique identifier representing your end-user, which can help OpenAI monitor and detect abuse.

### Returns

- `type Completion struct{…}`

  - `ID string`

  - `Choices []CompletionChoice`

    - `FinishReason string`

      - `const CompletionChoiceFinishReasonStop CompletionChoiceFinishReason = "stop"`

      - `const CompletionChoiceFinishReasonLength CompletionChoiceFinishReason = "length"`

      - `const CompletionChoiceFinishReasonContentFilter CompletionChoiceFinishReason = "content_filter"`

    - `Index int64`

    - `Text string`

    - `Logprobs CompletionChoiceLogprobs`

      - `TextOffset []int64`

      - `TokenLogprobs []float64`

      - `Tokens []string`

      - `TopLogprobs []map[string, float64]`

  - `Created int64`

  - `Model string`

  - `Object CompletionObject`

    - `const CompletionObjectTextCompletion CompletionObject = "text_completion"`

  - `SystemFingerprint string`

  - `Usage CompletionUsage`

    Usage statistics for the completion request.

    - `CompletionTokens int64`

    - `PromptTokens int64`

    - `TotalTokens int64`

    - `CompletionTokensDetails CompletionUsageCompletionTokensDetails`

      Breakdown of tokens used in a completion.

      - `AcceptedPredictionTokens int64`

      - `AudioTokens int64`

      - `ReasoningTokens int64`

      - `RejectedPredictionTokens int64`

    - `PromptTokensDetails CompletionUsagePromptTokensDetails`

      Breakdown of tokens used in the prompt.

      - `AudioTokens int64`

      - `CachedTokens int64`

### Example

```go
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)
}
```

#### Response

```json
{
  "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
    }
  }
}
```
