跳转到内容
搜索文档

Parallel

最后更新 查看 MarkdownAgent 设置

Parallel 是专为 AI 打造的 Web API,提供生产就绪的输出,幻觉极少,并基于证据给出结果。

端点

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/parallel

URL 结构

向 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

Tasks API 允许你创建全面的研究与分析任务。

cURL 示例

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

Search API 支持带可配置参数的高级搜索。

cURL 示例

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

Chat API 通过 AI Gateway 的 Unified Chat Completions API 受支持。更多详情见下文:

OpenAI 兼容端点

你也可以通过 REST API 使用 OpenAI API schema 访问 Parallel 模型。将请求发送至:

https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions

指定:


{
"model": "parallel/{model}"
}

JavaScript SDK 示例

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

FindAll API 支持从复杂查询中提取结构化数据。

cURL 示例

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."
  }'

这篇文档对您有帮助吗?