-
Notifications
You must be signed in to change notification settings - Fork 1.4k
add examples to use the gateway aside from the shorthand #3484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
09a04ee
8d8d8fe
f2a0687
0b4cb93
21ebce0
e74f5e6
b70b486
103da1a
9659237
1974ce0
2d15d5e
4a493d4
4a3e103
ef40b87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -119,18 +119,63 @@ export PYDANTIC_AI_GATEWAY_API_KEY="YOUR_PYDANTIC_AI_GATEWAY_API_KEY" | |||||
|
|
||||||
| You can access multiple models with the same API key, as shown in the code snippet below. | ||||||
|
|
||||||
| ```python {title="hello_world.py"} | ||||||
| from pydantic_ai import Agent | ||||||
| === "Hello World" | ||||||
|
|
||||||
| agent = Agent('gateway/openai:gpt-5') | ||||||
| ```python {title="hello_world.py"} | ||||||
| from pydantic_ai import Agent | ||||||
|
|
||||||
| 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. | ||||||
| """ | ||||||
| ``` | ||||||
| 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. | ||||||
| """ | ||||||
| ``` | ||||||
|
|
||||||
| === "Passing API Key directly" | ||||||
|
|
||||||
| Pass your API key directly using the provider: | ||||||
|
|
||||||
| ```python {title="passing_api_key.py"} | ||||||
| from pydantic_ai import Agent | ||||||
| from pydantic_ai.models.openai import OpenAIChatModel | ||||||
| from pydantic_ai.providers.gateway import gateway_provider | ||||||
|
|
||||||
| provider = gateway_provider('openai', api_key='PYDANTIC_AI_GATEWAY_API_KEY') | ||||||
|
||||||
| provider = gateway_provider('openai', api_key='PYDANTIC_AI_GATEWAY_API_KEY') | |
| provider = gateway_provider('openai', api_key='paig_<example_key>') |
or similar. (If it needs to match elsewhere, we can change it elsewhere?)
The current value from this example is the exact name of the environment variable that is used, which imo has just a little bit of potential for confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might make sense to make use of the route parameter too as that's a particularly relevant one; if you do, I'd use route='builtin-openai' or similar — those should always work.
(route='builtin-openai' means to use specifically the builtin openai provider, even if you've added your own OpenAI provider to the builtin routing group (which will have fallback.).)
I'm okay leaving that out for now, up to you.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmontagu Can you review the terminology here please? I don't think route and upstream provider are interchangeable like this
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same suggestion here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should link to the API docs for this function, so people can read the docstrings etc