Public preview: This API is in public preview. Endpoints, schemas, and limits may change before general availability.
Tool use
An end-to-end example of the model reaching for web_search, and how to render that in your UI.
Tools run server-side and surface through the stream. There is nothing to configure per request — the model decides, the platform runs, you watch.
This guide walks through one realistic example: a question that requires the model to search the web and cite sources.
The request#
const stream = await client.responses.create({
model: "auto",
input: "What was Apple's revenue in Q4 2025? Cite your source.",
stream: true,
});
The model has no internal knowledge of that quarter’s results. It will call web_search.
The event sequence#
You will receive events in roughly this order (sequence numbers in parentheses are illustrative):
(1) response.created
(2) response.output_item.added the assistant message begins
(3) response.content_part.added
(4) response.output_item.added function_call "web_search", status "in_progress"
(5) response.output_item.done function_call "web_search", status "completed", with the results
(6) response.output_text.delta "Apple"
(7) response.output_text.delta " reported"
(...) more deltas
(N) response.output_text.done full answer
(N+1) response.completed
The model may also write a short sentence before it searches (“Let me look that up.”), and it may call web_fetch on a result URL before answering. Several tool calls can be in flight at once: keep them apart by call_id.
Rendering it#
A reasonable chat UI pattern:
const state = {
tools: new Map(), // call_id -> { name, status }
text: "",
};
for await (const event of stream) {
switch (event.type) {
case "response.output_item.added":
if (event.item.type === "function_call") {
state.tools.set(event.item.call_id, { name: event.item.name, status: "running" });
render();
}
break;
case "response.output_item.done":
if (event.item.type === "function_call") {
const tool = state.tools.get(event.item.call_id);
if (tool) tool.status = event.item.status; // "completed" or "failed"
render();
}
break;
case "response.output_text.delta":
state.text += event.delta;
render();
break;
case "response.completed":
state.text = event.response.output_text; // the final answer
render();
break;
}
}
Render the tool pills (one per call_id) above or alongside the text. Update them in place when they change from running to completed or failed.
The tool output#
The output field on output_item.done is plain text that EU GPT writes for the model, not a data format, so don’t parse it. For web_search it is a numbered list of results, each with a title, URL, and snippet:
Found 5 results for "Apple Q4 2025 revenue":
1. **Apple reports fourth quarter results**
URL: https://www.apple.com/newsroom/…
Apple today announced financial results for its fiscal 2025 fourth quarter …
For calculator it is the result as a string. For current_datetime it is a small JSON object with the date, time, weekday, and time zone. For the document tools it is a confirmation; the file itself arrives as a response.file.generated event (see Tools).
Disabling tools for a request#
There is no per-request “no tools” flag. The levers you have:
- Ask in
instructions: “Answer from your own knowledge only. Do not use web_search or web_fetch.” The model usually complies. - Request JSON with
response_format: those requests run without tools. See Structured outputs. - Ask your organisation admin to switch off web tool calls for the whole organisation. See Tools.
Tool failures#
If a tool fails, the model sees the error in the tool’s output and handles it. It will either:
- Retry the tool with different arguments (you will see another
output_item.addedfor the same tool name). - Answer without the tool, or with what it found so far.
- Pick a different tool.
When a tool could not run at all, output_item.done has status: "failed". Your UI should surface “search failed” gracefully — most users prefer “I couldn’t search the web, so here’s what I know” over a silent absence of citations.
Putting it all together#
A minimal end-to-end script that streams to the terminal and prints tool activity inline:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.EUGPT_API_KEY,
baseURL: "https://api.eugpt.ai/v1",
});
const stream = await client.responses.create({
model: "auto",
input: "What's the latest news on the EU AI Act enforcement?",
stream: true,
});
for await (const event of stream) {
switch (event.type) {
case "response.output_item.added":
if (event.item.type === "function_call") {
process.stderr.write(`\n[tool] ${event.item.name} …`);
}
break;
case "response.output_item.done":
if (event.item.type === "function_call") {
process.stderr.write(` (${event.item.status})\n`);
}
break;
case "response.output_text.delta":
process.stdout.write(event.delta);
break;
case "error":
process.stderr.write(`\n[error] ${event.code}: ${event.message}\n`);
break;
case "response.completed":
process.stdout.write("\n");
break;
}
}