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/models/openai.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -394,9 +394,10 @@ agent = Agent(model)
394
394
395
395
### OpenRouter
396
396
397
-
To use [OpenRouter](https://openrouter.ai), first create an API key at [openrouter.ai/keys](https://openrouter.ai/keys).
397
+
[OpenRouter](https://openrouter.ai) now has dedicated support in PydanticAI with the [`OpenRouterModel`][pydantic_ai.models.openrouter.OpenRouterModel].
398
+
For detailed documentation and examples, see the [OpenRouter documentation](openrouter.md).
398
399
399
-
Once you have the API key, you can use it with the [`OpenRouterProvider`][pydantic_ai.providers.openrouter.OpenRouterProvider]:
400
+
You can also still use OpenRouter through the OpenAI-compatible interface:
To use `OpenRouterModel`, you need to either install `pydantic-ai`, or install `pydantic-ai-slim` with the `openrouter` optional group:
6
+
7
+
```bash
8
+
pip/uv-add "pydantic-ai-slim[openrouter]"
9
+
```
10
+
11
+
## Configuration
12
+
13
+
To use [OpenRouter](https://openrouter.ai/) through their API, go to [openrouter.ai/keys](https://openrouter.ai/keys) and follow your nose until you find the place to generate an API key.
14
+
15
+
`OpenRouterModelName` contains a list of available OpenRouter models.
16
+
17
+
## Environment variable
18
+
19
+
Once you have the API key, you can set it as an environment variable:
The model will validate and parse the response into your specified Pydantic model, allowing type-safe access to structured data fields via `result.output.field_name`.
0 commit comments