Skip to content

💎 fix: Handle usage_metadata in Title Transaction for Gemini Models#12386

Merged
danny-avila merged 2 commits into
danny-avila:devfrom
kojinseok-del:main
Apr 15, 2026
Merged

💎 fix: Handle usage_metadata in Title Transaction for Gemini Models#12386
danny-avila merged 2 commits into
danny-avila:devfrom
kojinseok-del:main

Conversation

@kojinseok-del

@kojinseok-del kojinseok-del commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Summary

I fixed a bug where title generation token transactions were silently skipped for Gemini models because the collectedUsage mapping in titleConvo did not account for Gemini's usage_metadata response format.

  • Add an else if (item.usage_metadata) branch in the titleConvo method's collectedUsage mapping to extract input_tokens and output_tokens from Gemini's usage_metadata object.
  • Resolve an issue where Gemini models return token usage via usage_metadata instead of the usage or tokenUsage keys that the existing code handled, causing the token values to remain undefined and the title generation transaction to be silently dropped.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • Configure a Gemini model (e.g., gemini-2.0-flash) as the title generation model via titleModel or as the active agent model.
  • Send a message to trigger a conversation and title generation.
  • Verify that the title generation transaction is recorded in the database with correct input_tokens and output_tokens values (previously these would be undefined, causing the transaction to be skipped).
  • Confirm that non-Gemini models (OpenAI, Anthropic, etc.) continue to record title transactions correctly through the existing usage and tokenUsage branches.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings

@danny-avila
danny-avila changed the base branch from main to dev April 15, 2026 13:47
kojinseok-del and others added 2 commits April 15, 2026 09:49
Gemini models return token usage via `usage_metadata` instead of `usage`
or `tokenUsage`. The `collectedUsage` mapping in `titleConvo` only
handled the latter two, causing title generation transactions to be
silently skipped for Gemini. Adds an `else if (item.usage_metadata)`
branch to extract `input_tokens`/`output_tokens`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@danny-avila

Copy link
Copy Markdown
Owner

@codex review

@danny-avila danny-avila changed the title fix: handle usage_metadata in title transaction for Gemini models 💎 fix: Handle usage_metadata in Title Transaction for Gemini Models Apr 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila
danny-avila merged commit edd4c6d into danny-avila:dev Apr 15, 2026
11 checks passed
krgokul pushed a commit to syedhabib39/LibreChat that referenced this pull request Apr 20, 2026
…danny-avila#12386)

* fix: handle `usage_metadata` in title transaction for Gemini models

Gemini models return token usage via `usage_metadata` instead of `usage`
or `tokenUsage`. The `collectedUsage` mapping in `titleConvo` only
handled the latter two, causing title generation transactions to be
silently skipped for Gemini. Adds an `else if (item.usage_metadata)`
branch to extract `input_tokens`/`output_tokens`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: remove trailing whitespace in usage_metadata handler

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
krgokul pushed a commit to syedhabib39/LibreChat that referenced this pull request Apr 21, 2026
…danny-avila#12386)

* fix: handle `usage_metadata` in title transaction for Gemini models

Gemini models return token usage via `usage_metadata` instead of `usage`
or `tokenUsage`. The `collectedUsage` mapping in `titleConvo` only
handled the latter two, causing title generation transactions to be
silently skipped for Gemini. Adds an `else if (item.usage_metadata)`
branch to extract `input_tokens`/`output_tokens`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: remove trailing whitespace in usage_metadata handler

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
yidianyiko pushed a commit to yidianyiko/LibreChat that referenced this pull request May 6, 2026
…danny-avila#12386)

* fix: handle `usage_metadata` in title transaction for Gemini models

Gemini models return token usage via `usage_metadata` instead of `usage`
or `tokenUsage`. The `collectedUsage` mapping in `titleConvo` only
handled the latter two, causing title generation transactions to be
silently skipped for Gemini. Adds an `else if (item.usage_metadata)`
branch to extract `input_tokens`/`output_tokens`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: remove trailing whitespace in usage_metadata handler

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
(cherry picked from commit edd4c6d)
jcbartle pushed a commit to jcbartle/LibreChat that referenced this pull request May 11, 2026
…danny-avila#12386)

* fix: handle `usage_metadata` in title transaction for Gemini models

Gemini models return token usage via `usage_metadata` instead of `usage`
or `tokenUsage`. The `collectedUsage` mapping in `titleConvo` only
handled the latter two, causing title generation transactions to be
silently skipped for Gemini. Adds an `else if (item.usage_metadata)`
branch to extract `input_tokens`/`output_tokens`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: remove trailing whitespace in usage_metadata handler

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ThomasVuNguyen pushed a commit to ThomasVuNguyen/LibreChat that referenced this pull request Jul 15, 2026
…danny-avila#12386)

* fix: handle `usage_metadata` in title transaction for Gemini models

Gemini models return token usage via `usage_metadata` instead of `usage`
or `tokenUsage`. The `collectedUsage` mapping in `titleConvo` only
handled the latter two, causing title generation transactions to be
silently skipped for Gemini. Adds an `else if (item.usage_metadata)`
branch to extract `input_tokens`/`output_tokens`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: remove trailing whitespace in usage_metadata handler

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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