// Probe (i): Responses API — non-stream, streaming event names, function call, structured output, reasoning summary, store:false. import { raw, rawSSE, save, short } from "./lib.ts"; const results: Record = {}; // 1. non-stream basic with reasoning summary + encrypted content results.basic = await raw("/responses", { method: "POST", body: JSON.stringify({ model: "grok-4.3", instructions: "Answer in one short sentence.", input: [{ role: "user", content: "What is the capital of Canada?" }], max_output_tokens: 300, store: false, reasoning: { effort: "low", summary: "auto" }, include: ["reasoning.encrypted_content"], }), }); console.log("basic", results.basic.status, short(results.basic.body, 1500)); // 2. streaming -> event names const s = await rawSSE("/responses", { model: "grok-4.3", input: "Say hello in French, 5 words max.", stream: true, store: false, max_output_tokens: 200, }); results.stream = { status: s.status, error: (s as any).error, eventTypes: [...new Set(s.events.map((e) => e.data?.type ?? e.event))], sseEventNames: [...new Set(s.events.map((e) => e.event).filter(Boolean))], samples: s.events.slice(0, 6).map((e) => e.data), last: s.events.slice(-2).map((e) => e.data), }; console.log("stream", s.status, results.stream.eventTypes); // 3. function call (flat tool) non-stream + streaming const tools = [{ type: "function", name: "get_weather", description: "Get weather", parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] } }]; const fc = await rawSSE("/responses", { model: "grok-4.3", input: [{ role: "user", content: "Weather in Montreal? Use the tool." }], tools, stream: true, store: false, max_output_tokens: 300 }); results.functionCallStream = { status: fc.status, error: (fc as any).error, eventTypes: [...new Set(fc.events.map((e) => e.data?.type))], fcEvents: fc.events.filter((e) => /function_call|output_item/.test(e.data?.type ?? "")).map((e) => e.data), }; console.log("fc stream", fc.status, results.functionCallStream.eventTypes); const completed = fc.events.find((e) => e.data?.type === "response.completed")?.data?.response; const call = completed?.output?.find((o: any) => o.type === "function_call"); if (call) { results.functionCallRound2 = await raw("/responses", { method: "POST", body: JSON.stringify({ model: "grok-4.3", input: [{ role: "user", content: "Weather in Montreal? Use the tool." }, ...completed.output, { type: "function_call_output", call_id: call.call_id, output: JSON.stringify({ temp_c: 21 }) }], tools, store: false, max_output_tokens: 200, }), }); console.log("fc round2", results.functionCallRound2.status, short(results.functionCallRound2.body?.output?.at(-1), 300)); } // 4. structured output via text.format results.structured = await raw("/responses", { method: "POST", body: JSON.stringify({ model: "grok-4.3", input: "Give info about Paris.", text: { format: { type: "json_schema", name: "city", strict: true, schema: { type: "object", properties: { city: { type: "string" }, country: { type: "string" } }, required: ["city", "country"], additionalProperties: false } } }, store: false, max_output_tokens: 200, }), }); console.log("structured", results.structured.status, short(results.structured.body?.output?.at(-1)?.content, 300)); // 5. image input via Responses results.imageFormat = await raw("/responses", { method: "POST", body: JSON.stringify({ model: "grok-4.3", input: [{ role: "user", content: [{ type: "input_text", text: "One word: what color?" }, { type: "input_image", image_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVR4nGP4z8DwHwj+MzD8Z2D4DwAdyQX7Q7dWpAAAAABJRU5ErkJggg==", detail: "high" }] }], store: false, max_output_tokens: 100, }), }); console.log("image", results.imageFormat.status, short(results.imageFormat.body?.output?.at(-1)?.content ?? results.imageFormat.body, 300)); // 6. rejected params on Responses: presence_penalty etc. results.rejectedParams = await raw("/responses", { method: "POST", body: JSON.stringify({ model: "grok-4.3", input: "ok", presence_penalty: 0.5, store: false, max_output_tokens: 20 }) }); console.log("rejected", results.rejectedParams.status, short(results.rejectedParams.body, 300)); results.multiAgentChat = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: "grok-4.20-multi-agent-0309", messages: [{ role: "user", content: "Reply: ok" }], max_completion_tokens: 20 }) }); console.log("multi-agent on chat/completions", results.multiAgentChat.status, short(results.multiAgentChat.body, 300)); save("07-responses.json", results);