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

The send() method accepts a single SendOptions object with the following properties:

Input Types

String Input

When input is a string, it’s automatically converted to a user message:

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 has the following structure:

Message Roles

  • system: System instructions that set the behavior of the assistant
  • developer: Instructions provided by the application developer, prioritized ahead of user messages.
  • user: Instructions provided by an end user.
  • assistant: Assistant responses (can include tool_calls)
  • tool: Results from tool/function calls (requires tool_call_id)
Example - System and User Messages:
For complete tool calling examples and best practices, see Tools documentation.

Return Value

The send() method returns a Promise<SendResponse> with the following structure:

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 Properties

The SendResponse class provides convenience getters for easier access: Example - Using Convenience Properties:

Error Handling

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