丁香类型SDK
官方JS SDK为: 花环,用于类型脚本和节点. cloro是一个SPER API,有一个API用于Google搜索和每个AI回答引擎 (ChatGPT,双子座,AI Overview,AI Mode,Bing AI Mode). 实时,结构化的JSON.
克洛还有正式的Python SDK,
cloro 关于 PyPI,并有一个主机
Claude、 Cursor 和 ChatGPT 的 MCP 服务器, (中文(简体) ),
因此AI代理可以调用与工具相同的端点.
使用 SDK,或 刚刚 curl 这个:同样的干净反应
无论是哪种方式。 SDK增加了打字方法,明智的重试和投票辅助器
用于同步任务队列,所以不要手卷. 有类型脚本的船舶
建立无害环境管理和共同司法体系.
安装
npm install @cloro-dev/cloro
需要节点 18+( 使用内置) fetch) (中文(简体) ). 与类型脚本、无害环境管理和
常见JS.
快速启动
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);
}
API 密钥来自 CLORO_API_KEY 环境变量,当你不
通过 apiKey。在
仪表板.cloro.dev。 。 。 .
常见JS
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);
});
发动机
每个引擎都是一种方法 client.monitor. AI引擎采取 prompt· ;
谷歌搜索和谷歌新闻 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" });
过 include: { ... } 请求额外格式 - markdown, (中文(简体) ), html, (中文(简体) ),
searchQueries, (中文(简体) ), shopping更多取决于发动机.
Bing AI 模式只接受 include: { markdown, html }编辑 html 值是一个
Bing 显示的页面的 URL 。 您也可以设置 state 改为两个字母的美国国家代码
(仅与 country: "US") (中文(简体) ). 结果 text, (中文(简体) ), sources,以及
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);
}
Async 任务队列
对于量大或长期进行的工作,要排好任务并进行考核以完成.
run() 在一个电话中创建-当时-等待:
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
更喜欢自己管理生命周期:
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 });
在单个请求中批量最多500个任务( 结果保存输入顺序) :
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);
}
全队状态 :
await client.asyncTasks.status(); // queued / processing counts, concurrency usage
有效 taskType 值 : CHATGPT, (中文(简体) ), GEMINI, (中文(简体) ), AIMODE, (中文(简体) ), BING_AIMODE, (中文(简体) ), GOOGLE, (中文(简体) ),
GOOGLE_NEWS。 。 。 .
配置
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
});
处理错误
所有错误子类 CloroErrorHTTP 失败映射到特定状态类型 :
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个)和 InternalServerError (第5xx)条也提供
与 TaskFailedError 编号 : TaskTimeoutError 传票人和
APITimeoutError 编号 : APIConnectionError 从运输.
参考数据
await client.countries(); // supported countries
await client.countries("chatgpt");
await client.countries("bing_aimode"); // countries for Bing AI Mode
await client.states(); // US states for location targeting (Google, Bing AI Mode)
链接
- 红外线 ——主办SERP+AI答-引擎API
- 萨尔瓦多 ——Google搜索这一SDK包装的终点
- 节点和类型脚本指南 快速启动、食谱和生产模式
- 文档 财务报告和审定财务报表 API 参考文献 (OpenAPI)
- 定价 • 妇女 盘子
- Python SDK: (英语) 花环
许可证
麻省理工学院