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-5.2") |
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 |
tags | string[] | Optional tags to categorize and label the request for analytics and filtering. Can also be sent via the x-edgee-tags header (comma-separated) |
compression_model | string | Compression model for this request: "claude", "codex", "opencode", "cursor". Each model is a bundle of compression strategies. Overrides API key settings when present. |
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) |
compression | Compression | undefined | Token compression metrics (if compression was applied) |
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 (after compression if applied) |
completion_tokens | number | Number of tokens in the completion |
total_tokens | number | Total tokens used (prompt + completion) |
Compression Object
Token compression metrics (when compression is applied):| Property | Type | Description |
|---|---|---|
saved_tokens | number | Number of tokens saved by compression |
cost_savings | number | Estimated cost savings in micro-units (e.g. 27000 = $0.027) |
reduction | number | Percentage reduction (e.g. 48 = 48%, may be fractional) |
time_ms | number | Time taken for compression in milliseconds |
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:
| 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