# Browser automation with Pydantic AI + Playwright

DevFeed: [Browser automation with Pydantic AI + Playwright](<https://devfeed.tech/articles/browser-automation-with-pydantic-ai-playwright-21751.md>)

Original publisher: [Read original article](<http://blog.pamelafox.org/2026/08/browser-automation-with-pydantic-ai.html>)

Author: Pamela Fox (noreply@blogger.com)

Published: 2026-08-20T21:57:18Z

Content type: tutorial

Language: en

Sources: [Pamela Fox](<https://devfeed.tech/sources/pamela-fox.md>)

Topics: [Playwright](<https://devfeed.tech/topics/playwright.md>), [Pydantic](<https://devfeed.tech/topics/pydantic.md>), [Browser Automation](<https://devfeed.tech/topics/browser-automation.md>), [Artificial Intelligence](<https://devfeed.tech/topics/ai.md>), [Azure OpenAI](<https://devfeed.tech/topics/azure-openai.md>), [Entra ID](<https://devfeed.tech/topics/entra-id.md>), [Authentication](<https://devfeed.tech/topics/authentication.md>), [OAuth 2.0](<https://devfeed.tech/topics/oauth2.md>), [OpenTelemetry](<https://devfeed.tech/topics/opentelemetry.md>)

Tags: [agents](<https://devfeed.tech/tags/agents.md>), [ai](<https://devfeed.tech/tags/ai.md>), [api-keys](<https://devfeed.tech/tags/api-keys.md>), [authentication](<https://devfeed.tech/tags/authentication.md>), [automation](<https://devfeed.tech/tags/automation.md>), [azure-openai](<https://devfeed.tech/tags/azure-openai.md>), [browser](<https://devfeed.tech/tags/browser.md>), [microsoft](<https://devfeed.tech/tags/microsoft.md>), [microsoft-foundry](<https://devfeed.tech/tags/microsoft-foundry.md>), [openai](<https://devfeed.tech/tags/openai.md>), [playwright](<https://devfeed.tech/tags/playwright.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

This tutorial explains how to combine Pydantic AI with Playwright to build agents that browse websites programmatically. It covers connecting Pydantic AI to Microsoft Foundry models through an OpenAI-compatible endpoint, using Entra token-based authentication, and applying Playwright for browsing, manual QA, and design iteration.

## Source excerpt

When we build agents, we often want to give them the ability to browse the web: open webpages, navigate from one page to the other, and read the content of a webpage. By combining Pydantic AI with the Playwright capability from Pydantic AI Harness, we can build agents that browse the web safely and programmatically. Using Pydantic AI with Microsoft Foundry models Pydantic AI is an open-source model-agnostic framework from Pydantic for building LLM-based applications and agents. It's type-safe and supports OpenTelemetry, making it a great choice for robust production applications. We can use Pydantic-AI with Microsoft Foundry models using either API keys or Entra token-based authentication. When possible, we always recommend the keyless route, so that's what we'll demonstrate here. We use the azure-identity package to authenticate with Entra, using either local or managed identity, and get back a token provider callback function for that credential: from azure.identity.aio import AzureDeveloperCliCredential, get_bearer_token_provider credential = AzureDeveloperCliCredential() token_provider = get_bearer_token_provider(credential, "https://cognitiveservices.azure.com/.default") Then we use the OpenAI package to configure the model connection: from openai import AsyncOpenAI client = AsyncOpenAI( base_url=os.environ["AZURE_OPENAI_ENDPOINT"] + "/openai/v1", api_key=token_provider, ) model = OpenAIChatModel( model_name=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"], provider=OpenAIProvider(openai_client=client), ) Let's explain the options used above: base_url: We point this at the OpenAI-compatible endpoint for our Foundry model. This endpoint works for Azure OpenAI models (like gpt-5.4, which this project deploys), and for cross-provider Foundry models that support the OpenAI v1 API, like Kimi-K2.7-Code. The base URL looks like "https://AZURE_OPENAI_SERVICE_NAME.openai.azure.com/openai/v1". api_key: We pass in the token provider callback function that generates OAuth2 token