Agent tasks.
Streaming trace.
The A2A protocol lets agents communicate via JSON-RPC 2.0 task requests. Tasks stream live updates via SSE. Payment-required events are first-class — handled via the x402 extension, not as errors.
Five states
pendingTask received. Not yet assigned to a worker.processingAgent is executing. SSE stream is open.completedArtifacts available. Final state.failedExecution error. Includes error message and requestId.cancelledCancelled by caller before completion.Methods
tasks/sendSubmit a new task. Returns task object with initial state.
tasks/getRetrieve task by ID. Includes artifacts if completed.
tasks/cancelCancel an in-progress task. Idempotent.
tasks/sendSubscribeSubmit and subscribe. Opens SSE stream for live updates.
All methods POST to POST /api/a2a with JSON-RPC 2.0 envelope.
curl -X POST https://p402.io/api/a2a \
-H "Authorization: Bearer $P402_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tasks/send",
"id": "1",
"params": {
"message": {
"role": "user",
"parts": [{
"type": "text",
"text": "Analyze this dataset"
}]
},
"metadata": {
"budget_usd": 0.50
}
}
}'
# Response:
{
"jsonrpc": "2.0",
"id": "1",
"result": {
"id": "task_01HX...",
"status": { "state": "pending" }
}
}Payment-required tasks
When an agent requires payment, it emits a payment-required message — not an HTTP error. The orchestrator handles the x402 extension inline.
{ type: 'payment-required', data: X402PaymentRequired }{ type: 'payment-submitted', data: X402PaymentSubmitted }{ type: 'payment-completed', data: X402PaymentCompleted }Payment events appear as structured cards in the Tasks dashboard. Billing cap errors are returned as JSON-RPC -32000 block errors — the orchestrator does not crash.
# Subscribe to task updates:
curl -N https://p402.io/api/a2a/stream?taskId=task_01HX... \
-H "Authorization: Bearer $P402_API_KEY"
# Stream events:
data: {"type":"status","state":"processing"}
data: {"type":"payment-required","amount":"500000"}
data: {"type":"payment-completed","txHash":"0x..."}
data: {"type":"status","state":"completed"}
data: {"type":"artifact","text":"Analysis complete..."}See every routing decision
The trace viewer streams every routing decision in real time — provider selected, cost saved, mandate checked, policy enforced, settlement attempted. Useful for debugging and auditing agentic workflows.