Skip to content

fix(usage): record exact embedding tokens - #2794

Closed
zierocode wants to merge 1 commit into
decolua:masterfrom
zierocode:codex/embedding-exact-usage
Closed

zierocode wants to merge 1 commit into
decolua:masterfrom
zierocode:codex/embedding-exact-usage

Conversation

@zierocode

Copy link
Copy Markdown
Contributor

Problem

Successful embedding responses already return provider usage to clients, but the local usage history does not record it. Embedding traffic is therefore absent from usage and cost accounting.

Fix

  • return normalized provider usage alongside the core success response
  • persist usage after a successful embedding request
  • accept only exact positive safe-integer totals where input equals total and completion is zero
  • reject estimated, malformed, zero, or internally inconsistent usage instead of fabricating counts
  • keep persistence non-blocking so a DB failure cannot fail a successful inference

Scope

This is provider-neutral embedding accounting. It does not change response bodies, provider routing, credentials, or the xAI/cache-cost work in #2453.

TDD evidence

RED on 79918c7830695bbca4a45c9fea4a42c3e9fd73d1:

records exact provider usage for successful embedding requests
Number of calls: 0

GREEN on 660552583fca0df6c51cbd23312b016ac5e05c32:

  • focused tests: 2 files, 47 tests passed
  • ESLint: passed on all changed files
  • production build: passed with isolated DATA_DIR

@decolua

decolua commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Thanks @zierocode for the contribution! Reviewed and merged into master. 🙏

@decolua decolua closed this Jul 23, 2026
@zierocode
zierocode deleted the codex/embedding-exact-usage branch September 29, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants