fix(usage): record OpenRouter image costs and token counts
Merged
SA
2d ago+275+275+012345678901234567890123456789-8-8-0123456789
Fixes #1382.
OpenRouter image generations were recorded as $0 with zero input/output tokens: core.ImageUsage dropped cost/cost_details and the Chat-style prompt_tokens/completion_tokens at decode.
core.ImageUsagenow decodes both usage namings (Images naming wins when both are present), keepsoutput_tokens_details, and collects unknown members intoRawUsage, which is passed through to the client like chat usage extras.- Image usage extraction merges
RawUsageintoRawData, so provider-reported costs (OpenRoutercost→cost_source: "openrouter_credits") apply to image endpoints as they do for chat. Without a cost, reported output tokens are priced atoutput_image_per_mtok.
Existing rows stored at $0 need POST /admin/usage/recalculate-pricing after deploy.
Summary by CodeRabbit
- New Features
- Image usage now accepts both image-style and chat-style token fields, including output-token details.
- Provider-supplied usage metadata and cost details are preserved for client responses. Exact per-request costs take precedence over catalog rates, and OpenRouter credit costs are identified when provided.
- Image output-token details are included in usage metadata.
- Bug Fixes
- Provider-reported image counts are no longer treated as generated image counts when calculating output costs.
- Documentation
- Clarified how provider costs, token field names, and cost details are handled for image requests.