Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ agent = Agent(model)
...
```

### OpenAI Responses API

PydanticAI also supports OpenAI's [Responses API](https://platform.openai.com/docs/api-reference/responses) through the [`OpenAIResponsesModel`][pydantic_ai.models.openai.OpenAIResponsesModel] class.

The Responses API has built-in tools that you can use instead of building your own:
- [Web search](https://platform.openai.com/docs/guides/tools-web-search)
- [File search](https://platform.openai.com/docs/guides/tools-file-search)
- [Computer use](https://platform.openai.com/docs/guides/tools-computer-use)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a note saying this is not yet supported in PydanticAI, will be soon.

!!! warning "Work in progress"
We currently don't support the native OpenAI tools listed above in the `OpenAIResponsesModel` class.

You can learn more about the differences between the Responses API and Chat Completions API in the [OpenAI API docs](https://platform.openai.com/docs/guides/responses-vs-chat-completions).

```python {title="openai_responses_model.py"}
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIResponsesModel

model = OpenAIResponsesModel('gpt-4o')
agent = Agent(model)
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example should be complete, if minimal.

Copy link
Member Author

@Kludex Kludex Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... There are 4 examples above that are exactly the same as this one. 🤔

Should I update all of them? Did you see them?

```

## Anthropic

### Install
Expand Down
10 changes: 7 additions & 3 deletions pydantic_ai_slim/pydantic_ai/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from . import _utils, messages as _messages
from .exceptions import ModelRetry
from .result import ResultDataT, ResultDataT_inv, ResultValidatorFunc
from .tools import AgentDepsT, RunContext, ToolDefinition
from .tools import AgentDepsT, GenerateToolJsonSchema, RunContext, ToolDefinition

T = TypeVar('T')
"""An invariant TypeVar."""
Expand Down Expand Up @@ -159,7 +159,9 @@ def __init__(self, response_type: type[ResultDataT], name: str, description: str
self.type_adapter = TypeAdapter(response_type)
outer_typed_dict_key: str | None = None
# noinspection PyArgumentList
parameters_json_schema = _utils.check_object_json_schema(self.type_adapter.json_schema())
parameters_json_schema = _utils.check_object_json_schema(
self.type_adapter.json_schema(schema_generator=GenerateToolJsonSchema)
)
else:
response_data_typed_dict = TypedDict( # noqa: UP013
'response_data_typed_dict',
Expand All @@ -168,7 +170,9 @@ def __init__(self, response_type: type[ResultDataT], name: str, description: str
self.type_adapter = TypeAdapter(response_data_typed_dict)
outer_typed_dict_key = 'response'
# noinspection PyArgumentList
parameters_json_schema = _utils.check_object_json_schema(self.type_adapter.json_schema())
parameters_json_schema = _utils.check_object_json_schema(
self.type_adapter.json_schema(schema_generator=GenerateToolJsonSchema)
)
# including `response_data_typed_dict` as a title here doesn't add anything and could confuse the LLM
parameters_json_schema.pop('title')

Expand Down
Loading