serpapi-sdk-patterns
Production-ready SerpApi client patterns with caching, typing, and multi-engine support. Use when building search services, implementing result caching, or wrapping SerpApi with typed responses. Trigger: "serpapi patterns", "serpapi best practices", "serpapi client wrapper".
Best use case
serpapi-sdk-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Production-ready SerpApi client patterns with caching, typing, and multi-engine support. Use when building search services, implementing result caching, or wrapping SerpApi with typed responses. Trigger: "serpapi patterns", "serpapi best practices", "serpapi client wrapper".
Teams using serpapi-sdk-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/serpapi-sdk-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How serpapi-sdk-patterns Compares
| Feature / Agent | serpapi-sdk-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Production-ready SerpApi client patterns with caching, typing, and multi-engine support. Use when building search services, implementing result caching, or wrapping SerpApi with typed responses. Trigger: "serpapi patterns", "serpapi best practices", "serpapi client wrapper".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
ChatGPT vs Claude for Agent Skills
Compare ChatGPT and Claude for AI agent skills across coding, writing, research, and reusable workflow execution.
SKILL.md Source
# SerpApi SDK Patterns
## Overview
Production patterns for SerpApi: typed result interfaces, response caching (critical since each search costs credits), multi-engine abstraction, and async search with the Searches Archive API.
## Instructions
### Step 1: Typed Result Interfaces
```typescript
interface SerpApiOrganicResult {
position: number;
title: string;
link: string;
snippet: string;
displayed_link: string;
source?: string;
}
interface SerpApiSearchResult {
search_metadata: { id: string; status: string; created_at: string };
search_parameters: Record<string, string>;
organic_results: SerpApiOrganicResult[];
answer_box?: { answer?: string; snippet?: string; title?: string };
knowledge_graph?: { title: string; description?: string; type?: string };
related_questions?: Array<{ question: string; snippet: string }>;
pagination?: { next: string };
}
```
### Step 2: Cached Search Client
```typescript
import { getJson } from 'serpapi';
import { LRUCache } from 'lru-cache';
const cache = new LRUCache<string, SerpApiSearchResult>({
max: 500,
ttl: 3600_000, // 1 hour -- search results are relatively stable
});
async function cachedSearch(params: Record<string, any>): Promise<SerpApiSearchResult> {
const key = JSON.stringify(params);
const cached = cache.get(key);
if (cached) return cached;
const result = await getJson({
...params,
api_key: process.env.SERPAPI_API_KEY,
}) as SerpApiSearchResult;
cache.set(key, result);
return result;
}
```
### Step 3: Multi-Engine Search Abstraction
```python
import serpapi, os
class SearchService:
ENGINES = {
"web": {"engine": "google", "query_param": "q"},
"news": {"engine": "google_news", "query_param": "q"},
"images": {"engine": "google_images", "query_param": "q"},
"youtube": {"engine": "youtube", "query_param": "search_query"},
"bing": {"engine": "bing", "query_param": "q"},
"shopping": {"engine": "google_shopping", "query_param": "q"},
}
def __init__(self):
self.client = serpapi.Client(api_key=os.environ["SERPAPI_API_KEY"])
def search(self, query: str, engine: str = "web", **kwargs) -> dict:
config = self.ENGINES[engine]
params = {
"engine": config["engine"],
config["query_param"]: query,
**kwargs,
}
return self.client.search(**params)
# Usage
svc = SearchService()
web = svc.search("Claude AI")
news = svc.search("Claude AI", engine="news")
videos = svc.search("Claude AI tutorial", engine="youtube")
```
### Step 4: Async Search (Background Processing)
```python
# Submit search asynchronously -- retrieve later
result = client.search(engine="google", q="expensive query", async_search=True)
search_id = result["search_metadata"]["id"]
# Later: retrieve from archive (no extra credit charge)
import time
while True:
archived = client.search(engine="google", search_id=search_id)
if archived["search_metadata"]["status"] == "Success":
break
time.sleep(2)
```
## Error Handling
| Pattern | Use Case | Benefit |
|---------|----------|---------|
| LRU cache | Repeated queries | Saves API credits |
| Engine abstraction | Multi-engine | Clean API for consumers |
| Async search | Heavy queries | Non-blocking, same credit cost |
| Type interfaces | All usage | Catch response changes early |
## Resources
- [SerpApi Python Client](https://github.com/serpapi/serpapi-python)
- [Searches Archive API](https://serpapi.com/search-archive-api)
- [All Engines](https://serpapi.com/)
## Next Steps
Apply patterns in `serpapi-core-workflow-a` for real-world usage.Related Skills
workhuman-sdk-patterns
Workhuman sdk patterns for employee recognition and rewards API. Use when integrating Workhuman Social Recognition, or building recognition workflows with HRIS systems. Trigger: "workhuman sdk patterns".
wispr-sdk-patterns
Wispr Flow sdk patterns for voice-to-text API integration. Use when integrating Wispr Flow dictation, WebSocket streaming, or building voice-powered applications. Trigger: "wispr sdk patterns".
windsurf-sdk-patterns
Apply production-ready Windsurf workspace configuration and Cascade interaction patterns. Use when configuring .windsurfrules, workspace rules, MCP servers, or establishing team coding standards for Windsurf AI. Trigger with phrases like "windsurf patterns", "windsurf best practices", "windsurf config patterns", "windsurfrules", "windsurf workspace".
windsurf-reliability-patterns
Implement reliable Cascade workflows with checkpoints, rollback, and incremental editing. Use when building fault-tolerant AI coding workflows, preventing Cascade from breaking builds, or establishing safe practices for multi-file AI edits. Trigger with phrases like "windsurf reliability", "cascade safety", "windsurf rollback", "cascade checkpoint", "safe cascade workflow".
webflow-sdk-patterns
Apply production-ready Webflow SDK patterns — singleton client, typed error handling, pagination helpers, and raw response access for the webflow-api package. Use when implementing Webflow integrations, refactoring SDK usage, or establishing team coding standards. Trigger with phrases like "webflow SDK patterns", "webflow best practices", "webflow code patterns", "idiomatic webflow", "webflow typescript".
vercel-sdk-patterns
Production-ready Vercel REST API patterns with typed fetch wrappers and error handling. Use when integrating with the Vercel API programmatically, building deployment tools, or establishing team coding standards for Vercel API calls. Trigger with phrases like "vercel SDK patterns", "vercel API wrapper", "vercel REST API client", "vercel best practices", "idiomatic vercel API".
vercel-reliability-patterns
Implement reliability patterns for Vercel deployments including circuit breakers, retry logic, and graceful degradation. Use when building fault-tolerant serverless functions, implementing retry strategies, or adding resilience to production Vercel services. Trigger with phrases like "vercel reliability", "vercel circuit breaker", "vercel resilience", "vercel fallback", "vercel graceful degradation".
veeva-sdk-patterns
Veeva Vault sdk patterns for REST API and clinical operations. Use when working with Veeva Vault document management and CRM. Trigger: "veeva sdk patterns".
vastai-sdk-patterns
Apply production-ready Vast.ai SDK patterns for Python and REST API. Use when implementing Vast.ai integrations, refactoring SDK usage, or establishing coding standards for GPU cloud operations. Trigger with phrases like "vastai SDK patterns", "vastai best practices", "vastai code patterns", "idiomatic vastai".
twinmind-sdk-patterns
Apply production-ready TwinMind SDK patterns for TypeScript and Python. Use when implementing TwinMind integrations, refactoring API usage, or establishing team coding standards for meeting AI integration. Trigger with phrases like "twinmind SDK patterns", "twinmind best practices", "twinmind code patterns", "idiomatic twinmind".
together-sdk-patterns
Together AI sdk patterns for inference, fine-tuning, and model deployment. Use when working with Together AI's OpenAI-compatible API. Trigger: "together sdk patterns".
techsmith-sdk-patterns
TechSmith sdk patterns for Snagit COM API and Camtasia automation. Use when working with TechSmith screen capture and video editing automation. Trigger: "techsmith sdk patterns".