SDK JavaScript / TypeScript
@serpcheap/sdk est le client officiel JavaScript/TypeScript — Node 18+, zéro dépendance (fetch
natif), entièrement typé.
Installation
Section intitulée « Installation »npm install @serpcheap/sdkDémarrage rapide
Section intitulée « Démarrage rapide »import { SerpCheap } from "@serpcheap/sdk";
const client = new SerpCheap("YOUR_API_KEY");
const res = await client.search({ q: "best running shoes", gl: "us" });for (const r of res.organic) { console.log(`${r.position}. ${r.title} — ${r.link}`);}const client = new SerpCheap("YOUR_API_KEY", { baseUrl: "https://api.serp.cheap", // default timeoutMs: 15000, // default maxRetries: 2, // retries on transient errors});Pagination
Section intitulée « Pagination »searchPages itère les pages pour vous (from/to inclusifs) :
for await (const page of client.searchPages({ q: "coffee makers" }, 1, 5)) { console.log(`page ${page.page}: ${page.organic.length} results`);}Gestion des erreurs
Section intitulée « Gestion des erreurs »import { SerpCheapError } from "@serpcheap/sdk";
try { const res = await client.search({ q: "query" });} catch (err) { if (err instanceof SerpCheapError) { console.error(`[${err.code}] ${err.message} (retryable=${err.retryable})`); }}