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
| Parameter | Type | Description |
|---|---|---|
model | str | The model identifier to use (e.g., "gpt-5.2") |
input | str | InputObject | dict | The input for the completion. Can be a simple string or a structured InputObject or dictionary |
stream | bool | If True, returns a generator yielding StreamChunk objects. If False (default), returns a SendResponse object |
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:
| Property | Type | Description |
|---|---|---|
messages | list[dict] | Array of conversation messages |
tools | list[dict] | None | Array of function tools available to the model |
tool_choice | str | dict | None | Controls which tool (if any) the model should call. See Tools documentation for details |
tags | list[str] | None | 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 | str | 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 | str | The role of the message sender: "system", "developer", "user", "assistant", or "tool" |
content | str | None | The message content. Required for system, user, tool and developer roles. Optional for assistant when tool_calls is present |
name | str | None | Optional name for the message sender |
tool_calls | list[dict] | None | Array of tool calls made by the assistant. Only present in assistant messages |
tool_call_id | str | None | 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 SendResponse object when stream=False (default):
SendResponse Object
| Property | Type | Description |
|---|---|---|
choices | list[Choice] | Array of completion choices (typically one) |
usage | Usage | None | Token usage information (if provided by the API) |
compression | Compression | None | Token compression metrics (if compression was applied) |
Choice Object
Each choice in thechoices array contains:
| Property | Type | Description |
|---|---|---|
index | int | The index of this choice in the array |
message | dict | The assistant’s message response |
finish_reason | str | None | Reason why the generation stopped. Possible values: "stop", "length", "tool_calls", "content_filter", or None |
Message Object (in Response)
Themessage in each choice has:
| Property | Type | Description |
|---|---|---|
role | str | The role of the message (typically "assistant") |
content | str | None | The text content of the response. None when tool_calls is present |
tool_calls | list[dict] | None | 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 | int | Number of tokens in the prompt (after compression if applied) |
completion_tokens | int | Number of tokens in the completion |
total_tokens | int | Total tokens used (prompt + completion) |
Compression Object
Token compression metrics (when compression is applied):| Property | Type | Description |
|---|---|---|
saved_tokens | int | Number of tokens saved by compression |
cost_savings | int | Estimated cost savings in micro-units (e.g. 27000 = $0.027) |
reduction | int | Percentage reduction (e.g. 48 = 48%) |
time_ms | int | 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 properties for easier access:
| Property | Type | Description |
|---|---|---|
text | str | None | Shortcut to choices[0].message["content"] |
message | dict | None | Shortcut to choices[0].message |
finish_reason | str | None | Shortcut to choices[0].finish_reason |
tool_calls | list | None | Shortcut to choices[0].message.get("tool_calls") |
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