Skip to content

Commit 3dc31b2

Browse files
committed
mention PAIG and PAI code example options
1 parent ea2a720 commit 3dc31b2

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

docs/agents.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ The [`Agent`][pydantic_ai.Agent] class has full API documentation, but conceptua
1818

1919
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.
2020

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+
2129
Here's a toy example of an agent that simulates a roulette wheel:
2230

2331
=== "Pydantic AI Gateway"
@@ -109,6 +117,14 @@ There are five ways to run an agent:
109117
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.
110118
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].
111119

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+
112128
Here's a simple example demonstrating the first four:
113129

114130
=== "Pydantic AI Gateway"

docs/gateway/overview.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Sign up at [gateway.pydantic.dev](https://gateway.pydantic.dev/).
99

1010
For questions and feedback, contact us on [Slack](https://logfire.pydantic.dev/docs/join-slack/).
1111

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+
1218
## Key features
1319
- **API key management**: access multiple LLM providers with a single Gateway key.
1420
- **Cost Limits**: set spending limits at project, user, and API key levels with daily, weekly, and monthly caps.

docs/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ Realistically though, no list is going to be as convincing as [giving it a try](
6464

6565
## Hello World Example
6666

67+
!!! tip "Two Ways to Run Examples"
68+
All code examples in this documentation support both:
69+
70+
- **Direct usage** with provider-specific models (e.g., `openai:gpt-5`)
71+
- **Gateway usage** via Pydantic AI Gateway (e.g., `gateway/chat:gpt-5`)
72+
73+
Look for the tabs at the top of code examples to switch between implementations. [Learn more about the Gateway →](gateway/overview.md)
74+
6775
Here's a minimal example of Pydantic AI:
6876

6977
```python {title="hello_world.py"}

docs/install.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ pip/uv-add pydantic-ai
1111
This installs the `pydantic_ai` package, core dependencies, and libraries required to use all the models included in Pydantic AI.
1212
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.
1313

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+
1420
## Use with Pydantic Logfire
1521

1622
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

Comments
 (0)