Skip to content

refactor: expose public hidden_params accessors - #44668

Merged
mateo-berri merged 27 commits into
mainfrom
litellm_private_usage_hidden_params
Oct 7, 2026
Merged

mateo-berri merged 27 commits into
mainfrom
litellm_private_usage_hidden_params

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • 239 of 1,811 reportPrivateUsage hits come from reading response._hidden_params
  • That blocks driving the private-usage budget to zero

How it solves it:

  • Add a public hidden_params property on every response type that stores _hidden_params
  • Move the 242 flagged in-tree reads and writes to hidden_params
  • _hidden_params stays as storage, so existing user code keeps working
  • DecisionsResponse is frozen, so it gets a read-only property
  • Responses whose storage is a HiddenParams model are read and written through HiddenParamsModelView, which only exposes set fields and extras, and transfers between responses move the raw storage object like main did
  • Duck-typed objects that only carry _hidden_params go through small getattr/setattr helpers in litellm_core_utils/hidden_params.py
  • First of four PRs taking reportPrivateUsage to zero, the budget ratchet lowers the limit after merge

User Flow

Before: an SDK or proxy user reads response metadata through the underscore attribute

  1. They call litellm.completion(...) or POST http://localhost:4000/v1/chat/completions
  2. They read response._hidden_params["response_cost"], or the proxy returns x-litellm-response-cost and x-litellm-model-id headers

After: the same calls return the same data, and a public name is also available

  1. They make the same call
  2. response._hidden_params and the new response.hidden_params return the same dict, and the proxy headers are unchanged

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

Video of the live run is in the Slack thread https://berriaillm.slack.com/archives/C0B302ZJU05/p1791232426675779

Shared setup is two proxies on random free ports, one per worktree, with real OpenAI and Anthropic keys, no DB, and this config

model_list:
  - model_name: qa-chat
    litellm_params: {model: openai/gpt-4o-mini, api_key: os.environ/OPENAI_API_KEY}
  - model_name: qa-responses
    litellm_params: {model: openai/gpt-4o-mini, api_key: os.environ/OPENAI_API_KEY}
  - model_name: qa-anthropic
    litellm_params: {model: anthropic/claude-haiku-4-5-20251001, api_key: os.environ/ANTHROPIC_API_KEY}
  - model_name: qa-embeddings
    litellm_params: {model: openai/text-embedding-3-small, api_key: os.environ/OPENAI_API_KEY}
  - model_name: qa-fallback
    litellm_params: {model: openai/gpt-4o-mini, api_key: deliberately-invalid-qa-key}
router_settings:
  num_retries: 0
  fallbacks: [{qa-fallback: [qa-chat]}]
litellm_settings:
  cache: true
  cache_params: {type: local, ttl: 600}

Before (2156d6c)

  1. POST /v1/chat/completions qa-chat returns 200 with x-litellm-response-cost: 3e-06, x-litellm-model-id: qa-chat, x-litellm-model-api-base, and duration headers
  2. Same request with "stream": true streams to [DONE], final usage chunk shows 14 tokens and cost 3e-06
  3. POST /v1/responses qa-responses returns 200 with cost 5.1e-06 and the same metadata headers
  4. POST /v1/messages qa-anthropic returns 200 with cost 5.5e-05
  5. POST /v1/embeddings qa-embeddings returns 200 with cost 8e-08
  6. POST /v1/chat/completions qa-fallback returns 200 from qa-chat with x-litellm-attempted-fallbacks: 1
  7. The same chat request sent twice returns the same response id with x-litellm-cache-key on the hit
  8. SDK litellm.completion(...) gives response._hidden_params["response_cost"] == 3e-06, and response.hidden_params raises AttributeError
  9. SDK call through a registered CustomLLM in litellm.custom_provider_map that calls OpenAI and returns a plain user BaseModel with only _hidden_params keeps response_cost 0.0042 and both additional_headers

After (9061b14)

  1. Same, identical x-litellm-* values apart from call ids and durations
  2. Same, 14 tokens and cost 3e-06
  3. Same, cost 5.1e-06
  4. Same, cost 5.5e-05
  5. Same, cost 8e-08
  6. Same, x-litellm-attempted-fallbacks: 1
  7. Same cache key and reused response id
  8. Same private cost, and response.hidden_params is response._hidden_params is True for both reading and assigning
  9. Same, cost 0.0042 and both headers, the user model still has no public accessor

Type

🧹 Refactoring

Caveats (if any)

Low

  • A real mid-stream fallback was not reproduced live, covered by unit tests only
  • DB-backed spend logging was not exercised in the live run
  • Native /v1/completions metadata was not checked live because OpenAI now returns 404 for gpt-3.5-turbo-instruct, davinci-002 and babbage-002 on both commits, unit tests cover that path
  • ModelResponseBase keeps its shared class-level _hidden_params = {} default, unchanged here

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/32b275f5ec964f1f82cf6192e19a6237
Open in Devin Desktop: https://app.devin.ai/desktop/session/32b275f5ec964f1f82cf6192e19a6237?variant=devin
Requested by: @mateo-berri

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

devin-ai-integration Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Refactors internal hidden params access to use public accessors.

The PR appears safe to merge based on the changes since the previous review.

Summary

The PR exposes public hidden_params accessors while retaining _hidden_params as backing storage and migrates in-tree metadata access across response types, routing, caching, and proxy paths.

  • The changes since the previous review make the async and sync streaming wrappers copy metadata into plain dicts.
  • Both previous Greptile threads are resolved.

Reviews (13) · Last reviewed commit: "fix(router): copy streaming hidden param..." · Reviewed by Greptile

Comment thread litellm/router.py Outdated
@codspeed

codspeed Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_private_usage_hidden_params (913c0a9) with main (1cdc0ec)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (bce020f) during the generation of this report, so 1cdc0ec was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

mateo-berri and others added 2 commits October 5, 2026 23:00
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

mateo-berri and others added 3 commits October 6, 2026 00:08
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

Comment thread enterprise/litellm_enterprise/proxy/hooks/managed_files.py Fixed

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

mateo-berri and others added 3 commits October 6, 2026 02:17
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread litellm/litellm_core_utils/hidden_params.py Outdated
mateo-berri and others added 2 commits October 6, 2026 03:29
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread litellm/main.py
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai review

Comment thread litellm/responses/litellm_completion_transformation/transformation.py Outdated
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread litellm/litellm_core_utils/hidden_params.py Outdated
mateo-berri and others added 2 commits October 7, 2026 04:48
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai review

…_hidden_params

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	tests/unit/proxy/hooks/test_dynamic_rate_limiter.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai review

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai review

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 913c0a9. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mateo-berri
mateo-berri merged commit d364d5e into main Oct 7, 2026
114 of 115 checks passed
@mateo-berri
mateo-berri deleted the litellm_private_usage_hidden_params branch October 7, 2026 07:01
mateo-berri added a commit that referenced this pull request Oct 8, 2026
…table/1.104.x

The public hidden_params accessor comes from #44668, which is not on stable/1.104.x, so the backported test reads the private attribute like the rest of the file
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