-
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?
Conversation
docs/gateway.md
Outdated
| 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') |
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.
route is an arg on gateway_provider not the model class, rightr?
docs/gateway.md
Outdated
| The first known use of "hello, world" was in a 1974 textbook about the C programming language. | ||
| """ | ||
| ``` | ||
| ```python {title="passing_api_key.py"} |
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.
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.
docs/gateway.md
Outdated
|
|
||
| === "Using a different upstream provider" | ||
|
|
||
| If you're using a different upstream provider, you can specify it in the route parameter: |
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
| ```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 |
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
docs/gateway.md
Outdated
| 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') |
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.
Minor, but I feel like it makes sense to make it more clear that this isn't the literal string you are supposed to enter
| 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.
docs/gateway.md
Outdated
|
|
||
| provider = gateway_provider( | ||
| 'openai', | ||
| api_key='PYDANTIC_AI_GATEWAY_API_KEY', |
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
currently the doc only shows how to instantiate an Agent using the shorthand, this PR adds an example for passing the api key and also one example to use a non-default upstream provider
This is the view from http://localhost:8000/api/providers/#pydantic-ai-gateway-provider i.e. https://ai.pydantic.dev/api/providers/#pydantic-ai-gateway-provider