Parallel ↗ 是专为 AI 打造的 Web API,提供生产就绪的输出,幻觉极少,并基于证据给出结果。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/parallel向 Parallel 发送请求时,可以在 parallel 后追加路径,通过 AI Gateway 路由到任意 Parallel 端点。例如,要访问位于 /v1/tasks/runs 的 Tasks API,请使用:
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/parallel/v1/tasks/runs向 Parallel 发送请求时,请确保具备以下条件:
- 你的 AI Gateway Account ID。
- 你的 AI Gateway gateway 名称。
- 有效的 Parallel API 密钥。
Tasks API ↗ 允许你创建全面的研究与分析任务。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/parallel/v1/tasks/runs \
--header 'x-api-key: {parallel_api_key}' \
--header 'Content-Type: application/json' \
--data '{
"input": "Create a comprehensive market research report on the HVAC industry in the USA including an analysis of recent M&A activity and other relevant details.",
"processor": "ultra"
}'Search API ↗ 支持带可配置参数的高级搜索。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/parallel/v1beta/search \
--header 'x-api-key: {parallel_api_key}' \
--header 'Content-Type: application/json' \
--data '{
"objective": "When was the United Nations established? Prefer UN'\''s websites.",
"search_queries": [
"Founding year UN",
"Year of founding United Nations"
],
"processor": "base",
"max_results": 10,
"max_chars_per_result": 6000
}'Chat API ↗ 通过 AI Gateway 的 Unified Chat Completions API 受支持。更多详情见下文:
你也可以通过 REST API 使用 OpenAI API schema 访问 Parallel 模型。将请求发送至:
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions指定:
{
"model": "parallel/{model}"
}import OpenAI from "openai";
const apiKey = "{parallel_api_key}";
const accountId = "{account_id}";
const gatewayId = "{gateway_id}";
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/compat`;
const client = new OpenAI({
apiKey,
baseURL,
});
try {
const model = "parallel/speed";
const messages = [{ role: "user", content: "Hello!" }];
const chatCompletion = await client.chat.completions.create({
model,
messages,
});
const response = chatCompletion.choices[0].message;
console.log(response);
} catch (e) {
console.error(e);
}FindAll API ↗ 支持从复杂查询中提取结构化数据。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/parallel/v1beta/findall/ingest \
--header 'x-api-key: {parallel_api_key}' \
--header 'Content-Type: application/json' \
--data '{
"query": "Find all AI companies that recently raised money and get their website, CEO name, and CTO name."
}'