Skip to content

New AI assistant answers: ChatGPT, Gemini, Copilot and AI Mode by API

SerpKite
Get API key

Python · openai-agents

OpenAI Agents SDK + SerpKite

Add Google search to an OpenAI Agents SDK agent with a @function_tool, or connect SerpKite's remote MCP server and get search, news, maps, webpage, AI assistant and other tools at once.

Overview

What OpenAI Agents SDK is, and where SerpKite fits

The OpenAI Agents SDK is a lightweight Python framework for agents with tools, handoffs and guardrails. @function_tool turns a typed Python function into a tool; the docstring becomes its description.

Unlike a hosted web search tool, SerpKite gives you real Google results with country and language control and a price per call you can see in every response.

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 OPENAI_API_KEY as well.

    pip install -U serpkite openai-agents
  3. 3

    Define a function tool

    Decorate a function with @function_tool.

  4. 4

    Run the agent

    Runner.run_sync for scripts, await Runner.run in async code.

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 agents import Agent, Runner, function_tool


@function_tool
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.

    Args:
        query: What to search for.
        country: Two-letter country code, e.g. us, gb, de.
    """
    return serpkite_search(query, country)


agent = Agent(
    name="Researcher",
    instructions="Search the web before answering. Cite the URLs you used.",
    tools=[google_search],
)

result = Runner.run_sync(agent, "What's new in the latest Postgres release?")
print(result.final_output)

AI assistants

Ask ChatGPT, Gemini and other AI assistants

The serpkite SDK asks ChatGPT, Gemini, Copilot Search, Google AI Mode and Brave's AI answer as a logged-out visitor (sk.chatgpt, sk.gemini, sk.copilot, sk.ai_mode, sk.brave_ai) and returns the answer as Markdown with the sources it cited. Wrap one with @function_tool. Give the agent a second opinion, or have it check what assistants say about your brand: track adds mentions of the brands and domains you list. See AI assistants.

Through the MCP server the same assistants are the chatgpt, gemini, copilot, ai_mode and brave_ai tools. MCPServerStreamableHttp gives up on a tool call after 5 seconds by default, so pass client_session_timeout_seconds=120 as in the MCP example above.

ChatGPT 4, Gemini 3, Copilot Search 3, Google AI Mode 2 and Brave AI 2 credits per answer; failed, refused and empty answers are free. Brave answers in 1–10 s, ChatGPT in 10–30 s and Gemini in 5–30 s, so allow at least 120 seconds per call.

Python
from agents import Agent, function_tool
from serpkite import SerpKite, SerpKiteError

sk = SerpKite()  # reads SERPKITE_API_KEY


@function_tool
def ask_chatgpt(prompt: str) -> str:
    """Ask ChatGPT (logged out, searching the web) and return its answer as Markdown
    with the sources it cited. Use it to see what ChatGPT tells people. Takes 10–30 s."""
    try:
        return sk.chatgpt(prompt=prompt, format="markdown")
    except SerpKiteError as e:
        return f"ChatGPT failed: {e.message}"


agent = Agent(
    name="Visibility analyst",
    instructions="Ask ChatGPT the user's question, then report which brands it names and which sources it cites.",
    tools=[ask_chatgpt],
)

FAQ

OpenAI Agents SDK and SerpKite: common questions

Start building

Give your OpenAI Agents SDK project Google search

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