Skip to main content
The 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

The send() method accepts multiple input types through the Into<Input> trait:

String Input

When input 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

When input is an InputObject, you have full control over the conversation: Example with InputObject:
Example with Tags:

Message Object

Each message in the messages array is created using Message constructors: Message Structure: Example - System and User Messages:
For complete tool calling examples and best practices, see Tools documentation.

Return Value

The send() method returns a Result<SendResponse>. On success, it contains:

SendResponse Object

Choice Object

Each choice in the choices array contains: Example - Handling Multiple Choices:

Message Object (in Response)

The message 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

The SendResponse struct provides convenience methods for easier access: Example - Using Convenience Methods:

Error Handling

The send() 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