Add provider-specific usage details, fix streaming usage, and return
usage from all high-level APIs (Chat.Send, Generate[T], Agent.Run).
Breaking changes:
- Chat.Send/SendMessage/SendWithImages now return (string, *Usage, error)
- Generate[T]/GenerateWith[T] now return (T, *Usage, error)
- Agent.Run/RunMessages now return (string, *Usage, error)
New features:
- Usage.Details map for provider-specific token breakdowns
(reasoning, cached, audio, thoughts tokens)
- OpenAI streaming now captures usage via StreamOptions.IncludeUsage
- Google streaming now captures UsageMetadata from final chunk
- UsageTracker.Details() for accumulated detail totals
- ModelPricing and PricingRegistry for cost computation
Closes#2
Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.
Summary
Details map[string]inttoUsagefor provider-specific token breakdowns (reasoning, cached, audio, thoughts tokens)StreamOptions.IncludeUsageUsageMetadatafrom final chunk*UsagefromChat.Send*,Generate[T]/GenerateWith[T], andAgent.Run*(breaking signature changes)UsageTrackermiddleware to accumulate detail values withDetails()accessorModelPricingandPricingRegistryfor cost computation with cached token discountsBreaking Changes
Chat.Send(string, error)(string, *Usage, error)Chat.SendMessage(string, error)(string, *Usage, error)Chat.SendWithImages(string, error)(string, *Usage, error)Generate[T](T, error)(T, *Usage, error)GenerateWith[T](T, error)(T, *Usage, error)Agent.Run(string, error)(string, *Usage, error)Agent.RunMessages(string, error)(string, *Usage, error)Files Changed
v2/provider/provider.goDetailsmap + key constants toUsagev2/response.goDetailsmap,addUsagehelper, re-export constantsv2/llm.goDetailsinconvertProviderResponsev2/openai/openai.gov2/anthropic/anthropic.gov2/google/google.gov2/chat.go*UsagefromSend/SendMessage/SendWithImagesv2/generate.go*UsagefromGenerate[T]/GenerateWith[T]v2/agent/agent.go*UsagefromRun/RunMessages, updateAsToolv2/middleware.goUsageTrackerdetail accumulation +Details()accessorv2/pricing.goModelPricing,PricingRegistryTest Plan
go build ./...compilesgo test ./...— all tests passgo vet ./...— no issuesgolangci-lint run ./...— no new issuesUsageTrackerGenerate[T]returning usageAgent.Runreturning usagePricingRegistry.Cost()with cached token discountCloses #2
Also created steve/steveternet#47 for V1 audit.
🤖 Generated with Claude Code