Skip to content

New Official SDKs for TypeScript, Python and Go

SerpKite
Get API key

Python · pydantic-ai

Pydantic AI + SerpKite

Register a typed SerpKite search function with @agent.tool_plain, or attach the SerpKite MCP server as a toolset. Pydantic AI validates the arguments; SerpKite returns Markdown.

Overview

What Pydantic AI is, and where SerpKite fits

Pydantic AI is a type-safe agent framework from the Pydantic team. Tools are ordinary functions registered with @agent.tool_plain (or @agent.tool when you need run context); argument types and docstrings become the tool schema.

Pair it with structured output: search with SerpKite, then have the agent return a validated Pydantic model.

Setup

Set it up in 4 steps

  1. 1

    Get an API key

    Sign up (no card), create a key in the dashboard and export it as SERPKITE_API_KEY. New accounts get 2,500 free credits, then 1,000 every month.

    export SERPKITE_API_KEY=skt_live_…
  2. 2

    Install

    Set your model provider's key too (the example uses OpenAI).

    pip install -U serpkite pydantic-ai
  3. 3

    Register the tool

    Decorate a function with @agent.tool_plain.

  4. 4

    Run with typed output

    output_type makes the agent return a validated model.

Code

Complete example

from serpkite import SerpKite, SerpKiteError

sk = SerpKite()  # reads SERPKITE_API_KEY


def serpkite_search(query: str, country: str = "us", num: int = 10) -> str:
    """Google search via SerpKite. Returns the results page as compact Markdown."""
    try:
        # format="markdown" returns a str: results, People Also Ask, related searches
        return sk.search(query, country=country, num=num, format="markdown")
    except SerpKiteError as e:
        return f"Search failed: {e.message}"


from pydantic import BaseModel
from pydantic_ai import Agent


class Answer(BaseModel):
    answer: str
    sources: list[str]


agent = Agent(
    "openai:gpt-5-mini",
    output_type=Answer,
    instructions="Search the web before answering. Put the URLs you used in sources.",
)


@agent.tool_plain
def google_search(query: str, country: str = "us") -> str:
    """Search Google for current information. Returns the top results with links, People Also Ask and related searches as Markdown. Use for recent events, facts and anything after your training cutoff."""
    return serpkite_search(query, country)


result = agent.run_sync("When is the next total solar eclipse visible from Europe?")
print(result.output.answer)
print(result.output.sources)

FAQ

Pydantic AI and SerpKite: common questions

Start building

Give your Pydantic AI project Google search

2,500 free credits, then 1,000 every month. No credit card.