-
Notifications
You must be signed in to change notification settings - Fork 1.6k
LiteLLM + Gemini 2.5 Pro: cached_tokens=None crashes Agents SDK with Pydantic int-validation error #758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm also getting this error:
|
I met a similar problem. import asyncio
import os
from agents import Agent, Runner
from agents.extensions.models.litellm_model import LitellmModel
gemini_api_key = os.getenv("GEMINI_API_KEY")
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
model=LitellmModel(
model="gemini/gemini-2.5-flash-preview-04-17",
api_key=gemini_api_key
)
)
async def main():
result = await Runner.run(agent, "write code for saying hi from LiteLLM")
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())
|
This might help! #760 (comment) |
Never mind I see you're on the latest version. Don't know what it could be. |
Oh wait I think #735 was just released in 0.0.17. Might be your issue? |
Uh oh!
There was an error while loading. Please reload this page.
Please read this first
cached_tokens=None
→ Pydantic error with LiteLLM + Gemini 2.5.Describe the bug
When
Runner.run()
executes an agent whose model is a Gemini 2.5-pro instance wrapped by LiteLLM, the pipeline dies during cost-calculation withThe log shows LiteLLM repeatedly inserting
cached_tokens=None
into the request metadata; Pydantic 2.11’sInputTokensDetails
model rejectsNone
because the field is typed asint
.The fallback code then silently downgrades the model to
o3-2025-04-16
, masking the issue in production.Debug information
v0.0.16
v1.71.1
gemini/gemini-2.5-pro-preview-05-06
Repro steps
Observed output
Commenting out the Gemini/LiteLLM model and falling back to any OpenAI model (
o3-2025-04-16
,gpt-4o
) makes the script succeed, confirming the issue is isolated to the Gemini + LiteLLM path.Expected behavior
0
) forcached_tokens
instead ofNone
, orNone
→0
before instantiatingInputTokensDetails
.Either fix would allow Gemini 2.5 to run without crashing and would eliminate silent model downgrades.
The text was updated successfully, but these errors were encountered: