Skip to content

About

The official TypeScript/Node client for cloro: one API for Google Search, Bing Search and AI answer engines (ChatGPT, Gemini, Google AI Mode, Bing AI Mode, AI Overview). Real-time, structured JSON.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

cloro TypeScript / Node SDK

The official JS SDK for cloro, for TypeScript and Node. cloro is a SERP API with one API for Google Search, Bing Search and every AI answer engine (ChatGPT, Gemini, AI Overview, AI Mode, Bing AI Mode). Real-time, structured JSON.

cloro also has an official Python SDK, cloro on PyPI, and a hosted MCP server for Claude, Cursor and ChatGPT, so an AI agent can call the same endpoints as tools.

Use the SDK, or just curl it: same clean response either way. The SDK adds typed methods, sensible retries, and a polling helper for the async task queue so you don't hand-roll it. Ships with TypeScript types and both ESM and CommonJS builds.

Installation

npm install @cloro-dev/cloro

Requires Node 18+ (uses the built-in fetch). Works with TypeScript, ESM, and CommonJS.

Quickstart

import { Cloro } from "@cloro-dev/cloro";

const client = new Cloro({ apiKey: "sk_live_..." }); // or set CLORO_API_KEY

const res = await client.monitor.chatgpt({
  prompt: "What do you know about Acme Corp?",
  country: "US",
  include: { markdown: true },
});

console.log(res.result.text);
for (const source of res.result.sources) {
  console.log(source.position, source.url, source.label);
}

The API key is read from the CLORO_API_KEY environment variable when you don't pass apiKey. Get a key (and 500 free credits) at dashboard.cloro.dev.

CommonJS
const { Cloro } = require("@cloro-dev/cloro");

const client = new Cloro({ apiKey: "sk_live_..." });
client.monitor.chatgpt({ prompt: "...", country: "US" }).then((res) => {
  console.log(res.result.text);
});

Engines

Every engine is a method on client.monitor. AI engines take a prompt; Google Search, Google News and Bing Search take a query.

await client.monitor.chatgpt({ prompt: "...", country: "US" });
await client.monitor.gemini({ prompt: "...", country: "US" });
await client.monitor.aimode({ prompt: "...", country: "US" }); // Google AI Mode
await client.monitor.bingAimode({ prompt: "...", country: "US" }); // Bing AI Mode

await client.monitor.google({ query: "best crm", country: "US", pages: 1 });
await client.monitor.googleNews({ query: "acme corp", country: "US" });
await client.monitor.bing({ query: "best crm", country: "US" }); // Bing Search

Pass include: { ... } to request extra formats — markdown, html, searchQueries, shopping, and more, depending on the engine.

Bing AI Mode accepts only include: { markdown, html }. The html value is a URL to the page that Bing shows. You can also set state to a two-letter US state code (only with country: "US"). The result has text, sources, and citationPills.

const bing = await client.monitor.bingAimode({
  prompt: "best crm for startups",
  country: "US",
  state: "CA",
  include: { markdown: true },
});
for (const pill of bing.result.citationPills) {
  console.log(pill.position, pill.domain, pill.url);
}

Bing Search returns the Bing results with the AI Overview. It accepts include: { html, aioverview }, pages and first. Set html to true to get the results page. Set aioverview to true to get the Bing AI summary as aioverview, or to { markdown: true } to also get it as markdown. The result has organicResults, ads when the page has ads and, when Bing shows a summary, aioverview, in the same shapes as Google Search. pages (1 to 10) costs 2 credits for each page after the first. first is the result to start at (default 1). Bing shows its AI summary only on the first page. Bing Search has no state or device. The country selects the Bing market.

const bing = await client.monitor.bing({
  query: "best crm for startups",
  country: "US",
  include: { aioverview: { markdown: true } },
});
for (const r of bing.result.organicResults) {
  console.log(r.position, r.link, r.title);
}
console.log(bing.result.aioverview?.markdown);

Async task queue

For high-volume or long-running work, enqueue tasks and poll them to completion. run() does create-then-wait in one call:

const result = await client.asyncTasks.run({
  taskType: "CHATGPT",
  payload: { prompt: "What is cloro?", country: "US" },
});
console.log(result.response); // present once COMPLETED
console.log(result.credits); // credits reserved / charged

Prefer to manage the lifecycle yourself:

const task = await client.asyncTasks.create({
  taskType: "GOOGLE",
  payload: { query: "serp api", country: "US" },
  priority: 5,
});
const snapshot = await client.asyncTasks.retrieve(task); // non-blocking
const done = await client.asyncTasks.wait(task, { timeout: 120_000, pollInterval: 2000 });

Batch up to 500 tasks in a single request (results preserve input order):

const results = await client.asyncTasks.createBatch([
  { taskType: "CHATGPT", payload: { prompt: "q1", country: "US" } },
  { taskType: "GEMINI", payload: { prompt: "q2", country: "GB" } },
]);
for (const item of results) {
  if (item.success) await client.asyncTasks.wait(item.task.id);
  else console.log("failed:", item.error.message);
}

Queue-wide status:

await client.asyncTasks.status(); // queued / processing counts, concurrency usage

Valid taskType values: CHATGPT, GEMINI, AIMODE, BING_AIMODE, GOOGLE, GOOGLE_NEWS, BING.

Configuration

const client = new Cloro({
  apiKey: "sk_live_...",
  baseUrl: "https://api.cloro.dev", // override if needed
  timeout: 300_000, // per-request milliseconds (the default)
  maxRetries: 2, // timeouts, connection errors, 429/5xx
});

Error handling

All errors subclass CloroError. HTTP failures map to status-specific types:

import { Cloro, AuthenticationError, RateLimitError, CloroError } from "@cloro-dev/cloro";

try {
  await client.monitor.chatgpt({ prompt: "...", country: "US" });
} catch (err) {
  if (err instanceof AuthenticationError) {
    // 401 — bad or missing API key
  } else if (err instanceof RateLimitError) {
    // 429 — the client already retried; back off further if it persists
  } else if (err instanceof CloroError) {
    // everything else
  } else {
    throw err;
  }
}

BadRequestError (400), PermissionDeniedError (403), NotFoundError (404), ConflictError (409), and InternalServerError (5xx) are also available, along with TaskFailedError / TaskTimeoutError from the poller and APITimeoutError / APIConnectionError from the transport.

Reference data

await client.countries(); // supported countries
await client.countries("chatgpt");
await client.countries("bing_aimode"); // countries for Bing AI Mode
await client.countries("bing"); // countries for Bing Search
await client.states(); // US states for location targeting (Google, Bing AI Mode)

Links

License

MIT

About

The official TypeScript/Node client for cloro: one API for Google Search, Bing Search and AI answer engines (ChatGPT, Gemini, Google AI Mode, Bing AI Mode, AI Overview). Real-time, structured JSON.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages