For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DocsAPI ReferenceSDKs
DocsAPI ReferenceSDKs
      • Overview
      • Chat Completions
      • Prompt Templates
      • Files & Batches
      • Embeddings
      • Image Generation
      • Responses (Reasoning)
      • Compare (Multi-model)
      • Models
      • Error Handling
LogoLogo
On this page
  • Chat Completions
  • Streaming
Go SDK

Chat Completions

||View as Markdown|
Was this page helpful?
Edit this page
Previous

Go SDK

Next

Prompt Templates

Built with

Chat Completions

1model := "openai/gpt-4o-mini"
2resp, err := client.Chat.Completions.Create(ctx, meshapi.ChatCompletionParams{
3 Model: &model,
4 Messages: []meshapi.ChatMessage{
5 {Role: "system", Content: "You are a helpful assistant."},
6 {Role: "user", Content: "Explain quantum entanglement."},
7 },
8})
9
10if err == nil {
11 fmt.Println(*resp.Choices[0].Message.Content)
12}

Streaming

Streaming uses Go channels to receive chunks as they arrive:

1chunkCh, errCh := client.Chat.Completions.Stream(ctx, params)
2for chunk := range chunkCh {
3 if len(chunk.Choices) > 0 && chunk.Choices[0].Delta != nil {
4 fmt.Print(*chunk.Choices[0].Delta.Content)
5 }
6}
7if err := <-errCh; err != nil {
8 // Handle stream error
9}