快速开始
搜索(Search)为 AI 应用提供网络搜索能力,返回带标题、链接、摘要内容和相关度的结构化结果,可直接用于问答,或交给智能体使用。
前提
准备 Bun 或支持原生 fetch 的 Node.js,以及你组织的 API Key(见 API Key),并在服务端设置 PRAXIS_API_KEY。组织需要有可用的 deepseek-flash 模型和余额。
1. 执行搜索
POST /search/v1/search,query 必填,max_results 限制结果条数(最多 20)。每条结果有 title、url、content 和 score。
curl -sS https://api.deepraxis.com/search/v1/search \ -H "Authorization: Bearer $PRAXIS_API_KEY" -H "Content-Type: application/json" \ -d '{"query": "Cloudflare Workers pricing", "max_results": 3}'响应的 results 数组按相关度排列,每项形如 {"title": "…", "url": "https://…", "content": "…", "score": 0.87}。
2. 让智能体使用搜索
给服务智能体加一个搜索绑定 bindings: [{ "type": "search" }],它的 codemode 就能调用 praxis.search.*(search.create、extract.create、crawl.create、map.create)。下面的脚本先直接搜一次,再创建绑定了搜索的智能体,让它通过 codemode 调搜索并给出链接。保存为 search-demo.mjs,执行 node search-demo.mjs。
import assert from "node:assert/strict";import { setTimeout as delay } from "node:timers/promises";
const { PRAXIS_API_KEY } = process.env;assert(PRAXIS_API_KEY, "Set PRAXIS_API_KEY in the server process");const api = "https://api.deepraxis.com";async function request(path, body) { const response = await fetch(`${api}${path}`, { method: body === undefined ? "GET" : "POST", headers: { Authorization: `Bearer ${PRAXIS_API_KEY}`, "Content-Type": "application/json" }, ...(body === undefined ? {} : { body: JSON.stringify(body) }), signal: AbortSignal.timeout(60_000), }); const result = await response.json(); if (!response.ok) { throw new Error(`HTTP ${response.status}; request=${response.headers.get("X-Request-Id")}; ${result.error?.message ?? result.detail ?? ""}`); } return result;}
// 1. Search directly.const found = await request("/search/v1/search", { query: "Cloudflare Workers pricing", max_results: 3 });assert(found.results.length > 0, "Expected at least one result");console.log(found.results.map(({ title, url, score }) => ({ title, url, score })));
// 2. Give an agent the search service with a binding.const agent = await request("/agent/v1/agents", { name: "Research assistant", kind: "service", model: "deepseek-flash", system: "Answer with current information. Look it up with codemode through the platform search service and cite the URL.", tools: [{ type: "agent_toolset_20260401", configs: [{ name: "web_search", enabled: false }, { name: "web_fetch", enabled: false }], }], bindings: [{ type: "search" }],});assert.equal(agent.bindings[0].type, "search");const session = await request("/agent/v1/sessions", { agent: { type: "agent", id: agent.id, version: agent.version },});await request(`/agent/v1/sessions/${session.id}/events`, { events: [{ type: "user.message", content: [{ type: "text", text: "Use codemode to call praxis.search.search.create for the Cloudflare Workers pricing page and give me its URL." }] }],});
// 3. Wait for a reply that is followed by an idle status.const deadline = Date.now() + 180_000;let reply = "";while (Date.now() < deadline && !reply) { const { data } = await request(`/agent/v1/sessions/${session.id}/events?order=asc&limit=100`); const last = data.findLastIndex((event) => event.type === "agent.message"); if (last >= 0 && data.slice(last).some((event) => event.type === "session.status_idle")) { reply = data.filter((event) => event.type === "agent.message") .flatMap((event) => event.content ?? []).map((block) => block.text ?? "").join("\n"); } else await delay(2000);}assert(reply.includes("http"), `Expected a URL in the reply, got: ${reply}`);console.log({ session: session.id, reply });预期结果: 先输出三条结果的标题、链接和分数;最后输出会话 ID 和智能体的回复,回复里包含它从搜索结果取到的链接。示例关闭了 web_search 和 web_fetch 两个原生工具,是为了确认回答确实来自搜索绑定。
搜索绑定与 web_search 工具的区别
两者都能让智能体搜索网络,但不是同一条路:
{type: "search"} 绑定 | 原生 web_search 工具 | |
|---|---|---|
| 是什么 | 在智能体的 bindings 里开放整个搜索服务 | 内置工具集里的一个工具,新智能体默认启用 |
| 怎么用 | 智能体在 codemode 里写代码调用 praxis.search.search.create、extract、crawl、map,能用上接口的全部参数,并对结果做进一步处理 | 模型直接调用,传查询,得到带引用的结果;可按域名设置允许或屏蔽 |
| 开关 | 绑定上的 enabled;需要机器(environment_id 不能为 null) | 工具集 configs 里按名字启用或禁用 |
| 适合 | 要批量搜索、抓取页面、遍历站点,或把结果交给后续代码处理 | 随口查一下最新信息 |
只想让智能体能上网查资料,保留默认的 web_search 即可,不需要绑定。需要搜索服务的完整接口时才加绑定。
失败时检查
| 现象 | 处理 |
|---|---|
| HTTP 401 | 检查 PRAXIS_API_KEY 是否存在、是否属于你的组织 |
创建智能体 400 bindings need a machine | 绑定需要机器,不要把 environment_id 设为 null |
| 智能体没有调用搜索 | 在提示里明确要求用 codemode 调用 praxis.search.search.create,并在事件里确认出现 codemode 工具调用 |
下一步
计费
每次搜索调用按固定单价计费(与实际服务的供应商无关):basic 按调用次数计费(查看实时价格)、advanced 按调用次数计费(查看实时价格)。费用计入组织余额,在费用与充值页查看。搜索失败(非 200 或空结果)不计费。价格调整提前 30 天通知。