send() method is used to make non-streaming chat completion requests to the Edgee AI Gateway. It returns a SendResponse object with the model’s response.
Arguments
Input Types
String Input
Wheninput is a string, it’s automatically converted to a user message:
InputObject or Dictionary
Wheninput is an InputObject or dictionary, you have full control over the conversation:
Example with Dictionary 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 includetool_calls)tool: Results from tool/function calls (requirestool_call_id)
Return Value
Thesend() method returns a SendResponse object when stream=False (default):
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 Properties
TheSendResponse class provides convenience properties for easier access:
Example - Using Convenience Properties:
Streaming with send()
You can usesend() with stream=True to get streaming responses. This returns a generator yielding StreamChunk objects:
Error Handling
Thesend() method can raise exceptions in several scenarios:
Common Errors
- API errors:
RuntimeError: API error {status}: {message}- The API returned an error status - Network errors: Standard HTTP errors from
urllib - Invalid input: Errors from invalid request structure