Repository navigation
fix(groq): default service_tier when the reply omits it - #52431
Conversation
|
[AI] @greptileai review Generated by Claude Code |
[Medium impact] The change affects Groq chat responses that omit a service tier. The live QA requirement must be satisfied before merging. Findings
|
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
f7f11a6 to
9afe0fe
Compare
Handwritten 1-3 sentence description
[insert handwritten description here]
Details
TLDR
Problem this solves:
service_tierfail with AttributeError/v1/messagesreturns 500, Responses bridge failsHow it solves it:
service_tierwith aNonedefaultauto, as already intendedUser Flow
Before: a developer calling a Groq model gets an error whenever Groq leaves
service_tierout of its reply"model": "groq/llama-3.3-70b-versatile"service_tierfield'ModelResponse' object has no attribute 'service_tier', and the same call on POST https://litellm-domain/v1/messages returns 500After: the same request returns the completion
service_tierfield"service_tier": "auto", and POST https://litellm-domain/v1/messages returns 200 tooPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Live proxy proof
No Groq credentials exist in this environment, so the
groq/llama-3.3-70b-versatiledeployment points itsapi_baseat a local stub that speaks Groq's OpenAI compatible/openai/v1/chat/completionswire format and answers with a normal Groq style completion that leaves outservice_tier. A client then sends one chat completion through the live proxyBefore is
532df6ef85655e56d82e334e1ab071c5c7fc29e9(parent of the fix commit) and after is9afe0fe69706c9b5f02c56fb7479ce673c7b4004(branch tip ofnate_fix_groq_missing_service_tier). The same proxy command, config, Redis, and stub were used for bothProxy command, run from the repo root of each checkout (
run_proxy.sh)A dedicated Redis on 6402 (
redis-server --port 6402 --save '' --appendonly no) backsrouter_settingsandgeneral_settings.coordination_redis. The two workers were confirmed in each run by twoStarted server processlines, and no checkout printed that the workers flag is ignored with reload. The master key is a randomsk-value exported asLITELLM_MASTER_KEY(the proxy refuses the well knownsk-1234). The provider keys are placeholder strings since the deployments point at the local stubProxy config (one config shared by the three proofs)
Stub (stub.py, run as python stub.py 4251, prints every request it receives)
Client script (client.sh, run with LITELLM_MASTER_KEY exported)
Before
The client gets an error even though the stub answered 200 with content. The router retried twice, so the stub saw three identical requests
Stub received (before)
Proxy traceback (before)
After
The same request returns 200 with the stub's content and
service_tierreported asautoWorker PIDs and stub received (after)
Unit tests
Scope is one line in
GroqChatConfig.transform_response(litellm/llms/groq/chat/transformation.py), wheregetattr(model_response, "service_tier")now passesNoneas the default._map_groq_service_tieralready mapsNonetoauto, so a reply that carries a tier behaves exactly as before and only the reply without one changes, from an exception toauto. Every Groq chat path (chat completions, the/v1/messagesbridge and the Responses bridge) goes through this method, so one unit test throughlitellm.completioncovers the shared defect.The bug was found by the Dec 1 integration contract tests (draft PR #50853). The tests skipped with BUG for it are
tests/integration/providers/test_dec1_otherprov2_groq_wire.py::test_groq_service_tier_is_reported_in_the_openai_vocabulary[None-auto]and the other Groq cells that skip with_SERVICE_TIER_BUGor_GROQ_SERVICE_TIER_BUGintest_dec1_otherprov2_groq_wire.py,test_dec1_openai_compatible_chat_wire.py,test_dec1_openai_messages_bridge_wire.py,test_dec1_respapi2_carriers_wire.pyandtest_dec1_respapi2_chaining_owned_proxy.py.The new regression test
test_reply_without_service_tier_is_reported_as_automocks a Groq reply with noservice_tierand checks the response comes back withservice_tier == "auto"and its content intact. It failed before the fix withAPIConnectionError: GroqException - 'ModelResponse' object has no attribute 'service_tier'and passes at the tip.Type
Bug Fix
Final Attestation
Generated by Claude Code