send() method is used to make non-streaming chat completion requests to the Edgee AI Gateway. It returns a Result<SendResponse> with the model’s response.
Arguments
Input Types
Thesend() method accepts multiple input types through the Into<Input> trait:
String Input
Wheninput is a string (&str or String), it’s automatically converted to a user message:
Vec<Message>
You can pass a vector of messages directly:
InputObject
Wheninput is an InputObject, you have full control over the conversation:
Example with InputObject:
Message Object
Each message in themessages array is created using Message constructors:
Message Structure:
Example - System and User Messages:
Return Value
Thesend() method returns a Result<SendResponse>. On success, it 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 returns a Result<SendResponse>, which can contain various error types:
Common Errors
- API errors:
Error::Api { status, message }- The API returned an error status - HTTP errors:
Error::Http(reqwest::Error)- Network or HTTP errors - JSON errors:
Error::Json(serde_json::Error)- JSON serialization/deserialization errors - Missing API key:
Error::MissingApiKey- API key not provided