Skip to content

Commit 8d8d8fe

Browse files
committed
move examples to usage
1 parent 09a04ee commit 8d8d8fe

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

docs/gateway.md

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,6 @@ from pydantic_ai import Agent
3535

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

38-
result = agent.run_sync('Where does "hello world" come from?')
39-
print(result.output)
40-
"""
41-
The first known use of "hello, world" was in a 1974 textbook about the C programming language.
42-
"""
43-
```
44-
```python {title="passing_api_key.py"}
45-
from pydantic_ai import Agent
46-
47-
from pydantic_ai import Agent
48-
from pydantic_ai.providers.gateway import gateway_provider
49-
from pydantic_ai.models.openai import OpenAIChatModel
50-
51-
provider = gateway_provider('openai', api_key='PYDANTIC_AI_GATEWAY_API_KEY')
52-
model = OpenAIChatModel('gpt-5', provider=provider)
53-
agent = Agent(model)
54-
55-
result = agent.run_sync('Where does "hello world" come from?')
56-
print(result.output)
57-
"""
58-
The first known use of "hello, world" was in a 1974 textbook about the C programming language.
59-
"""
60-
```
61-
```python {title="routing_via_provider.py"}
62-
from pydantic_ai import Agent
63-
64-
from pydantic_ai import Agent
65-
from pydantic_ai.providers.gateway import gateway_provider
66-
from pydantic_ai.models.openai import OpenAIChatModel
67-
68-
provider = gateway_provider('openai', api_key='PYDANTIC_AI_GATEWAY_API_KEY')
69-
model = OpenAIChatModel('gpt-5', provider=provider, route='modal-ai')
70-
agent = Agent(model)
71-
7238
result = agent.run_sync('Where does "hello world" come from?')
7339
print(result.output)
7440
"""
@@ -164,7 +130,49 @@ print(result.output)
164130
The first known use of "hello, world" was in a 1974 textbook about the C programming language.
165131
"""
166132
```
133+
=== "Passing API Key Directly"
134+
135+
Pass your API key directly using the provider:
136+
137+
```python {title="passing_api_key.py"}
138+
from pydantic_ai import Agent
139+
140+
from pydantic_ai import Agent
141+
from pydantic_ai.providers.gateway import gateway_provider
142+
from pydantic_ai.models.openai import OpenAIChatModel
143+
144+
provider = gateway_provider('openai', api_key='PYDANTIC_AI_GATEWAY_API_KEY')
145+
model = OpenAIChatModel('gpt-5', provider=provider)
146+
agent = Agent(model)
167147

148+
result = agent.run_sync('Where does "hello world" come from?')
149+
print(result.output)
150+
"""
151+
The first known use of "hello, world" was in a 1974 textbook about the C programming language.
152+
"""
153+
```
154+
155+
=== "Using a different upstream provider"
156+
157+
If you're using a different upstream provider, you can specify it in the route parameter:
158+
159+
```python {title="routing_via_provider.py"}
160+
from pydantic_ai import Agent
161+
162+
from pydantic_ai import Agent
163+
from pydantic_ai.providers.gateway import gateway_provider
164+
from pydantic_ai.models.openai import OpenAIChatModel
165+
166+
provider = gateway_provider('openai', api_key='PYDANTIC_AI_GATEWAY_API_KEY', route='modal-ai')
167+
model = OpenAIChatModel('gpt-5', provider=provider)
168+
agent = Agent(model)
169+
170+
result = agent.run_sync('Where does "hello world" come from?')
171+
print(result.output)
172+
"""
173+
The first known use of "hello, world" was in a 1974 textbook about the C programming language.
174+
"""
175+
```
168176

169177
### Claude Code
170178

0 commit comments

Comments
 (0)