Use this file to discover all available pages before exploring further.
The Stream() method is used to make streaming chat completion requests to the Edgee AI Gateway. It returns two channels: one for StreamChunk objects and one for errors.
When input is a string, it’s automatically converted to a user message:
chunkChan, errChan := client.Stream("gpt-5.2", "Tell me a story")for { select { case chunk, ok := <-chunkChan: if !ok { return } if text := chunk.Text(); text != "" { fmt.Print(text) } if reason := chunk.FinishReason(); reason != "" { fmt.Printf("\nFinished: %s\n", reason) } case err := <-errChan: if err != nil { log.Fatal(err) } }}// Equivalent to: input: InputObject{Messages: []Message{{Role: "user", Content: "Tell me a story"}}}
When input is an InputObject or map[string]interface{}, you have full control over the conversation:
Property
Type
Description
Messages
[]Message
Array of conversation messages
Tools
[]Tool
Array of function tools available to the model
ToolChoice
any
Controls which tool (if any) the model should call. See Tools documentation for details
Tags
[]string
Optional tags to categorize and label the request for analytics and filtering. Can also be sent via the x-edgee-tags header (comma-separated)
CompressionModel
*string
Compression model for this request: "agentic", "claude", "opencode", "cursor", or "customer". Each model is a bundle of compression strategies. Overrides API key settings when present.
CompressionConfiguration
*CompressionConfiguration
Configuration for the compression model. Currently only available for agentic. Contains optional Rate (0.0-1.0, default 0.8) and SemanticPreservationThreshold (0-100).
Final chunk: Contains FinishReason indicating why generation stopped
Example - Collecting Full Response:
chunkChan, errChan := client.Stream("gpt-5.2", "Tell me a story")var fullText strings.Builderfor { select { case chunk, ok := <-chunkChan: if !ok { fmt.Printf("\n\nFull response (%d characters):\n", fullText.Len()) fmt.Println(fullText.String()) return } if text := chunk.Text(); text != "" { fullText.WriteString(text) fmt.Print(text) // Also display as it streams } case err := <-errChan: if err != nil { log.Fatal(err) } }}
Some chunks may not contain Content. This is normal and can happen when:
The chunk only contains metadata (role, finish_reason)
The chunk is part of tool call processing
Network buffering creates empty chunks
Always check for chunk.Text() before using it:
for { select { case chunk, ok := <-chunkChan: if !ok { return } if text := chunk.Text(); text != "" { // ✅ Good: Check before using fmt.Print(text) } // ❌ Bad: fmt.Print(chunk.Text()) - may print empty string case err := <-errChan: if err != nil { log.Fatal(err) } }}