sarvamai-go SDK Documentation
Chat

Completions

`Chat.Completions` for non-streaming chat responses.

Signature

func (c *ChatClient) Completions(ctx context.Context, model string, messages []ChatMessage, opts ...option) (*ChatResponse, error)

Options

OptionTypeValidation
WithTemperaturefloat640.0 to 2.0
WithTopPfloat640.0 to 1.0
WithReasoningEffortlow|medium|highstrict enum
WithMaxTokensuint32no client-side range check
WithStop[]stringno client-side content check
WithNint1 to 128
WithSeedint64no client-side range check
WithFrequencyPenaltyfloat64-2.0 to 2.0
WithPresencePenaltyfloat64-2.0 to 2.0
WithWikiGroundingboolno extra validation

Request validation

  • model required
  • messages required and non-empty
  • each message needs non-empty role and content
  • all numeric range checks listed in table above

Response highlights

FieldType
IDstring
Choices[]Choice
Createdint64
Modelstring
UsageUsage

Example

resp, err := client.Chat.Completions(
    ctx,
    chat.ModelSarvamM,
    []chat.ChatMessage{
        chat.SystemMessage("You are concise."),
        chat.UserMessage("Summarize Go interfaces in 2 lines."),
    },
    chat.WithTemperature(0.4),
    chat.WithMaxTokens(120),
)
if err != nil {
    panic(err)
}

text, err := resp.FirstChoice()
if err != nil {
    panic(err)
}
fmt.Println(text)

On this page