You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(protocol): clarify usage/UsageTotals is a TanStack extension, not AG-UI
AG-UI's RUN_FINISHED only defines threadId/runId/result; finishReason and usage
are TanStack additions that ride along via AG-UI's passthrough schemas. Rename
the documented type TokenUsage → UsageTotals to match the exported type, correct
fields that don't exist on the breakdowns (cacheCreation/cacheRead,
accepted/rejectedPredictionTokens), and document cost/costDetails plus an
OpenRouter cost example.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
// Provider-reported cost, when available (e.g. OpenRouter)
133
+
cost?:number;
134
+
costDetails?: {
135
+
upstreamCost?:number; // Total cost the gateway paid upstream
136
+
upstreamInputCost?:number; // Upstream cost for input (prompt) tokens
137
+
upstreamOutputCost?:number; // Upstream cost for output (completion) tokens
138
+
};
126
139
}
127
140
```
128
141
@@ -200,11 +213,35 @@ interface TokenUsage {
200
213
}
201
214
```
202
215
216
+
**Example (OpenRouter with cost):**
217
+
```json
218
+
{
219
+
"type": "RUN_FINISHED",
220
+
"runId": "run_abc123",
221
+
"model": "openai/gpt-4o",
222
+
"timestamp": 1701234567892,
223
+
"finishReason": "stop",
224
+
"usage": {
225
+
"promptTokens": 150,
226
+
"completionTokens": 75,
227
+
"totalTokens": 225,
228
+
"cost": 0.0012,
229
+
"costDetails": {
230
+
"upstreamInputCost": 0.0008,
231
+
"upstreamOutputCost": 0.0004
232
+
}
233
+
}
234
+
}
235
+
```
236
+
203
237
**Token Usage Notes:**
238
+
-`usage` is a TanStack AI extension to the AG-UI `RUN_FINISHED` event; all fields beyond the three core counts are optional and provider-dependent.
204
239
-`promptTokensDetails.cachedTokens` - Tokens read from cache (OpenAI/Anthropic prompt caching)
205
240
-`promptTokensDetails.cacheWriteTokens` - Tokens written to cache (Anthropic prompt caching)
206
241
-`completionTokensDetails.reasoningTokens` - Internal reasoning tokens (o1, Claude thinking)
207
-
-`providerUsageDetails` - Provider-specific fields not in the standard schema
242
+
-`durationSeconds` - Set by duration-billed models (e.g. Whisper transcription) instead of token counts
243
+
-`providerUsageDetails` - Provider-specific fields not in the standard schema (e.g. OpenRouter's accepted/rejected prediction tokens, Anthropic's server tool use)
244
+
-`cost` / `costDetails` - Provider-reported per-request cost, populated only by gateways that return it (e.g. OpenRouter)
208
245
- For Gemini, modality-specific token counts (audio, video, image, text) are extracted from the response
0 commit comments