-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issue
Description
Chat Completions compatible APIs should use the following finish_reason values
["stop", "length", "tool_calls", "content_filter", "function_call"]
However, OpenRouter does not use function_call
and introduces a new error
finish_reason. This causes pydantic ai to raise a validation error:
pydantic_ai.exceptions.UnexpectedModelBehavior: Invalid response from OpenAI chat completions endpoint: 1 validation error for ChatCompletion
choices.0.finish_reason
Input should be 'stop', 'length', 'tool_calls', 'content_filter' or 'function_call' [type=literal_error, input_value='error', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
OpenRouter docs: https://openrouter.ai/docs/api-reference/overview#finish-reason
See https://pydanticlogfire.slack.com/archives/C083V7PMHHA/p1757441718457539?thread_ts=1757428644.886389&cid=C083V7PMHHA for context.
Example Code
Replace model name with openrouter:google/gemini-2.5-flash-lite
in weather example
Python, Pydantic AI & LLM client version
python 3.13
pydantic-ai 1.0.2
amaizing-paraskevas
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working