You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/agents.md
+16Lines changed: 16 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,14 @@ The [`Agent`][pydantic_ai.Agent] class has full API documentation, but conceptua
18
18
19
19
In typing terms, agents are generic in their dependency and output types, e.g., an agent which required dependencies of type `#!python Foobar` and produced outputs of type `#!python list[str]` would have type `Agent[Foobar, list[str]]`. In practice, you shouldn't need to care about this, it should just mean your IDE can tell you when you have the right type, and if you choose to use [static type checking](#static-type-checking) it should work well with Pydantic AI.
20
20
21
+
!!! info "Code Examples with Gateway Support"
22
+
Throughout this documentation, code examples are provided in two variations using tabs:
23
+
24
+
- **Pydantic AI Gateway**: Shows how to use examples with the [Pydantic AI Gateway](https://gateway.pydantic.dev/), which provides a unified interface to access multiple LLM models with additional features like failover, budget control, and Logfire observability.
25
+
- **Pydantic AI**: Shows the direct implementation using Pydantic AI with provider-specific model strings.
26
+
27
+
Both approaches are functionally equivalent for basic usage. Choose the Gateway tab if you're using Pydantic AI Gateway, or the Pydantic AI tab for direct provider integration.
28
+
21
29
Here's a toy example of an agent that simulates a roulette wheel:
22
30
23
31
=== "Pydantic AI Gateway"
@@ -109,6 +117,14 @@ There are five ways to run an agent:
109
117
4.[`agent.run_stream_events()`][pydantic_ai.agent.AbstractAgent.run_stream_events] — a function which returns an async iterable of [`AgentStreamEvent`s][pydantic_ai.messages.AgentStreamEvent] and a [`AgentRunResultEvent`][pydantic_ai.run.AgentRunResultEvent] containing the final run result.
110
118
5.[`agent.iter()`][pydantic_ai.Agent.iter] — a context manager which returns an [`AgentRun`][pydantic_ai.agent.AgentRun], an async iterable over the nodes of the agent's underlying [`Graph`][pydantic_graph.graph.Graph].
111
119
120
+
!!! note "Model String Formats"
121
+
Examples in this documentation show two model string formats:
122
+
123
+
- **Gateway format**: `gateway/chat:gpt-5` or `gateway/anthropic:claude-sonnet-4-5`
124
+
- **Direct format**: `openai:gpt-5` or `anthropic:claude-sonnet-4-5`
125
+
126
+
Use the Gateway format if you're routing requests through Pydantic AI Gateway.
127
+
112
128
Here's a simple example demonstrating the first four:
Copy file name to clipboardExpand all lines: docs/gateway/overview.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,12 @@ Sign up at [gateway.pydantic.dev](https://gateway.pydantic.dev/).
9
9
10
10
For questions and feedback, contact us on [Slack](https://logfire.pydantic.dev/docs/join-slack/).
11
11
12
+
## Documentation Integration
13
+
14
+
To help you get started with [Pydantic AI Gateway](https://gateway.pydantic.dev), most code examples throughout the Pydantic AI docs include a "Pydantic AI Gateway" tab alongside the standard "Pydantic AI" tab. This allows you to see how to adapt examples for Gateway usage by simply switching tabs.
15
+
16
+
The main difference is that when using Gateway, model strings use the `gateway/` prefix.
17
+
12
18
## Key features
13
19
-**API key management**: access multiple LLM providers with a single Gateway key.
14
20
-**Cost Limits**: set spending limits at project, user, and API key levels with daily, weekly, and monthly caps.
Copy file name to clipboardExpand all lines: docs/install.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,12 @@ pip/uv-add pydantic-ai
11
11
This installs the `pydantic_ai` package, core dependencies, and libraries required to use all the models included in Pydantic AI.
12
12
If you want to install only those dependencies required to use a specific model, you can install the ["slim"](#slim-install) version of Pydantic AI.
13
13
14
+
### Gateway Integration
15
+
16
+
If you're using Pydantic AI Gateway, you'll see "Pydantic AI Gateway" tabs in code examples throughout the documentation. These show how to adapt examples to use the Gateway's unified model interface.
17
+
18
+
See the [Gateway documentation](gateway/usage.md) for setup instructions.
19
+
14
20
## Use with Pydantic Logfire
15
21
16
22
Pydantic AI has an excellent (but completely optional) integration with [Pydantic Logfire](https://pydantic.dev/logfire) to help you view and understand agent runs.
0 commit comments