Menu
Important
Stay updated on React2Shell

Pydantic AI

Last updated September 24, 2025

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.

  1. First, create a new directory for your project and initialize it:

  2. Install the required Pydantic AI packages along with the package:

  3. 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.

  4. 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
  5. Run your application using Python:

    You should see structured city information for Tokyo, Paris, and New York displayed in your console.


Was this helpful?

supported.