Skip to main content
Do this when your app runs AgentArea tasks on behalf of its own users and bills them for it. AgentArea reports what a task cost; deciding the price is yours.

Prerequisites

  • An API key or service client. Only those callers may set end_user_id, metadata and webhook on a task, and only they read end_user_id and metadata back. A browser session gets 403 setting them and null reading 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

1

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.
2

Receive the webhook

AgentArea POSTs one JSON body per terminal event, task.completed, task.failed or task.cancelled (other events: Bill a delegation when it happens):
Verify before trusting it: recompute HMAC-SHA256 with your secret over <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.
3

Or read the task

total_cost and total_tokens are written when a turn ends, so a running task reads the totals of its last finished turn.

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 in webhook.events:
The list replaces the default, so keep the three terminal types in it if you still want them. The types a webhook can take: 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:
Headers and signature are the same as for a terminal event; the signature covers this body. What to rely on:
  • Charge what a delegation cost on delegation.completed, where data.success and data.child_cost (USD the child task spent) are final.
  • Charge a delegation as a unit on delegation.started when the person pays for the work being started, whatever its outcome. It is sent before the child task exists and can be followed by delegation.failed instead.
  • 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.started has data.continued: true and the subtask’s data.child_task_id. Do not charge it as another unit.
  • At least once. event_id (also X-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. seq is 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_cost on the delegating task’s terminal event already includes its children. Do not add child_cost to it.

Verify

Start a task with a webhook pointing at a request bin, wait for the turn to end, and check one delivery arrived with X-AgentArea-Event: task.completed and a total_cost equal to GET …/tasks/{task_id}’s.

Troubleshooting

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).
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.
At-least-once: deduplicate on X-AgentArea-Delivery.

Stream task events

Read the same terminal events live

MCP tool call context

How end_user_id and metadata reach your tool servers
Last modified on December 2, 2026