Send() method is used to make chat completion requests to the Edgee AI Gateway.
Arguments
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:
Example with InputObject:
Map Input
You can also use amap[string]interface{} for dynamic input:
Message Object
Each message in theMessages array has the following structure:
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
Choice Object
Each choice in theChoices array contains:
Example - Handling Multiple Choices:
Message Object (in Response)
TheMessage in each choice has:
Usage Object
Token usage information (when available):
Example - Accessing Token Usage:
Compression Object
Token compression metrics (when compression is applied):
Example - Accessing Compression Metrics:
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:
Example - Using Convenience Methods:
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