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
TheSend() method accept multiple input types:
String Input
Wheninput is a string, it’s automatically converted to a user message:
InputObject
Wheninput 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) |
CompressionModel | *string | Compression model for this request: "claude", "codex", "opencode", "cursor". Each model is a bundle of compression strategies. Overrides API key settings when present. |
Map Input
You can also use amap[string]interface{} for dynamic input:
Message Object
Each message in theMessages 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)
Return Value
TheSend() 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 theChoices 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 |
Message Object (in Response)
TheMessage 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) |
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. 48 = 48%, may be fractional) |
TimeMs | int | Time taken for compression in milliseconds |
The
Compression object is only present when token compression is applied to the request. Simple queries may not trigger compression.Convenience Methods
TheSendResponse 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 |
Error Handling
TheSend() method return Go errors:
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