Skip to content

New Official SDKs for TypeScript, Python and Go

SerpKite
Get API key

TypeScript · ai

Vercel AI SDK + SerpKite

Define a SerpKite search tool with tool() and zod, pass it to generateText or streamText, and let any model search Google. Works in Next.js route handlers, Node and edge runtimes.

Overview

What Vercel AI SDK is, and where SerpKite fits

The Vercel AI SDK is a TypeScript toolkit for building AI apps with any model provider. Tools are defined with tool(), a zod inputSchema and an execute function.

The official serpkite TypeScript SDK has zero dependencies and runs anywhere fetch does (Node 18+, Bun, Deno, edge). Keep the key on the server: call it from a route handler, not from the browser.

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

    The SerpKite SDK, the AI SDK, a provider and zod.

    npm install serpkite ai @ai-sdk/openai zod
  3. 3

    Define the tool

    Describe when to use it; the model reads the description.

  4. 4

    Call generateText with a step limit

    stopWhen: stepCountIs(5) lets the model search, read the result and answer.

Code

Complete example

import { openai } from "@ai-sdk/openai";
import { generateText, stepCountIs, tool } from "ai";
import { z } from "zod";

import { SerpKite, SerpKiteError } from "serpkite";

const sk = new SerpKite(); // reads SERPKITE_API_KEY

async function serpkiteSearch(query: string, country = "us") {
  try {
    // format: "markdown" returns a string: results, People Also Ask, related searches
    return await sk.search({ q: query, country, format: "markdown" });
  } catch (err) {
    if (err instanceof SerpKiteError) return `Search failed: ${err.message}`;
    throw err;
  }
}

const googleSearch = tool({
  description: "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.",
  inputSchema: z.object({
    query: z.string().describe("The search query"),
    country: z.string().length(2).default("us").describe("Two-letter country code"),
  }),
  execute: async ({ query, country }) => serpkiteSearch(query, country),
});

const { text } = await generateText({
  model: openai("gpt-5-mini"),
  tools: { googleSearch },
  stopWhen: stepCountIs(5),
  prompt: "What did the latest Node.js LTS release change? Cite sources.",
});

console.log(text);

FAQ

Vercel AI SDK and SerpKite: common questions

Start building

Give your Vercel AI SDK project Google search

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