litellm/tests/unit/proxy/google_endpoints
ellisc42 c345f50f1c
fix(auth): enforce key budgets on Google generateContent calls that leave the model out of the URL (#53404)
* fix(auth): enforce key budgets on Google generateContent calls that leave the model out of the URL

The router serves POST /v1beta/models/:generateContent (and /models/:generateContent,
:streamGenerateContent) with the model taken from the body, because the path
convertor accepts an empty value. The auth gate's route matcher required at least
one character for the model, so these calls were not LLM routes and skipped the
key, team and proxy budget checks.

The model placeholder before a ":" suffix now matches zero or more non-colon
characters, the same values the router accepts.

* fix(auth): let a Google model name with a colon reach the budget check

* fix(auth): give an empty Google model URL its call type and check countTokens on the URL model

* fix(google): count an empty-model countTokens call with the body model it was checked on

With no model in the URL, countTokens checked model access on the body model but counted with an empty model. It now counts with the body model, like generateContent. Tests pin countTokens to the URL model over proxy-wide models and cover countTokens in the zero-budget route test.

* fix(google): keep countTokens unmetered with a colon model and let managed agents count the body model

The unbilled check split the last path segment at its first colon, so a colon model name like gemini-text:v1 made countTokens look metered once those routes counted as LLM routes. It now reads the verb after the last colon. A managed agent's countTokens with no model in the URL now resolves the body model, like the countTokens handler

* fix(auth): check a forced model on the empty Google model URL like the handler serves it

With completion_model or --model set, the empty /v1beta/models/:generateContent URL checked the body model while the handler served the forced model. The empty URL now resolves its model the same way as a named URL, through the handler's own precedence

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-22 22:04:46 +00:00
..
__init__.py
test_endpoints.py fix(auth): enforce key budgets on Google generateContent calls that leave the model out of the URL (#53404) 2026-11-22 22:04:46 +00:00
test_gemini_agents_endpoints.py fix(gemini)!: accept Google's current Managed Agents fields on create and interactions (#48750) 2026-10-28 12:37:59 -07:00
test_google_api_endpoints.py fix(proxy): answer x-litellm-call-id on every token count response (#51037) 2026-11-11 22:26:47 +00:00
test_google_endpoint_routing.py fix(proxy): return 4xx instead of 500 for missing required params, invalid pagination and unknown ids (#43787) 2026-10-02 22:48:53 -07:00
test_google_gemini_proxy_request.py
test_interactions_agent_param.py fix(gemini)!: accept Google's current Managed Agents fields on create and interactions (#48750) 2026-10-28 12:37:59 -07:00
test_managed_agents_model_param.py