Go SDK - Send Method
Complete guide to the Send() method in the Go SDK.
The Send() method is used to make chat completion requests to the Edgee AI Gateway.
Arguments
| Parameter | Type | Description |
|---|---|---|
model | string | The model identifier to use (e.g., "openai/gpt-5.2") |
input | any | The input for the completion. Can be a string, InputObject, *InputObject, or map[string]interface{} |
Input Types
The Send() method accept multiple input types:
String Input
When input is a string, it's automatically converted to a user message:
response, err := client.Send("gpt-5.2", "What is the capital of France?")
if err != nil {
log.Fatal(err)
}
// Equivalent to: input: InputObject{Messages: []Message{{Role: "user", Content: "What is the capital of France?"}}}
fmt.Println(response.Text())
// "The capital of France is Paris."
InputObject
When input is an InputObject, 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. Can be string ("auto", "none") or map[string]interface{}. 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) |
ToolResultTrimming | *bool | Turn tool-result trimming on or off for this request, e.g. edgee.BoolPtr(true). Leave it nil to keep the API key setting. |
ToolSurfaceReduction | *bool | Turn MCP tool surface reduction on or off for this request. The threshold still comes from the API key. Leave it nil to keep the API key setting. |
OutputBrevity | *bool | Turn output brevity on or off for this request. Leave it nil to keep the API key setting. |
Example with InputObject:
import "github.com/edgee-ai/go-sdk/edgee"
input := edgee.InputObject{
Messages: []edgee.Message{
{Role: "user", Content: "What is 2+2?"},
},
}
response, err := client.Send("gpt-5.2", input)
if err != nil {
log.Fatal(err)
}
fmt.Println(response.Text())
// "2+2 equals 4."
Example with Tags:
input := edgee.InputObject{
Messages: []edgee.Message{
{Role: "user", Content: "Summarize this article"},
},
Tags: []string{"summarization", "production", "user-123"},
}
response, err := client.Send("gpt-5.2", input)
Map Input
You can also use a map[string]interface{} for dynamic input:
input := map[string]interface{}{
"messages": []map[string]string{
{"role": "user", "content": "What is 2+2?"},
},
}
response, err := client.Send("gpt-5.2", input)
if err != nil {
log.Fatal(err)
}
Message Object
Each message in the Messages array has the following structure:
| Property | Type | Description |
|---|---|---|
Role | string | The role of the message sender: "system", "developer", "user", "assistant", or "tool" |
Content | string | The message content. Required for system, user, tool and developer roles. Optional for assistant when ToolCalls is present |
Name | *string | Optional name for the message sender |
ToolCalls | []ToolCall | Array of tool calls made by the assistant. Only present in assistant messages |
ToolCallID | *string | ID of the tool call this message is responding to. Required for tool role messages |
Message Roles
system: System instructions that set the behavior of the assistantdeveloper: Instructions provided by the application developer, prioritized ahead of user messages.user: Instructions provided by an end user.assistant: Assistant responses (can includeToolCalls)tool: Results from tool/function calls (requiresToolCallID)
Example - System and User Messages:
input := edgee.InputObject{
Messages: []edgee.Message{
{Role: "system", Content: "You are a helpful assistant."},
{Role: "user", Content: "What is 2+2?"},
{Role: "assistant", Content: "2+2 equals 4."},
{Role: "user", Content: "What about 3+3?"},
},
}
response, err := client.Send("gpt-5.2", input)
if err != nil {
log.Fatal(err)
}
fmt.Println(response.Text())
// "3+3 equals 6."
For complete tool calling examples and best practices, see Tools documentation.
Return Value
The Send() method returns (SendResponse, error). On success, the SendResponse contains:
SendResponse Object
| Property | Type | Description |
|---|---|---|
ID | string | Unique identifier for the completion |
Object | string | Object type (typically "chat.completion") |
Created | int64 | Unix timestamp of when the completion was created |
Model | string | Model identifier used for the completion |
Choices | []Choice | Array of completion choices (typically one) |
Usage | *Usage | Token usage information (if provided by the API) |
Compression | *Compression | Token compression metrics (if compression was applied) |
Choice Object
Each choice in the Choices array contains:
| Property | Type | Description |
|---|---|---|
Index | int | The index of this choice in the array |
Message | *Message | The assistant's message response |
FinishReason | *string | Reason why the generation stopped. Possible values: "stop", "length", "tool_calls", "content_filter", or nil |
Example - Handling Multiple Choices:
response, err := client.Send("gpt-5.2", "Give me a creative idea.")
if err != nil {
log.Fatal(err)
}
// Process all choices
for _, choice := range response.Choices {
fmt.Printf("Choice %d: %s\n", choice.Index, choice.Message.Content)
if choice.FinishReason != nil {
fmt.Printf("Finish reason: %s\n", *choice.FinishReason)
}
}
Message Object (in Response)
The Message in each choice has:
| Property | Type | Description |
|---|---|---|
Role | string | The role of the message (typically "assistant") |
Content | string | The text content of the response. Empty when ToolCalls is present |
ToolCalls | []ToolCall | Array of tool calls requested by the model (if any). See Tools documentation for details |
Usage Object
Token usage information (when available):
| Property | Type | Description |
|---|---|---|
PromptTokens | int | Number of tokens in the prompt (after compression if applied) |
CompletionTokens | int | Number of tokens in the completion |
TotalTokens | int | Total tokens used (prompt + completion) |
Example - Accessing Token Usage:
response, err := client.Send("gpt-5.2", "Explain quantum computing briefly.")
if err != nil {
log.Fatal(err)
}
if response.Usage != nil {
fmt.Printf("Prompt tokens: %d\n", response.Usage.PromptTokens)
fmt.Printf("Completion tokens: %d\n", response.Usage.CompletionTokens)
fmt.Printf("Total tokens: %d\n", response.Usage.TotalTokens)
}
Compression Object
Token compression metrics (when compression is applied):
| Property | Type | Description |
|---|---|---|
SavedTokens | int | Number of tokens saved by compression |
CostSavings | int | Estimated cost savings in micro-units (e.g. 27000 = $0.027) |
Reduction | float64 | Percentage reduction (e.g. 18 = 18%, may be fractional) |
TimeMs | int | Time taken for compression in milliseconds |
Example - Accessing Compression Metrics:
response, err := client.Send("gpt-5.2", edgee.InputObject{
Messages: messages, // a conversation that includes tool calls and their results
ToolResultTrimming: edgee.BoolPtr(true),
})
if err != nil {
log.Fatal(err)
}
if response.Compression != nil {
fmt.Printf("Saved tokens: %d\n", response.Compression.SavedTokens)
fmt.Printf("Reduction: %.1f%%\n", response.Compression.Reduction)
fmt.Printf("Cost savings: $%.3f\n", float64(response.Compression.CostSavings)/1000000)
fmt.Printf("Time: %d ms\n", response.Compression.TimeMs)
}
Convenience Methods
The SendResponse struct provides convenience methods for easier access:
| Method | Return Type | Description |
|---|---|---|
Text() | string | Shortcut to Choices[0].Message.Content |
MessageContent() | *Message | Shortcut to Choices[0].Message |
FinishReason() | string | Shortcut to *Choices[0].FinishReason (returns empty string if nil) |
ToolCalls() | []ToolCall | Shortcut to Choices[0].Message.ToolCalls |
Example - Using Convenience Methods:
response, err := client.Send("gpt-5.2", "Hello!")
if err != nil {
log.Fatal(err)
}
// Instead of: response.Choices[0].Message.Content
fmt.Println(response.Text())
// Instead of: response.Choices[0].Message
if msg := response.MessageContent(); msg != nil {
fmt.Printf("Role: %s\n", msg.Role)
}
// Instead of: *response.Choices[0].FinishReason
fmt.Println(response.FinishReason())
// Instead of: response.Choices[0].Message.ToolCalls
if toolCalls := response.ToolCalls(); len(toolCalls) > 0 {
fmt.Printf("Tool calls: %+v\n", toolCalls)
}
Error Handling
The Send() method return Go errors:
response, err := client.Send("gpt-5.2", "Hello!")
if err != nil {
// Handle errors
log.Fatalf("Request failed: %v", err)
}
Common Errors
- API errors:
fmt.Errorf("API error %d: %s", statusCode, message)- The API returned an error status - Network errors: Standard Go HTTP errors
- Invalid input:
fmt.Errorf("unsupported input type: %T", input)- Invalid request structure - JSON errors: Errors from JSON marshaling/unmarshaling