import {
SocialRouter,
SocialRouterError,
AuthenticationError,
InsufficientCreditsError,
RateLimitError,
} from "@socialrouter/sdk";
const sr = new SocialRouter({ apiKey: "sr_live_your_key" });
try {
const run = await sr.run("linkedin/profile.info", {
url: "https://linkedin.com/in/example",
});
} catch (err) {
if (err instanceof RateLimitError) {
// retryAfter is only set when the API sends a reset timestamp; back off
// on a fixed delay when it is absent.
const waitMs = err.retryAfter ? err.retryAfter * 1000 - Date.now() : 60_000;
console.log(`Rate limited. Retry in ${Math.max(0, Math.ceil(waitMs / 1000))}s`);
} else if (err instanceof InsufficientCreditsError) {
console.log("Add credits:", err.message);
} else if (err instanceof AuthenticationError) {
console.log("Check your API key:", err.message);
} else if (err instanceof SocialRouterError) {
console.log(`API error [${err.code}]: ${err.message}`);
}
}