TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1// Probe (h): server-side web_search tool via /v1/responses (streaming) on grok-4.3; plus legacy search_parameters on chat/completions.2import { raw, rawSSE, save, short } from "./lib.ts";34const results: Record<string, any> = {};5const s = await rawSSE("/responses", {6 model: "grok-4.3",7 input: "In one sentence, what is the current version of Node.js LTS? Cite a source.",8 tools: [{ type: "web_search" }],9 // NOTE: include: ["web_search_call_output"] (as documented) is rejected: 400 'Argument not supported: "web_search_call_output" in "include" field'10 stream: true,11 store: false,12 max_output_tokens: 600,13});14const types = [...new Set(s.events.map((e) => e.data?.type))];15const completed = s.events.find((e) => e.data?.type === "response.completed")?.data?.response;16results.webSearchStream = {17 status: s.status,18 error: (s as any).error,19 eventTypes: types,20 searchEvents: s.events.filter((e) => /web_search/.test(e.data?.type ?? "")).map((e) => e.data),21 completedOutputTypes: completed?.output?.map((o: any) => o.type),22 completedResponseKeys: completed ? Object.keys(completed) : null,23 citations: completed?.citations,24 annotations: completed?.output?.filter((o: any) => o.type === "message").flatMap((o: any) => o.content.flatMap((c: any) => c.annotations ?? [])),25 text: completed?.output?.filter((o: any) => o.type === "message").flatMap((o: any) => o.content.map((c: any) => c.text)).join(""),26 usage: completed?.usage,27 webSearchCallItems: completed?.output?.filter((o: any) => o.type === "web_search_call"),28};29console.log("web_search stream", s.status, types, (s as any).error ? JSON.stringify((s as any).error) : "");30console.log("output types", results.webSearchStream.completedOutputTypes);31console.log("text", short(results.webSearchStream.text, 400));32console.log("citations", short(results.webSearchStream.citations, 400));33console.log("annotations", short(results.webSearchStream.annotations, 400));34console.log("usage", short(results.webSearchStream.usage, 500));3536// legacy search_parameters on chat/completions37results.legacySearchParamsChat = await raw("/chat/completions", {38 method: "POST",39 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 }),40});41console.log("legacy search chat", results.legacySearchParamsChat.status, short(results.legacySearchParamsChat.body, 600));4243// web_search tool on chat/completions (is it accepted?)44results.webSearchToolChat = await raw("/chat/completions", {45 method: "POST",46 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 }),47});48console.log("web_search tool on chat", results.webSearchToolChat.status, short(results.webSearchToolChat.body, 600));4950// chat/completions accepts tools[].type = "live_search" per the 422 message above — probe it51results.liveSearchToolChat = await raw("/chat/completions", {52 method: "POST",53 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 }),54});55const lb: any = results.liveSearchToolChat.body;56console.log("live_search tool on chat", results.liveSearchToolChat.status, short(lb?.choices?.[0]?.message ?? lb, 500));57console.log(" citations:", short(lb?.citations, 300), "| usage:", short(lb?.usage, 400), "| top keys:", lb && typeof lb === "object" ? Object.keys(lb) : "");5859// include variants on responses60for (const inc of ["web_search_call.results", "web_search_call.action.sources", "no_inline_citations"]) {61 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 }) });62 results[`include:${inc}`] = { status: r.status, error: r.status !== 200 ? r.body : undefined };63 console.log("include", inc, r.status, r.status !== 200 ? short(r.body, 200) : "");64}65save("08-websearch.json", results);66