| name | serpapi-security-basics |
| description | Secure SerpApi API keys and prevent credit abuse.
Use when storing API keys, implementing backend proxies,
or auditing SerpApi access patterns.
Trigger: "serpapi security", "serpapi API key security", "secure serpapi".
|
| allowed-tools | Read, Write, Grep |
| version | 1.4.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","search","seo","serpapi"] |
| compatibility | Designed for Claude Code |
SerpApi Security Basics
Overview
SerpApi uses a single API key for authentication. The key grants full account access -- there are no scoped keys or OAuth. Protect it like a credit card: never expose in frontend code, always proxy through your backend.
Instructions
Step 1: Never Expose API Key in Frontend
const result = await fetch(`https://serpapi.com/search.json?q=${query}&api_key=YOUR_KEY`);
const result = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
export async function GET(req: Request) {
const url = new URL(req.url);
const q = url.searchParams.get('q');
const result = await getJson({
engine: 'google', q,
api_key: process.env.SERPAPI_API_KEY,
});
return Response.json(result.organic_results);
}
Step 2: Secure Storage
.env
.env.local
gh secret set SERPAPI_API_KEY
vercel env add SERPAPI_API_KEY
fly secrets set SERPAPI_API_KEY=x
Step 3: Rate Limit Your Proxy
import rateLimit from 'express-rate-limit';
const searchLimiter = rateLimit({
windowMs: 60_000,
max: 10,
message: 'Too many searches, try again later',
});
app.get('/api/search', searchLimiter, searchHandler);
Step 4: Monitor Usage
curl -s "https://serpapi.com/account.json?api_key=$SERPAPI_API_KEY" \
| jq '{used: .this_month_usage, remaining: .plan_searches_left}'
Security Checklist
Resources
Next Steps
For production deployment, see serpapi-prod-checklist.