Aller au contenu

SDK JavaScript / TypeScript

@serpcheap/sdk est le client officiel JavaScript/TypeScript — Node 18+, zéro dépendance (fetch natif), entièrement typé.

Fenêtre de terminal
npm install @serpcheap/sdk
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
});

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`);
}
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})`);
}
}