Skip to content

Commit 09a04ee

Browse files
committed
add examples to pass an api key and route through a non default provider
1 parent eae558b commit 09a04ee

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/gateway.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ 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+
3872
result = agent.run_sync('Where does "hello world" come from?')
3973
print(result.output)
4074
"""

0 commit comments

Comments
 (0)