Prerequisites
- An API key or service client. Only those callers may set
end_user_id,metadataandwebhookon a task, and only they readend_user_idandmetadataback. A browser session gets 403 setting them andnullreading them. - For the webhook: an HTTPS endpoint the deployment’s outbound policy lets the worker reach, and a secret of 32 to 512 characters.
The numbers
A task that takes follow-ups ends every turn with
task.completed
(data.execution_status: "waiting"), and each turn’s total_cost and
tokens_used are the running totals of the task. Charge the difference
from the last value you processed for that task.
execution_status says what the run does after the event: waiting (it takes
a follow-up), completed (it ended), or settling on task.cancelled (it is
still recording the call the cancel interrupted; a later delivery does not
follow, and total_cost can still grow by that call’s cost on the task read).
Steps
Tag the task with your end user and ask for a webhook
webhook.secret is write-only: it goes to the secret manager and is never
returned. Without it deliveries are unsigned.Receive the webhook
AgentArea POSTs one JSON body per terminal event, Verify before trusting it: recompute HMAC-SHA256 with your secret over
task.completed,
task.failed or task.cancelled (other events:
Bill a delegation when it happens):<t>.<raw body>, compare with v1 in constant time, and reject a t more
than five minutes old. Deduplicate on X-AgentArea-Delivery (the event id):
a delivery that got a 5xx, a 429 or no answer is retried, a 4xx is not.Bill a delegation when it happens
Do this when a charge depends on something inside the turn, such as the agent delegating to another agent, and must not wait for the turn to end or depend on your app reading the task’s event stream at that moment. Name the event types inwebhook.events:
Any other type, a live-only one like
llm.call.chunk, an empty list or a type
listed twice is refused with 422 at webhook.events.
A terminal event keeps the body shown above. Every other type arrives in one
envelope, with under data the event’s stored data, the fields the task’s
event feed carries for it:
- Charge what a delegation cost on
delegation.completed, wheredata.successanddata.child_cost(USD the child task spent) are final. - Charge a delegation as a unit on
delegation.startedwhen the person pays for the work being started, whatever its outcome. It is sent before the child task exists and can be followed bydelegation.failedinstead. - A continued subtask is not a new one. A delegating agent may go on with a
subtask it started earlier (its answer to the subtask’s question, a
correction): that
delegation.startedhasdata.continued: trueand the subtask’sdata.child_task_id. Do not charge it as another unit. - At least once.
event_id(alsoX-AgentArea-Delivery) is the same on every retry and replay of an event: make the charge idempotent on it. - No order. An event whose delivery failed is retried while later ones go
out.
seqis the event’s position in the task’s feed; sort by it when order matters. - Retries. A 5xx, a 429 or no answer is retried, up to 20 attempts over several hours; then the delivery is set aside until an operator replays it. A 4xx is set aside at once.
- Events are sent on the task they happen in. Delegation events belong to the delegating task, so its webhook receives them. A delegated child task does not inherit the webhook: nothing is posted for the child’s own events.
total_coston the delegating task’s terminal event already includes its children. Do not addchild_costto it.
Verify
Start a task with a webhook pointing at a request bin, wait for the turn to end, and check one delivery arrived withX-AgentArea-Event: task.completed
and a total_cost equal to GET …/tasks/{task_id}’s.
Troubleshooting
The task is created with 422 webhook.url
The task is created with 422 webhook.url
The URL is not http(s), or it resolves to an address the deployment’s
outbound policy refuses (private and metadata addresses, unless the
operator allows them).
No delivery arrives
No delivery arrives
Deliveries go through the worker’s channel delivery stream, so the worker’s
channel delivery consumer must be running. A 4xx from your endpoint is not
retried.
Two deliveries for one turn
Two deliveries for one turn
At-least-once: deduplicate on
X-AgentArea-Delivery.Related
Stream task events
Read the same terminal events live
MCP tool call context
How end_user_id and metadata reach your tool servers