Skip to content

Commit 6617a52

Browse files
committed
openai: fix tool_call param construction for SDK >=1.99; update KnownModelName with gpt-5-chat-latest (prefixed and bare)
1 parent 4dfd104 commit 6617a52

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

pydantic_ai_slim/pydantic_ai/models/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@
307307
'openai:gpt-5-2025-08-07',
308308
'openai:gpt-5-mini-2025-08-07',
309309
'openai:gpt-5-nano-2025-08-07',
310+
'openai:gpt-5-chat-latest',
311+
'gpt-5-chat-latest',
312+
'gpt-5',
313+
'gpt-5-mini',
314+
'gpt-5-nano',
315+
'gpt-5-2025-08-07',
316+
'gpt-5-mini-2025-08-07',
317+
'gpt-5-nano-2025-08-07',
318+
'gpt-5-chat-latest',
310319
'openai:o1',
311320
'openai:o1-2024-12-17',
312321
'openai:o1-mini',

pydantic_ai_slim/pydantic_ai/models/openai.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,13 @@ async def _map_messages(self, messages: list[ModelMessage]) -> list[chat.ChatCom
505505

506506
@staticmethod
507507
def _map_tool_call(t: ToolCallPart) -> chat.ChatCompletionMessageToolCallParam:
508-
return chat.ChatCompletionMessageToolCallParam(
509-
id=_guard_tool_call_id(t=t),
510-
type='function',
511-
function={'name': t.tool_name, 'arguments': t.args_as_json_str()},
512-
)
508+
# openai>=1.99 changed these Param classes to typing.Union aliases;
509+
# construct as a plain dict compatible with the union instead of instantiating.
510+
return {
511+
'id': _guard_tool_call_id(t=t),
512+
'type': 'function',
513+
'function': {'name': t.tool_name, 'arguments': t.args_as_json_str()},
514+
}
513515

514516
def _map_json_schema(self, o: OutputObjectDefinition) -> chat.completion_create_params.ResponseFormat:
515517
response_format_param: chat.completion_create_params.ResponseFormatJSONSchema = { # pyright: ignore[reportPrivateImportUsage]

0 commit comments

Comments
 (0)