SERPHouseSERPHouse

Vercel AI SDK

Use @serphouse/ai-sdk with the Vercel AI SDK for live web search in AI applications.

@serphouse/ai-sdk is an official AI SDK integration for the SERPHouse Search APIs. It exposes SERPHouse search endpoints as native AI tools, allowing any model supported by the Vercel AI SDK to search the web, retrieve news, or discover short videos through tool calling.

Instead of writing HTTP requests, handling authentication, validating inputs, or parsing responses, you simply register the provided tools and let the model decide when to use them.

Why @serphouse/ai-sdk?

Modern LLMs are limited by their training data and cannot reliably answer questions that require fresh information. @serphouse/ai-sdk bridges this gap by turning SERPHouse APIs into AI-native tools.

Although SERPHouse already provides powerful Search APIs, integrating them into an AI workflow usually requires building HTTP clients, managing authentication, defining tool schemas, validating inputs, handling API responses, and writing repetitive boilerplate.

@serphouse/ai-sdk removes all of that. It wraps SERPHouse APIs into fully typed Vercel AI SDK tools with built-in Zod validation, allowing models to search the internet with only a few lines of code. Instead of manually deciding when to call the API, the language model automatically chooses the appropriate tool whenever it needs external information.

Features

FeatureBenefit
Native tool() integrationPlug-and-play with Vercel AI SDK
Fully typed with TypeScriptAutocomplete and type safety
Built-in Zod validationInput validation out of the box
Zero HTTP boilerplateNo fetch, no axios, no manual requests
Automatic tool callingModel decides when to search
Model-agnosticWorks with OpenAI, Anthropic, Google, and more
Lightweight & production readyMinimal dependencies, fully tested

Installation

Quick setup with a single command.

npm install @serphouse/ai-sdk

Peer dependencies: npm install ai zod

Requires Node.js >= 18.

API Key Setup

The SDK automatically reads the SERPHOUSE_API_KEY environment variable. You can also pass an API key explicitly when creating a tool.

export SERPHOUSE_API_KEY="your_api_key"

Getting Started

Register the tools and let the model decide when to use them:

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { search, news } from "@serphouse/ai-sdk";

const { text } = await generateText({
  model: openai("gpt-4o"),
  tools: {
    search: search(),
    news: news(),
  },
  prompt: "What happened in AI this week?",
});

console.log(text);

The model automatically decides whether a tool is needed, which tool should be called, and what arguments should be passed. No manual API requests are required.

Available Tools

ToolDescriptionEndpoint
search()Google Web Search/web-search-lite
news()Google News Search/google-news
shortVideo()Google Short Videos Search/google-short-videos-api

Each tool includes a Zod input schema, execute handler, type safety, and automatic tool execution.

Tool Input Schema

Every tool accepts the same search parameters (except gl, which is only supported by search()):

PropertyTypeDefaultDescription
qstringRequiredSearch query
domainstring"google.com"Google domain
langstring"en"Language
locstring"New York,New York,United States"Search location
pagenumber1Page number
date_rangestring"y"Time filter
device"desktop" | "mobile""desktop"Device
glstring"US"Country code (search() only)

Authentication

The SDK resolves the API key in the following order.

Environment Variable

export SERPHOUSE_API_KEY="your_api_key"
const tool = search();

Explicit API Key

const tool = search({
  apiKey: "sk-xxxxxxxx",
});

Explicit keys always override the environment variable.

API Reference

Google Web Search. Returns organic results, ads, knowledge graph, related searches, featured snippets, and rich results.

import { search } from "@serphouse/ai-sdk";
const tool = search();

news()

Google News Search. Returns headlines, publishers, publish date, URLs, and news metadata.

import { news } from "@serphouse/ai-sdk";
const tool = news();

shortVideo()

Google Short Videos Search. Returns short videos, metadata, and source URLs.

import { shortVideo } from "@serphouse/ai-sdk";
const tool = shortVideo();

Tool Options

type ToolOptions = {
  apiKey?: string;
};

Examples

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { search, news } from "@serphouse/ai-sdk";

const { text } = await generateText({
  model: openai("gpt-4o"),
  tools: {
    search: search(),
    news: news(),
  },
  prompt: "Latest AI news",
});

Using Multiple Tools

import { search, news, shortVideo } from "@serphouse/ai-sdk";

const tools = {
  search: search(),
  news: news(),
  shortVideo: shortVideo(),
};

The model automatically chooses the correct tool depending on the prompt.

PromptTool
Search React documentationsearch()
Latest NVIDIA newsnews()
Best AI coding reelsshortVideo()

Error Handling

If an API key cannot be found, the SDK throws an authentication error. If SERPHouse returns an API error, it is propagated through the tool execution.

Handle errors normally using try/catch:

try {
  const result = await generateText(...);
} catch (error) {
  console.error(error);
}

Why Use This SDK Instead of Calling the API Directly?

Direct API@serphouse/ai-sdk
Manual HTTP requestsNative AI SDK tools
Manual validationBuilt-in Zod schemas
Manual authenticationAutomatic API key resolution
Manual response handlingAutomatic tool execution
BoilerplateMinimal code
Model unaware of APIsModels can call tools automatically

Last updated on

How is this guide?

On this page