V2 callers cannot fully track token consumption across all API surfaces:
Streaming: OpenAI and Google streaming don't capture usage in the done event
Chat.Send(): Runs a tool-call loop but only returns string — usage from all iterations lost
Generate[T]: Returns only the typed result — usage lost
Agent.Run(): Delegates to Chat but doesn't expose usage
Provider-specific details: Anthropic cache tokens, OpenAI reasoning/cached tokens, Google thoughts tokens — all discarded
Cost tracking: No pricing/cost mechanism exists
Solution
Add Details map[string]int to Usage for provider-specific token breakdowns
Fix streaming usage for OpenAI and Google
Return *Usage from Chat.Send*, Generate[T], and Agent.Run*
Enhance UsageTracker middleware to accumulate details
Add ModelPricing / PricingRegistry utility for cost computation
## Problem
V2 callers cannot fully track token consumption across all API surfaces:
- **Streaming**: OpenAI and Google streaming don't capture usage in the done event
- **Chat.Send()**: Runs a tool-call loop but only returns `string` — usage from all iterations lost
- **Generate[T]**: Returns only the typed result — usage lost
- **Agent.Run()**: Delegates to Chat but doesn't expose usage
- **Provider-specific details**: Anthropic cache tokens, OpenAI reasoning/cached tokens, Google thoughts tokens — all discarded
- **Cost tracking**: No pricing/cost mechanism exists
## Solution
1. Add `Details map[string]int` to `Usage` for provider-specific token breakdowns
2. Fix streaming usage for OpenAI and Google
3. Return `*Usage` from `Chat.Send*`, `Generate[T]`, and `Agent.Run*`
4. Enhance `UsageTracker` middleware to accumulate details
5. Add `ModelPricing` / `PricingRegistry` utility for cost computation
Phase 4: Enhance UsageTracker middleware to accumulate detail values
Phase 5: Add ModelPricing/PricingRegistry in v2/pricing.go
Phase 6: Tests and verification
Starting work on this. Plan of approach:
1. **Phase 1**: Add `Details map[string]int` to `provider.Usage` and public `Usage`, extract provider-specific details from OpenAI/Anthropic/Google
2. **Phase 2**: Fix streaming usage for OpenAI (enable `StreamOptions.IncludeUsage`) and Google (capture `UsageMetadata` from last chunk)
3. **Phase 3**: Change signatures — `Chat.Send*`, `Generate[T]`, `Agent.Run*` now return `*Usage`
4. **Phase 4**: Enhance `UsageTracker` middleware to accumulate detail values
5. **Phase 5**: Add `ModelPricing`/`PricingRegistry` in `v2/pricing.go`
6. **Phase 6**: Tests and verification
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
V2 callers cannot fully track token consumption across all API surfaces:
string— usage from all iterations lostSolution
Details map[string]inttoUsagefor provider-specific token breakdowns*UsagefromChat.Send*,Generate[T], andAgent.Run*UsageTrackermiddleware to accumulate detailsModelPricing/PricingRegistryutility for cost computationStarting work on this. Plan of approach:
Details map[string]inttoprovider.Usageand publicUsage, extract provider-specific details from OpenAI/Anthropic/GoogleStreamOptions.IncludeUsage) and Google (captureUsageMetadatafrom last chunk)Chat.Send*,Generate[T],Agent.Run*now return*UsageUsageTrackermiddleware to accumulate detail valuesModelPricing/PricingRegistryinv2/pricing.goWork finished. PR: #3
Also created steve/steveternet#47 for the V1 audit.