litellm - 💡(How to fix) Fix Gemini: frequency_penalty listed as supported but rejected by API

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

import litellm

This claims frequency_penalty is supported:

params = litellm.get_supported_openai_params(model='gemini/gemini-2.5-flash') print('frequency_penalty' in params) # True

But this fails:

litellm.drop_params = True # has no effect since param is "supported" response = await litellm.acompletion( model="gemini/gemini-2.5-flash", messages=[{"role": "user", "content": "Hello"}], temperature=0, max_tokens=50, frequency_penalty=0.4, )

GeminiException BadRequestError - {"error": {"code": 400, "message": "Penalty is not enabled for models/gemini-2.5-flash"}}

Code Example

Penalty is not enabled for models/gemini-2.5-flash

---

import litellm

# This claims frequency_penalty is supported:
params = litellm.get_supported_openai_params(model='gemini/gemini-2.5-flash')
print('frequency_penalty' in params)  # True

# But this fails:
litellm.drop_params = True  # has no effect since param is "supported"
response = await litellm.acompletion(
    model="gemini/gemini-2.5-flash",
    messages=[{"role": "user", "content": "Hello"}],
    temperature=0,
    max_tokens=50,
    frequency_penalty=0.4,
)
# GeminiException BadRequestError - {"error": {"code": 400, "message": "Penalty is not enabled for models/gemini-2.5-flash"}}
RAW_BUFFERClick to expand / collapse

Bug Description

litellm.get_supported_openai_params(model='gemini/gemini-2.5-flash') includes frequency_penalty in the returned list, but when the parameter is actually passed, the Gemini API rejects it with a 400 error:

Penalty is not enabled for models/gemini-2.5-flash

This also means litellm.drop_params = True does not help — since litellm considers the param "supported" for Gemini, it maps it to the native Gemini API parameter rather than dropping it. The API then rejects it.

Reproduction

import litellm

# This claims frequency_penalty is supported:
params = litellm.get_supported_openai_params(model='gemini/gemini-2.5-flash')
print('frequency_penalty' in params)  # True

# But this fails:
litellm.drop_params = True  # has no effect since param is "supported"
response = await litellm.acompletion(
    model="gemini/gemini-2.5-flash",
    messages=[{"role": "user", "content": "Hello"}],
    temperature=0,
    max_tokens=50,
    frequency_penalty=0.4,
)
# GeminiException BadRequestError - {"error": {"code": 400, "message": "Penalty is not enabled for models/gemini-2.5-flash"}}

Expected Behavior

Either:

  1. get_supported_openai_params should not list frequency_penalty for Gemini models that don't support it, or
  2. drop_params=True should catch and handle the case where a provider's API rejects a parameter that litellm thought was supported

Environment

  • litellm version: 1.82.4
  • Model: gemini/gemini-2.5-flash (also likely affects other Gemini models)
  • OS: macOS

extent analysis

TL;DR

The litellm library incorrectly lists frequency_penalty as a supported parameter for the Gemini model, causing a 400 error when the parameter is passed to the Gemini API.

Guidance

  • Verify the supported parameters for the Gemini model using the Gemini API documentation to ensure accuracy.
  • Consider modifying the get_supported_openai_params function to exclude frequency_penalty for Gemini models that do not support it.
  • If using drop_params=True is not effective, try removing the frequency_penalty parameter from the request to the Gemini API.
  • Check if there are any updates or patches available for the litellm library that address this issue.

Example

# Example of removing frequency_penalty parameter
response = await litellm.acompletion(
    model="gemini/gemini-2.5-flash",
    messages=[{"role": "user", "content": "Hello"}],
    temperature=0,
    max_tokens=50,
    # Remove frequency_penalty parameter
)

Notes

The issue seems to be specific to the litellm library and its interaction with the Gemini API. The solution may require updates to the library or modifications to the code that uses it.

Recommendation

Apply workaround: Remove the frequency_penalty parameter from the request to the Gemini API, as shown in the example above, until a fix is available for the litellm library.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix Gemini: frequency_penalty listed as supported but rejected by API