feat(webhooks): return per-call usage breakdown with provider/model/cost (#1421)

feat(webhooks): per-call usage breakdown with provider/model/cost (#1421)
This commit is contained in:
thotam authored and GitHub committed 2026-07-10 22:56:05 +07:00
1 parent 6b738924d5
commit 0c1ededc92
18 files changed
+551 -59

No files matched your search

+53 -6
View File
@@ -264,13 +264,29 @@ Triggers an agent with an input prompt. Available in all editions.
"agent_id": "<uuid>",
"output": "Here are the metrics: ...",
"usage": {
"prompt_tokens": 150,
"completion_tokens": 200,
"total_tokens": 350,
"prompt_tokens": 250,
"completion_tokens": 220,
"total_tokens": 470,
"cache_read_input_tokens": 120,
"cache_creation_input_tokens": 30,
"prompt_tokens_include_cached_segments": true
},
"total_cost_usd": 0.0279,
"calls": [
{
"type": "llm_call", "name": "9router/cx/gpt-5.6 #1",
"provider": "9router", "model": "cx/gpt-5.6",
"prompt_tokens": 150, "completion_tokens": 200, "total_tokens": 350,
"cache_read_input_tokens": 120, "cache_creation_input_tokens": 30,
"prompt_tokens_include_cached_segments": true, "cost_usd": 0.0187
},
{
"type": "tool_call", "name": "read_image",
"provider": "9router", "model": "cx/gpt-5.5",
"prompt_tokens": 100, "completion_tokens": 20, "total_tokens": 120,
"cost_usd": 0.0092
}
],
"finish_reason": "stop"
}
```
@@ -279,6 +295,17 @@ Triggers an agent with an input prompt. Available in all editions.
> prompt caching was active (omitted otherwise). When
> `prompt_tokens_include_cached_segments` is `true`, `prompt_tokens` already counts
> the cached segments, so non-cached input = `prompt_tokens - cache_read_input_tokens`.
>
> `calls[]` lists every LLM call and every tool that makes a **direct** internal LLM
> call (e.g. `read_image`, `read_video`), each attributed to its `provider`/`model`
> with its own tokens and `cost_usd`. `usage` is the **sum of all calls** — so it
> includes tool-internal LLM tokens — and `total_cost_usd` is the sum of
> `calls[].cost_usd` (best-effort; `0` when a model has no configured pricing).
>
> Note: token spend inside **nested agent runs** (`subagent`/`delegate` tools, which
> spawn a separate child agent loop) is **not** itemized in `calls[]` and not included
> in `usage`/`total_cost_usd` — consistent with how the child run's usage has always
> been excluded from the parent's totals.
Sync mode times out after the configured deadline (default **600s**). On timeout: `504 Gateway Timeout` with `webhook.llm_timeout`.
@@ -434,18 +461,38 @@ User-Agent: goclaw-webhook/1
"status": "done",
"output": "Agent response text...",
"usage": {
"prompt_tokens": 150,
"completion_tokens": 200,
"total_tokens": 350,
"prompt_tokens": 250,
"completion_tokens": 220,
"total_tokens": 470,
"cache_read_input_tokens": 120,
"cache_creation_input_tokens": 30,
"prompt_tokens_include_cached_segments": true
},
"total_cost_usd": 0.0279,
"calls": [
{
"type": "llm_call", "name": "9router/cx/gpt-5.6 #1",
"provider": "9router", "model": "cx/gpt-5.6",
"prompt_tokens": 150, "completion_tokens": 200, "total_tokens": 350,
"cache_read_input_tokens": 120, "cache_creation_input_tokens": 30,
"prompt_tokens_include_cached_segments": true, "cost_usd": 0.0187
},
{
"type": "tool_call", "name": "read_image",
"provider": "9router", "model": "cx/gpt-5.5",
"prompt_tokens": 100, "completion_tokens": 20, "total_tokens": 120,
"cost_usd": 0.0092
}
],
"metadata": {},
"error": ""
}
```
> `calls[]` and `total_cost_usd` on the async callback follow the same semantics as
> the sync response above: `usage` is the sum of all `calls[]` (including
> tool-internal LLM calls), each call carries its own `provider`/`model`/tokens/`cost_usd`.
`status` is `"done"` on success, `"failed"` on agent error. `error` is non-empty on failure.
### Retry Schedule