Send a user message, cancel the current turn, or return a function call result to a session.
Endpoint
POST /agents/sessions/{session_id}/events
Returns 202 Accepted with an empty body. The response may include an x-request-id header.
A 202 means the input was durably accepted and delivery was scheduled. It does not mean the model has consumed the input or the turn has completed. Use SSE, the turn terminal status, and item history to determine the result.
Request parameters
| Field | Required | Type | Description |
|---|---|---|---|
session_id | Yes | string | Session ID, for example sess_xxx |
events | Yes | array<object> | Event array. An empty array [] is an empty batch and produces no input |
events[].type | Yes | string | Event type: agent.session.input.message, agent.session.input.cancel, or agent.session.input.tool_result |
events[].input | Conditional | array<object> | User message array for a message event; cannot be empty |
events[].input[].role | Conditional | string | Message role, fixed as user |
events[].input[].content | Conditional | array | Content part array; cannot be empty |
events[].input[].content[].type | Conditional | string | Content part type; input_text or input_image |
events[].input[].content[].text | Conditional | string | Text content |
events[].input[].content[].image_url | Conditional | string | Image URL |
events[].turn_id | Conditional | string | tool_result event: public turn ID from required_actions |
events[].call_id | Conditional | string | tool_result event: function call ID |
events[].success | Conditional | boolean | tool_result event: whether the call succeeded |
events[].output | Conditional | string or array / null | tool_result event: function output; a string, or an array of input_text / input_image |
events[].error | Conditional | string / null | tool_result event: failure message |
events[] supports the following type values:
agent.session.input.message: Send a user message.inputis a non-empty array of user messages.agent.session.input.cancel: Cancel the current execution. Onlytype; does not acceptturn_id.agent.session.input.tool_result: Return a function call result. Carriesturn_id,call_id,success,outputorerror.
input field for message is an array, not the string shorthand used when creating a session. cancel cancels only the current turn. Fields from other branches and unknown fields are rejected.
Function calling
After the model initiates a function call, the session's required_actions contains a pending item:
arguments is already parsed into an object; do not parse it again as a JSON string. After a client restart, retrieve the session and read required_actions before continuing.
Idempotency
You can send an Idempotency-Key header:
- The key must be 1–256 characters. An empty or oversized key returns
400. - Retrying with the same session, key, and content reuses the acceptance result and does not deliver the input again.
- The same key with different content returns
409 conflict_error. - A batch containing only
cancelis the current-cancel exception: retrying with the same key still applies to the current turn at that time. - Without the header, the API does not provide request-level automatic deduplication.
- A batch containing only messages is merged into one user input in array order. A mixed batch is processed item by item; a semantic failure in a later item does not roll back items already accepted.
Request example
Response example
202 Accepted with no response body. Acceptance does not mean the model has consumed the tool result or the turn has completed.
Error codes
| HTTP status | Error type / code | Solution |
|---|---|---|
400 | invalid_request_error / invalid_request_error | Fix the request structure and event content; use a non-empty Idempotency-Key of 1-256 characters |
404 | not_found_error / not_found_error | Use a session ID that exists and has not been deleted in the current workspace |
409 | conflict_error / conflict_error | Confirm the current resource state; reuse the same request content for the same Idempotency-Key |
503 | server_error / agents_api_upstream_unavailable | Retry later. If it keeps failing, submit a ticket with x-request-id |