Pydantic AI
Pydantic AI is a Python agent framework designed to make it easy to build production grade applications with AI. This guide demonstrates how to integrate Vercel AI Gateway with Pydantic AI to access various AI models and providers.
First, create a new directory for your project and initialize it:
Install the required Pydantic AI packages along with the package:
Create a file with your Vercel AI Gateway API key:
If you're using the AI Gateway from within a Vercel deployment, you can also use the environment variable which will be automatically provided.
Create a new file called with the following code:
The following code:
- Defines a Pydantic model for structured output
- Uses the to route requests through the AI Gateway
- Handles the response data using Pydantic's type validation
Run your application using Python:
You should see structured city information for Tokyo, Paris, and New York displayed in your console.
Was this helpful?