Skip to content

fix(groq): register and correctly route compound systems - #32470

Closed
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
litellm_groq_compound_models
Closed

devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
litellm_groq_compound_models

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #32467

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • 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

I don't have a Groq API key in this environment, so I couldn't capture a real e2e run against api.groq.com. The exact commands to reproduce before/after are below; I'll add the captured output once a key is available

Before (on litellm_internal_staging), calling either compound system fails because LiteLLM strips the groq/ prefix and sends compound-mini, which Groq rejects

curl http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer sk-1234" \
  -d '{"model": "groq/compound-mini", "messages": [{"role": "user", "content": "what is the latest news about litellm"}]}'
# litellm.NotFoundError: GroqException - The model `compound-mini` does not exist or you do not have access to it.

After this change LiteLLM sends the full groq/compound-mini id (the actual Groq model id, see https://console.groq.com/docs/compound) and the two systems are registered in the model cost map so litellm.model_cost / get_model_info resolve them

curl http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer sk-1234" \
  -d '{"model": "groq/compound", "messages": [{"role": "user", "content": "what is the latest news about litellm"}]}'

Type

🐛 Bug Fix

Changes

Groq exposes its compound systems (groq/compound and groq/compound-mini) with the groq/ prefix as part of the actual model id. LiteLLM strips the provider prefix before building the request body, so it was sending compound / compound-mini, which Groq rejects with model_not_found. GroqChatConfig.transform_request now re-adds the prefix for these two ids only, leaving every other Groq model (e.g. llama-3.3-70b-versatile, openai/gpt-oss-120b) untouched

GROQ_COMPOUND_MODELS = frozenset({"compound", "compound-mini"})

# in GroqChatConfig
def _get_groq_model_name(model: str) -> str:
    return f"groq/{model}" if model in GROQ_COMPOUND_MODELS else model

Both systems are also added to model_prices_and_context_window.json and the backup map (context window 131072, max output 8192, chat mode). Groq bills compound as passthrough to the underlying models and server-side tools rather than a fixed per-token rate, so input_cost_per_token / output_cost_per_token are set to 0

Tests in tests/test_litellm/llms/groq/chat/test_transformation.py assert the registry entries exist with the right metadata and, as the core regression, that a completion for groq/compound(-mini) puts groq/compound(-mini) in the request body sent to Groq while a normal model like groq/llama-3.3-70b-versatile is unchanged

Link to Devin session: https://app.devin.ai/sessions/01226ae22f3d438a879200d39ae42875

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes Groq's compound system routing by re-prepending the groq/ provider prefix (which Groq requires as part of the actual model ID) before sending the request, and registers both compound models in the pricing JSON with zero-cost passthrough pricing.

  • GroqChatConfig.transform_request is overridden to call _get_groq_model_name, which re-adds the groq/ prefix for compound and compound-mini after LiteLLM has stripped it; all other Groq models are left unchanged.
  • groq/compound and groq/compound-mini are added to both the primary and backup cost map JSON files with 131k input tokens, 8192 output tokens, and zero per-token cost to reflect Groq's passthrough billing model.

Confidence Score: 3/5

The routing fix is directionally correct, but the implementation hardcodes model names against the team's explicit JSON-driven pattern, and the key regression test may not actually intercept the HTTP call it intends to verify.

The transformation logic is simple and the JSON entries look accurate. However, GROQ_COMPOUND_MODELS is a hardcoded frozenset that the team's rules require to live in the pricing JSON so new compound variants work without code changes. More critically, the integration test that is supposed to prove the core bug is fixed uses a pattern — passing an HTTPHandler as client= to litellm.completion and then checking mock_post.call_args — that other tests in this directory do not use and that may not intercept the actual outbound call. If the mock is never invoked, the assertion silently passes without verifying anything. The CI checkbox is unchecked, so these tests have not been confirmed green.

litellm/llms/groq/chat/transformation.py (hardcoded model set) and tests/test_litellm/llms/groq/chat/test_transformation.py (uncertain mock interception in the integration test)

Important Files Changed

Filename Overview
litellm/llms/groq/chat/transformation.py Adds GROQ_COMPOUND_MODELS frozenset and overrides transform_request to re-prepend groq/ for compound model IDs; violates the team rule requiring model-specific flags to live in the JSON cost map rather than be hardcoded in Python.
model_prices_and_context_window.json Adds entries for groq/compound and groq/compound-mini with 0-cost passthrough pricing, 131072 input and 8192 output tokens, and web-search support; looks correct.
litellm/model_prices_and_context_window_backup.json Mirror of the main JSON changes for the two compound Groq models; identical and consistent with the primary file.
tests/test_litellm/llms/groq/chat/test_transformation.py New test file covering model name mapping and JSON registry; the integration test that calls litellm.completion with a patched HTTPHandler instance may not intercept the actual HTTP call, leaving the core regression assertion untested.

Reviews (1): Last reviewed commit: "fix(groq): register and correctly route ..." | Re-trigger Greptile


from ...openai_like.chat.transformation import OpenAILikeChatConfig

GROQ_COMPOUND_MODELS = frozenset({"compound", "compound-mini"})

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.

P1 Hardcoded model list violates team rule on model-specific flags

GROQ_COMPOUND_MODELS is a hardcoded frozenset in the codebase. The team's explicit rule is to put model-specific flags in model_prices_and_context_window.json and read them via get_model_info, so that adding a new model (e.g. a future groq/compound-pro) works without a LiteLLM code update. The JSON entries for these models are already added in this PR, so a custom field like "requires_groq_prefix": true could be added there and checked via litellm.get_model_info(f"groq/{model}") in _get_groq_model_name. The current approach means any new Groq compound variant requires both a JSON entry and a code change to stay correct.

Rule Used: What: Do not hardcode model-specific flags in the ... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +57 to +92

Groq exposes the compound systems with the "groq/" prefix as part of the
actual model id, so LiteLLM must send "groq/compound(-mini)" instead of the
prefix-stripped "compound(-mini)", which Groq rejects with model_not_found.
"""
client = HTTPHandler()
fake_response = httpx.Response(
status_code=200,
json={
"id": "chatcmpl-1",
"object": "chat.completion",
"created": 1,
"model": expected_api_model,
"service_tier": "auto",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "hi"},
"finish_reason": "stop",
}
],
"usage": {"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2},
},
request=httpx.Request("POST", "https://api.groq.com/openai/v1/chat/completions"),
)

with patch.object(client, "post", return_value=fake_response) as mock_post:
litellm.completion(
model=requested_model,
messages=[{"role": "user", "content": "hi"}],
api_key="fake-key",
client=client,
)

sent_body = json.loads(mock_post.call_args.kwargs["data"])
assert sent_body["model"] == expected_api_model

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.

P1 Integration test pattern may not intercept the HTTP call as intended

litellm.completion(..., client=client) where client is an HTTPHandler may not forward that instance to the Groq handler's HTTP call. If litellm constructs its own HTTPHandler internally (as it does for most OpenAI-compatible providers), mock_post is never called, mock_post.call_args is None, and the final line raises AttributeError rather than asserting anything meaningful. Other transformation tests in this directory (e.g. Anthropic) call the config's transform_request method directly to inspect the serialized body, which is a more reliable and direct pattern. Verifying this test actually runs green in CI (the CI checkbox is unchecked in the PR) would confirm or dispel the concern.

@codecov

codecov Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 30 untouched benchmarks


Comparing litellm_groq_compound_models (7933266) with litellm_internal_staging (cd6e8cd)

Open in CodSpeed

@tin-berri

Copy link
Copy Markdown
Contributor

Closing as stale: no activity in the last 30 days. Feel free to reopen if this is still relevant.

@tin-berri tin-berri closed this Oct 3, 2026
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.

[Bug]: Groq Compound models (groq/compound and groq/compound-mini) are not recognized by LiteLLM

3 participants