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:
| Property | Type | Description |
|---|---|---|
model | string | The model identifier to use (e.g., "openai/gpt-4o") |
input | string | InputObject | The input for the completion. Can be a simple string or a structured InputObject |
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:
| Property | Type | Description |
|---|---|---|
messages | Message[] | Array of conversation messages |
tools | Tool[] | Array of function tools available to the model |
tool_choice | ToolChoice | Controls which tool (if any) the model should call. See Tools documentation for details |
Message Object
Each message in themessages array has the following structure:
| Property | Type | Description |
|---|---|---|
role | string | The role of the message sender: "system", "developer", "user", "assistant", or "tool" |
content | string | The message content. Required for system, user, tool and developer roles. Optional for assistant when tool_calls is present |
name | string | Optional name for the message sender |
tool_calls | ToolCall[] | Array of tool calls made by the assistant. Only present in assistant messages |
tool_call_id | string | ID of the tool call this message is responding to. Required for tool role messages |
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
| Property | Type | Description |
|---|---|---|
choices | Choice[] | Array of completion choices (typically one) |
usage | Usage | undefined | Token usage information (if provided by the API) |
Choice Object
Each choice in thechoices array contains:
| Property | Type | Description |
|---|---|---|
index | number | The index of this choice in the array |
message | Message | The assistant’s message response |
finish_reason | string | null | Reason why the generation stopped. Possible values: "stop", "length", "tool_calls", "content_filter", or null |
Message Object (in Response)
Themessage in each choice has:
| Property | Type | Description |
|---|---|---|
role | string | The role of the message (typically "assistant") |
content | string | null | The text content of the response. null when tool_calls is present |
tool_calls | ToolCall[] | undefined | 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 | number | Number of tokens in the prompt |
completion_tokens | number | Number of tokens in the completion |
total_tokens | number | Total tokens used (prompt + completion) |
Convenience Properties
TheSendResponse class provides convenience getters for easier access:
| Property | Type | Description |
|---|---|---|
text | string | null | Shortcut to choices[0].message.content |
message | Message | null | Shortcut to choices[0].message |
finishReason | string | null | Shortcut to choices[0].finish_reason |
toolCalls | ToolCall[] | null | Shortcut to choices[0].message.tool_calls |
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