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
| Feature | Benefit |
|---|---|
Native tool() integration | Plug-and-play with Vercel AI SDK |
| Fully typed with TypeScript | Autocomplete and type safety |
| Built-in Zod validation | Input validation out of the box |
| Zero HTTP boilerplate | No fetch, no axios, no manual requests |
| Automatic tool calling | Model decides when to search |
| Model-agnostic | Works with OpenAI, Anthropic, Google, and more |
| Lightweight & production ready | Minimal dependencies, fully tested |
Installation
Quick setup with a single command.
npm install @serphouse/ai-sdkPeer 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
| Tool | Description | Endpoint |
|---|---|---|
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()):
| Property | Type | Default | Description |
|---|---|---|---|
q | string | Required | Search query |
domain | string | "google.com" | Google domain |
lang | string | "en" | Language |
loc | string | "New York,New York,United States" | Search location |
page | number | 1 | Page number |
date_range | string | "y" | Time filter |
device | "desktop" | "mobile" | "desktop" | Device |
gl | string | "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
search()
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.
| Prompt | Tool |
|---|---|
| Search React documentation | search() |
| Latest NVIDIA news | news() |
| Best AI coding reels | shortVideo() |
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 requests | Native AI SDK tools |
| Manual validation | Built-in Zod schemas |
| Manual authentication | Automatic API key resolution |
| Manual response handling | Automatic tool execution |
| Boilerplate | Minimal code |
| Model unaware of APIs | Models can call tools automatically |
Related Links
Last updated on
How is this guide?