Skip to content

Commit 291fa1f

Browse files
committed
Merge branch 'main' into 3225
2 parents 7127de6 + 335555e commit 291fa1f

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

docs/.hooks/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
def on_page_markdown(markdown: str, page: Page, config: Config, files: Files) -> str:
1818
"""Called on each file after it is read and before it is converted to HTML."""
19-
relative_path_root = (DOCS_ROOT / page.file.src_uri).parent
20-
markdown = inject_snippets(markdown, relative_path_root)
19+
relative_path = DOCS_ROOT / page.file.src_uri
20+
markdown = inject_snippets(markdown, relative_path.parent)
2121
markdown = replace_uv_python_run(markdown)
2222
markdown = render_examples(markdown)
2323
markdown = render_video(markdown)
24-
markdown = create_gateway_toggle(markdown, relative_path_root)
24+
markdown = create_gateway_toggle(markdown, relative_path)
2525
return markdown
2626

2727

@@ -120,13 +120,13 @@ def sub_cf_video(m: re.Match[str]) -> str:
120120
"""
121121

122122

123-
def create_gateway_toggle(markdown: str, relative_path_root: Path) -> str:
123+
def create_gateway_toggle(markdown: str, relative_path: Path) -> str:
124124
"""Transform Python code blocks with Agent() calls to show both Pydantic AI and Gateway versions."""
125125
# Pattern matches Python code blocks with or without attributes, and optional annotation definitions after
126126
# Annotation definitions are numbered list items like "1. Some text" that follow the code block
127127
return re.sub(
128128
r'```py(?:thon)?(?: *\{?([^}\n]*)\}?)?\n(.*?)\n```(\n\n(?:\d+\..+?\n)+?\n)?',
129-
lambda m: transform_gateway_code_block(m, relative_path_root),
129+
lambda m: transform_gateway_code_block(m, relative_path),
130130
markdown,
131131
flags=re.MULTILINE | re.DOTALL,
132132
)
@@ -136,7 +136,7 @@ def create_gateway_toggle(markdown: str, relative_path_root: Path) -> str:
136136
GATEWAY_MODELS = ('anthropic', 'openai', 'openai-responses', 'openai-chat', 'bedrock', 'google-vertex', 'groq')
137137

138138

139-
def transform_gateway_code_block(m: re.Match[str], relative_path_root: Path) -> str:
139+
def transform_gateway_code_block(m: re.Match[str], relative_path: Path) -> str:
140140
"""Transform a single code block to show both versions if it contains Agent() calls."""
141141
attrs = m.group(1) or ''
142142
code = m.group(2)
@@ -186,9 +186,9 @@ def replace_agent_model(match: re.Match[str]) -> str:
186186

187187
# Build attributes string
188188
docs_path = DOCS_ROOT / 'gateway'
189-
relative_path = docs_path.relative_to(relative_path_root, walk_up=True)
190-
link = f"<a href='{relative_path}' style='float: right;'>Learn about Gateway</a>"
191189

190+
relative_path_to_gateway = docs_path.relative_to(relative_path, walk_up=True)
191+
link = f"<a href='{relative_path_to_gateway}' style='float: right;'>Learn about Gateway</a>"
192192
attrs_str = f' {{{attrs}}}' if attrs else ''
193193

194194
if 'title="' in attrs:

docs/gateway.md

Lines changed: 7 additions & 7 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](https://pydantic.dev/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 other tools in the [Pydantic stack](https://pydantic.dev/).
8+
**[Pydantic AI Gateway](https://pydantic.dev/ai-gateway)** 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).
@@ -26,8 +26,8 @@ To help you get started with [Pydantic AI Gateway](https://gateway.pydantic.dev)
2626
- **BYOK and managed providers:** Bring your own API keys (BYOK) from LLM providers, or pay for inference directly through the platform.
2727
- **Multi-provider support:** Access models from OpenAI, Anthropic, Google Vertex, Groq, and AWS Bedrock. _More providers coming soon_.
2828
- **Backend observability:** Log every request through [Pydantic Logfire](https://pydantic.dev/logfire) or any OpenTelemetry backend (_coming soon_).
29-
- **Zero translation**: Unlike traditional AI gateways that translate everything to one common schema, PAIG allows requests to flow through directly in each provider's native format. This gives you immediate access to the new model features as soon as they are released.
30-
- **Open source with self-hosting**: PAIG's core is [open source](https://github.com/pydantic/pydantic-ai-gateway/) (under [AGPL-3.0](https://www.gnu.org/licenses/agpl-3.0.en.html)), allowing self-hosting with file-based configuration, instead of using the managed service.
29+
- **Zero translation**: Unlike traditional AI gateways that translate everything to one common schema, **Pydantic AI Gateway** allows requests to flow through directly in each provider's native format. This gives you immediate access to the new model features as soon as they are released.
30+
- **Open source with self-hosting**: Pydantic AI Gateway core is [open source](https://github.com/pydantic/pydantic-ai-gateway/) (under [AGPL-3.0](https://www.gnu.org/licenses/agpl-3.0.en.html)), allowing self-hosting with file-based configuration, instead of using the managed service.
3131
- **Enterprise ready**: Includes SSO (with OIDC support), granular permissions, and flexible deployment options. Deploy to your Cloudflare account, or run on-premises with our [consulting support](https://pydantic.dev/contact).
3232

3333
```python {title="hello_world.py"}
@@ -80,7 +80,7 @@ Users can only create personal keys, that will inherit spending caps from both U
8080
## Usage
8181

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

8686
To use different models, change the model string `gateway/<api_format>:<model_name>` to other models offered by the supported providers.
@@ -114,7 +114,7 @@ Before you start, make sure you are on version 1.16 or later of `pydantic-ai`. T
114114
Set the `PYDANTIC_AI_GATEWAY_API_KEY` environment variable to your Gateway API key:
115115

116116
```bash
117-
export PYDANTIC_AI_GATEWAY_API_KEY="YOUR_PAIG_TOKEN"
117+
export PYDANTIC_AI_GATEWAY_API_KEY="YOUR_PYDANTIC_AI_GATEWAY_API_KEY"
118118
```
119119

120120
You can access multiple models with the same API key, as shown in the code snippet below.
@@ -140,10 +140,10 @@ Set your gateway credentials as environment variables:
140140

141141
```bash
142142
export ANTHROPIC_BASE_URL="https://gateway.pydantic.dev/proxy/anthropic"
143-
export ANTHROPIC_AUTH_TOKEN="YOUR_PAIG_TOKEN"
143+
export ANTHROPIC_AUTH_TOKEN="YOUR_PYDANTIC_AI_GATEWAY_API_KEY"
144144
```
145145

146-
Replace `YOUR_PAIG_TOKEN` with the API key from the Keys page.
146+
Replace `YOUR_PYDANTIC_AI_GATEWAY_API_KEY` with the API key from the Keys page.
147147

148148
Launch Claude Code by typing `claude`. All requests will now route through the Pydantic AI Gateway.
149149

pydantic_ai_slim/pydantic_ai/_output.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def __init__(
465465
self.processor = processor
466466

467467
def dump(self) -> JsonSchema:
468-
return self.object_def.json_schema # pyright: ignore[reportOptionalMemberAccess]
468+
return self.object_def.json_schema # pyright: ignore[reportOptionalMemberAccess]
469469

470470

471471
class NativeOutputSchema(StructuredTextOutputSchema[OutputDataT]):
@@ -541,7 +541,7 @@ def mode(self) -> OutputMode:
541541
return 'tool'
542542

543543
def dump(self) -> JsonSchema:
544-
toolset_processors = [self.toolset.processors[k] for k in self.toolset.processors] # pyright: ignore[reportOptionalMemberAccess]
544+
toolset_processors = [self.toolset.processors[k] for k in self.toolset.processors] # pyright: ignore[reportOptionalMemberAccess]
545545
processors_union = UnionOutputProcessor(toolset_processors)
546546
return processors_union.object_def.json_schema
547547

@@ -736,7 +736,7 @@ class UnionOutputProcessor(BaseObjectOutputProcessor[OutputDataT]):
736736

737737
def __init__(
738738
self,
739-
outputs: Sequence[OutputTypeOrFunction[OutputDataT]|ObjectOutputProcessor[OutputDataT]],
739+
outputs: Sequence[OutputTypeOrFunction[OutputDataT] | ObjectOutputProcessor[OutputDataT]],
740740
*,
741741
name: str | None = None,
742742
description: str | None = None,

pydantic_ai_slim/pydantic_ai/durable_exec/temporal/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def _workflow_runner(runner: WorkflowRunner | None) -> WorkflowRunner:
6767
'rich',
6868
'httpx',
6969
'anyio',
70+
'sniffio',
7071
'httpcore',
7172
# Used by fastmcp via py-key-value-aio
7273
'beartype',

pydantic_ai_slim/pydantic_ai/providers/gateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ def gateway_provider(
132132
environment variable will be used if available. Otherwise, defaults to `https://gateway.pydantic.dev/proxy`.
133133
http_client: The HTTP client to use for the Gateway.
134134
"""
135-
api_key = api_key or os.getenv('PYDANTIC_AI_GATEWAY_API_KEY')
135+
api_key = api_key or os.getenv('PYDANTIC_AI_GATEWAY_API_KEY', os.getenv('PAIG_API_KEY'))
136136
if not api_key:
137137
raise UserError(
138138
'Set the `PYDANTIC_AI_GATEWAY_API_KEY` environment variable or pass it via `gateway_provider(..., api_key=...)`'
139139
' to use the Pydantic AI Gateway provider.'
140140
)
141141

142-
base_url = base_url or os.getenv('PYDANTIC_AI_GATEWAY_BASE_URL', GATEWAY_BASE_URL)
142+
base_url = base_url or os.getenv('PYDANTIC_AI_GATEWAY_BASE_URL', os.getenv('PAIG_BASE_URL', GATEWAY_BASE_URL))
143143
http_client = http_client or cached_async_http_client(provider=f'gateway/{upstream_provider}')
144144
http_client.event_hooks = {'request': [_request_hook(api_key)]}
145145

0 commit comments

Comments
 (0)