// Probe (h): server-side web_search tool via /v1/responses (streaming) on grok-4.3; plus legacy search_parameters on chat/completions. import { raw, rawSSE, save, short } from "./lib.ts"; const results: Record = {}; const s = await rawSSE("/responses", { model: "grok-4.3", input: "In one sentence, what is the current version of Node.js LTS? Cite a source.", tools: [{ type: "web_search" }], // NOTE: include: ["web_search_call_output"] (as documented) is rejected: 400 'Argument not supported: "web_search_call_output" in "include" field' stream: true, store: false, max_output_tokens: 600, }); const types = [...new Set(s.events.map((e) => e.data?.type))]; const completed = s.events.find((e) => e.data?.type === "response.completed")?.data?.response; results.webSearchStream = { status: s.status, error: (s as any).error, eventTypes: types, searchEvents: s.events.filter((e) => /web_search/.test(e.data?.type ?? "")).map((e) => e.data), completedOutputTypes: completed?.output?.map((o: any) => o.type), completedResponseKeys: completed ? Object.keys(completed) : null, citations: completed?.citations, annotations: completed?.output?.filter((o: any) => o.type === "message").flatMap((o: any) => o.content.flatMap((c: any) => c.annotations ?? [])), text: completed?.output?.filter((o: any) => o.type === "message").flatMap((o: any) => o.content.map((c: any) => c.text)).join(""), usage: completed?.usage, webSearchCallItems: completed?.output?.filter((o: any) => o.type === "web_search_call"), }; console.log("web_search stream", s.status, types, (s as any).error ? JSON.stringify((s as any).error) : ""); console.log("output types", results.webSearchStream.completedOutputTypes); console.log("text", short(results.webSearchStream.text, 400)); console.log("citations", short(results.webSearchStream.citations, 400)); console.log("annotations", short(results.webSearchStream.annotations, 400)); console.log("usage", short(results.webSearchStream.usage, 500)); // legacy search_parameters on chat/completions results.legacySearchParamsChat = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: "grok-4.3", messages: [{ role: "user", content: "One sentence: latest Node.js LTS version?" }], search_parameters: { mode: "on", return_citations: true }, max_completion_tokens: 300 }), }); console.log("legacy search chat", results.legacySearchParamsChat.status, short(results.legacySearchParamsChat.body, 600)); // web_search tool on chat/completions (is it accepted?) results.webSearchToolChat = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: "grok-4.3", messages: [{ role: "user", content: "One sentence: latest Node.js LTS version?" }], tools: [{ type: "web_search" }], max_completion_tokens: 300 }), }); console.log("web_search tool on chat", results.webSearchToolChat.status, short(results.webSearchToolChat.body, 600)); // chat/completions accepts tools[].type = "live_search" per the 422 message above — probe it results.liveSearchToolChat = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: "grok-4.3", messages: [{ role: "user", content: "One sentence: latest Node.js LTS version? Cite a source." }], tools: [{ type: "live_search" }], max_completion_tokens: 400 }), }); const lb: any = results.liveSearchToolChat.body; console.log("live_search tool on chat", results.liveSearchToolChat.status, short(lb?.choices?.[0]?.message ?? lb, 500)); console.log(" citations:", short(lb?.citations, 300), "| usage:", short(lb?.usage, 400), "| top keys:", lb && typeof lb === "object" ? Object.keys(lb) : ""); // include variants on responses for (const inc of ["web_search_call.results", "web_search_call.action.sources", "no_inline_citations"]) { const r = await raw("/responses", { method: "POST", body: JSON.stringify({ model: "grok-4.3", input: "One word: ok", tools: [{ type: "web_search" }], include: [inc], store: false, max_output_tokens: 50 }) }); results[`include:${inc}`] = { status: r.status, error: r.status !== 200 ? r.body : undefined }; console.log("include", inc, r.status, r.status !== 200 ? short(r.body, 200) : ""); } save("08-websearch.json", results);