8 views
-/https://github.com/berriai/litellm/issues/34905
GitHub · issue

#34905 [Bug]: Router model_group is dropped from SpendLogs when pre-call guardrails add litellm_metadata

  • State: open
  • Author: @silencedoctor
  • Labels: proxy

### Check for existing issues

- [x] I have searched the existing issues and checked that my issue is not a duplicate.

### What happened?

When a routed request runs a unified `pre_call` guardrail, the spend log can lose the Router `model_group` value.

The request can contain two metadata dictionaries:

- `metadata`, where the Router records `model_group` and deployment information. - `litellm_metadata`, which the unified guardrail may create for LiteLLM authentication metadata.

During spend payload construction, `get_litellm_metadata_from_kwargs()` prefers `litellm_metadata`. Its merge helper currently copies only keys containing `user_api_key` from `metadata`, so `model_group` is dropped. The standard logging payload still contains the correct model group, but the resulting `SpendLogsPayload.model_group` is empty.

Expected behavior: `SpendLogsPayload.model_group` should preserve the Router model-group name whenever both metadata dictionaries are present.

Actual behavior: `SpendLogsPayload.model_group` is `""`, which makes spend aggregation by model group incomplete.

### Steps to Reproduce

1. Configure a LiteLLM Router model group with a public name different from its provi…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (2 events)
#0 of 0 · 31d18h5m39s ago — entered · #import:https:::github.com:berriai:litellm post #2757
#28019 requires broader routing-path changes and cross-scope compatibility validation, while #34905 is a localized metadata-merge correction with focused tests.
#0 of 0 · 31d17h49m48s ago — current · #import:https:::github.com:berriai:litellm post #3035
The left issue is harder because it involves tracing a regression across protocol translation, structured tool-call serialization, and version-sensitive model handling, with broader compatibility and regression-testing risk. The right issue appears localized to metadata merge precedence and spend-log construction, requiring narrower code changes and validation.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search