Skip to content

PydanticSerializationError when running LiteLlm based agent via adk web or api_server #6164

@claud42

Description

@claud42

🔴 Required Information

Describe the Bug:
When developing agent by LiteLlm, the adk web or adk api_server command raise an exception due to LiteLlm having a client field in type of LiteLLMClient that can't be deserialized to be part of FastAPI's response.

Steps to Reproduce:

  1. Install adk
  2. Develop an agent by LiteLlm (see minimal reproducible code at the end)
  3. Run $ adk web --port 8000
  4. Open http://127.0.0.1:8000
  5. Error and stacktrace:
INFO:     127.0.0.1:57588 - "GET /dev/apps/my_agent/build_graph HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
<... skipped many lines> 
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'google.adk.models.lite_llm.LiteLLMClient'>

Expected Behavior:
No 500 error for the HTTP request.
No error message in adk web or adk api_server stdout/stderr.

Observed Behavior:
500 error in HTTP request.
Error message showed as in above.

Environment Details:

  • ADK Library Version (pip show google-adk): Version: 2.2.0
  • Desktop OS: macOS
  • Python Version (python -V): 3.14.4

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used: google/gemma-4-26B-A4B-it

🟡 Optional Information

Additional Context:
Root cause:
LiteLlm.llm_client is a declared Pydantic field but its class LiteLLMClient has no JSON serializer. Any JSON serialization of a LiteLlm instance raises the error, e.g., when using FastAPI.

By contrast, Gemini exposes its api_client as a @cached_property, not a field, so it is never part of the serialized output.

A fix is obvious and trivial.

Minimal Reproduction Code:

model = LiteLlm(
    model="...",
    api_base="...",
)

root_agent = Agent(
    model=model,
    name='root_agent',
    description='A helpful assistant for user questions.',
    instruction='Answer user questions to the best of your knowledge',
)

How often has this issue occurred?:

  • Always (100%)

Metadata

Metadata

Assignees

Labels

models[Component] Issues related to model support

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions