send() method is used to make non-streaming chat completion requests to the Edgee AI Gateway. It returns a Promise<SendResponse> with the model’s response.
Arguments
Thesend() method accepts a single SendOptions object with the following properties:
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:
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 Promise<SendResponse> with the following structure:
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 getters for easier access:
Example - Using Convenience Properties:
Error Handling
Thesend() method can throw errors in several scenarios:
Common Errors
- API errors:
Error: API error {status}: {message}- The API returned an error status - Network errors: Standard fetch network errors
- Invalid input: Errors from invalid request structure