Skip to content
Open
34 changes: 34 additions & 0 deletions docs/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,40 @@ from pydantic_ai import Agent

agent = Agent('gateway/openai:gpt-5')

result = agent.run_sync('Where does "hello world" come from?')
print(result.output)
"""
The first known use of "hello, world" was in a 1974 textbook about the C programming language.
"""
```
```python {title="passing_api_key.py"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to the "Usage > Pydantic AI" section below, and make sure there's some text before each code sample explaining what it shows.

from pydantic_ai import Agent

from pydantic_ai import Agent
from pydantic_ai.providers.gateway import gateway_provider
from pydantic_ai.models.openai import OpenAIChatModel

provider = gateway_provider('openai', api_key='PYDANTIC_AI_GATEWAY_API_KEY')
model = OpenAIChatModel('gpt-5', provider=provider)
agent = Agent(model)

result = agent.run_sync('Where does "hello world" come from?')
print(result.output)
"""
The first known use of "hello, world" was in a 1974 textbook about the C programming language.
"""
```
```python {title="routing_via_provider.py"}
from pydantic_ai import Agent

from pydantic_ai import Agent
from pydantic_ai.providers.gateway import gateway_provider
from pydantic_ai.models.openai import OpenAIChatModel

provider = gateway_provider('openai', api_key='PYDANTIC_AI_GATEWAY_API_KEY')
model = OpenAIChatModel('gpt-5', provider=provider, route='modal-ai')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

route is an arg on gateway_provider not the model class, rightr?

agent = Agent(model)

result = agent.run_sync('Where does "hello world" come from?')
print(result.output)
"""
Expand Down
Loading