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
| Parameter | Type | Description |
|---|---|---|
model | impl Into<String> | The model identifier to use (e.g., "gpt-4o") |
input | impl Into<Input> | The input for the completion. Can be a string (&str or String), Vec<Message>, or InputObject |
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:
| Property | Type | Description |
|---|---|---|
messages | Vec<Message> | Array of conversation messages |
tools | Option<Vec<Tool>> | Array of function tools available to the model |
tool_choice | Option<serde_json::Value> | Controls which tool (if any) the model should call. See Tools documentation for details |
Message Object
Each message in themessages array is created using Message constructors:
| Constructor | Description |
|---|---|
Message::system(content) | System instructions that set the behavior of the assistant |
Message::developer(content) | Instructions provided by the application developer, prioritized ahead of user messages |
Message::user(content) | Instructions provided by an end user |
Message::assistant(content) | Assistant responses (can include tool_calls) |
Message::tool(tool_call_id, content) | Results from tool/function calls |
| Property | Type | Description |
|---|---|---|
role | Role | The role of the message sender: Role::System, Role::Developer, Role::User, Role::Assistant, or Role::Tool |
content | Option<String> | The message content. Required for System, User, and Tool roles. Optional for Assistant when tool_calls is present |
tool_calls | Option<Vec<ToolCall>> | Array of tool calls made by the assistant. Only present in Assistant messages |
tool_call_id | Option<String> | ID of the tool call this message is responding to. Required for Tool role messages |
Return Value
Thesend() method returns a Result<SendResponse>. On success, it contains:
SendResponse Object
| Property | Type | Description |
|---|---|---|
id | String | Unique identifier for the completion |
object | String | Object type (typically "chat.completion") |
created | u64 | Unix timestamp of when the completion was created |
model | String | Model identifier used for the completion |
choices | Vec<Choice> | Array of completion choices (typically one) |
usage | Option<Usage> | Token usage information (if provided by the API) |
Choice Object
Each choice in thechoices array contains:
| Property | Type | Description |
|---|---|---|
index | u32 | The index of this choice in the array |
message | Message | The assistant’s message response |
finish_reason | Option<String> | Reason why the generation stopped. Possible values: "stop", "length", "tool_calls", "content_filter", or None |
Message Object (in Response)
Themessage in each choice has:
| Property | Type | Description |
|---|---|---|
role | Role | The role of the message (typically Role::Assistant) |
content | Option<String> | The text content of the response. None when tool_calls is present |
tool_calls | Option<Vec<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 |
|---|---|---|
prompt_tokens | u32 | Number of tokens in the prompt |
completion_tokens | u32 | Number of tokens in the completion |
total_tokens | u32 | Total tokens used (prompt + completion) |
Convenience Methods
TheSendResponse struct provides convenience methods for easier access:
| Method | Return Type | Description |
|---|---|---|
text() | Option<&str> | Shortcut to choices[0].message.content.as_deref() |
message() | Option<&Message> | Shortcut to choices[0].message |
finish_reason() | Option<&str> | Shortcut to choices[0].finish_reason.as_deref() |
tool_calls() | Option<&Vec<ToolCall>> | Shortcut to choices[0].message.tool_calls.as_ref() |
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