Skip to content

Commit b03d146

Browse files
committed
apply changes
1 parent 9d9e7ab commit b03d146

File tree

1 file changed

+52
-42
lines changed

1 file changed

+52
-42
lines changed

docs/gateway.md

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ status: new
55

66
# Pydantic AI Gateway
77

8-
**Pydantic AI Gateway** (PAIG) is a unified interface for accessing multiple AI providers with a single key. Features include built-in OpenTelemetry observability, real-time cost monitoring, failover management, and native integration with the Pydantic stack.
8+
**[Pydantic AI Gateway](https://pydantic.dev/gateway)** (PAIG) is a unified interface for accessing multiple AI providers with a single key. Features include built-in OpenTelemetry observability, real-time cost monitoring, failover management, and native integration with the other tools in the [Pydantic stack](https://pydantic.dev/).
99

1010
!!! note "Free while in Beta"
1111
The Pydantic AI Gateway is currently in Beta. You can bring your own key (BYOK) or buy inference through the Gateway (we will eat the card fee for now).
@@ -20,6 +20,7 @@ Sign up at [gateway.pydantic.dev](https://gateway.pydantic.dev/).
2020
To help you get started with [Pydantic AI Gateway](https://gateway.pydantic.dev), some code examples on the Pydantic AI documentation include a "Via Pydantic AI Gateway" tab, alongside a "Direct to Provider API" tab with the standard Pydantic AI model string. The main difference between them is that when using Gateway, model strings use the `gateway/` prefix.
2121

2222
## Key features
23+
2324
- **API key management**: access multiple LLM providers with a single Gateway key.
2425
- **Cost Limits**: set spending limits at project, user, and API key levels with daily, weekly, and monthly caps.
2526
- **BYOK and managed providers:** Bring your own API keys (BYOK) from LLM providers, or pay for inference directly through the platform.
@@ -32,7 +33,7 @@ To help you get started with [Pydantic AI Gateway](https://gateway.pydantic.dev)
3233
```python {title="hello_world.py"}
3334
from pydantic_ai import Agent
3435

35-
agent = Agent('gateway/chat:gpt-5')
36+
agent = Agent('gateway/openai:gpt-5')
3637

3738
result = agent.run_sync('Where does "hello world" come from?')
3839
print(result.output)
@@ -41,34 +42,42 @@ The first known use of "hello, world" was in a 1974 textbook about the C program
4142
"""
4243
```
4344
# Quick Start
45+
4446
This section contains instructions on how to set up your account and run your app with Pydantic AI Gateway credentials.
4547

4648
## Create an account
47-
Using your GitHub or Google account, sign in at https://gateway.pydantic.dev.
49+
50+
Using your GitHub or Google account, sign in at [gateway.pydantic.dev](https://gateway.pydantic.dev).
4851
Choose a name for your organization (or accept the default). You will automatically be assigned the Admin role.
4952

5053
A default project will be created for you. You can choose to use it, or create a new one on the [Projects](https://gateway.pydantic.dev/admin/projects) page.
5154

52-
## Add **Providers** by bringing your own API keys (BYOK)
53-
Pydantic AI Gateway allows you to bring your API keys from your favourite provider(s).
55+
## Add **Providers**
56+
There are two ways to use Providers in the Pydantic AI Gateway: you can bring your own key (BYOK) or buy inference through the platform.
57+
58+
### Bringing your own API key (BYOK)
5459

5560
On the [Providers](https://gateway.pydantic.dev/admin/providers) page, fill in the form to add a provider. Paste your API key into the form under Credentials, and make sure to **select the Project that will be associated to this provider**. It is possible to add multiple keys from the same provider.
5661

62+
### Use Built-in Providers
63+
On the top of the dashboard page, click in the 'Add billing details' button, and put in your credit card details to enable the built-in providers. This will allow you to buy inference through the available providers.
64+
5765
## Grant access to your team
5866
On the [Users](https://gateway.pydantic.dev/admin/users) page, create an invitation and share the URL with your team to allow them to access the project.
5967

60-
## Create gateway project keys
68+
## Create Gateway project keys
6169
On the Keys page, Admins can create project keys which are not affected by spending limits. Users can only create personal keys, that will inherit spending caps from both User and Project levels, whichever is more restrictive.
6270

6371
# Usage
6472
After setting up your account with the instructions above, you will be able to make an AI model request with the Pydantic AI Gateway.
6573
The code snippets below show how you can use PAIG with different frameworks and SDKs.
74+
You can add `gateway/` as prefix on every known provider that
6675

67-
To use different models, change the model string `gateway/<api_type>:<model_name>` to other models offered by the supported providers.
76+
To use different models, change the model string `gateway/<api_format>:<model_name>` to other models offered by the supported providers.
6877

6978
Examples of providers and models that can be used are:
7079

71-
| **Provider** | **API Type** | **Example Model** |
80+
| **Provider** | **API Format** | **Example Model** |
7281
| --- |-----------------|------------------------------------------|
7382
| OpenAI | `openai` | `gateway/openai:gpt-5` |
7483
| Anthropic | `anthropic` | `gateway/anthropic:claude-sonnet-4-5` |
@@ -77,7 +86,7 @@ Examples of providers and models that can be used are:
7786
| AWS Bedrock | `bedrock` | `gateway/bedrock:amazon.nova-micro-v1:0` |
7887

7988
## Pydantic AI
80-
Before you start, update to the latest version of `pydantic-ai`:
89+
Before you start, make sure you are on version 1.16 or later of `pydantic-ai`. To update to the latest version run:
8190

8291
=== "uv"
8392

@@ -91,7 +100,7 @@ Before you start, update to the latest version of `pydantic-ai`:
91100
pip install -U pydantic-ai
92101
```
93102

94-
Set the `PYDANTIC_AI_GATEWAY_API_KEY` environment variable to your gateway API key:
103+
Set the `PYDANTIC_AI_GATEWAY_API_KEY` environment variable to your Gateway API key:
95104

96105
```bash
97106
export PYDANTIC_AI_GATEWAY_API_KEY="YOUR_PAIG_TOKEN"
@@ -128,38 +137,39 @@ Launch Claude Code by typing `claude`. All requests will now route through the P
128137

129138
## SDKs
130139

131-
=== "OpenAI SDK"
140+
### OpenAI SDK
132141

133-
```python {title="openai_sdk.py" test="skip"}
134-
import openai
142+
```python {title="openai_sdk.py" test="skip"}
143+
import openai
135144

136-
client = openai.Client(
137-
base_url='https://gateway.pydantic.dev/proxy/chat/',
138-
api_key='paig_...',
139-
)
145+
client = openai.Client(
146+
base_url='https://gateway.pydantic.dev/proxy/chat/',
147+
api_key='paig_...',
148+
)
140149

141-
response = client.chat.completions.create(
142-
model='gpt-5',
143-
messages=[{'role': 'user', 'content': 'Hello world'}],
144-
)
145-
print(response.choices[0].message.content)
146-
#> Hello user
147-
```
148-
=== "Anthropic SDK"
149-
150-
```python {title="anthropic_sdk.py" test="skip"}
151-
import anthropic
152-
153-
client = anthropic.Anthropic(
154-
base_url='https://gateway.pydantic.dev/proxy/anthropic/',
155-
auth_token='paig_...',
156-
)
157-
158-
response = client.messages.create(
159-
max_tokens=1000,
160-
model='claude-sonnet-4-5',
161-
messages=[{'role': 'user', 'content': 'Hello world'}],
162-
)
163-
print(response.content[0].text)
164-
#> Hello user
165-
```
150+
response = client.chat.completions.create(
151+
model='gpt-5',
152+
messages=[{'role': 'user', 'content': 'Hello world'}],
153+
)
154+
print(response.choices[0].message.content)
155+
#> Hello user
156+
```
157+
158+
### Anthropic SDK
159+
160+
```python {title="anthropic_sdk.py" test="skip"}
161+
import anthropic
162+
163+
client = anthropic.Anthropic(
164+
base_url='https://gateway.pydantic.dev/proxy/anthropic/',
165+
auth_token='paig_...',
166+
)
167+
168+
response = client.messages.create(
169+
max_tokens=1000,
170+
model='claude-sonnet-4-5',
171+
messages=[{'role': 'user', 'content': 'Hello world'}],
172+
)
173+
print(response.content[0].text)
174+
#> Hello user
175+
```

0 commit comments

Comments
 (0)