Custom function calling
Expose application-owned operations such as weather lookup, database retrieval, or business actions to a model.
AI & ML · Const
tools is the request parameter that gives an OpenAI model access to callable functions and built-in capabilities. The model can choose a tool, while your application performs the operation and returns its output for continued generation.
The tools parameter is an array of capabilities made available to the model for a request. A model can select a tool, after which the application executes the corresponding code and sends the result in a follow-up request so the model can produce a final response or make additional tool calls.
tools: Tool[]| Name | Type | Description |
|---|---|---|
tools | array | Array of tools that the model may call for the request; entries can describe custom functions or supported built-in tools. |
The model response may contain a tool call, a final response, or additional tool calls.
tools parameter.import OpenAI from "openai";
const client = new OpenAI();
const tools = [{
type: "function",
name: "get_weather",
description: "Get current temperature for a city.",
parameters: {
type: "object",
properties: { location: { type: "string" } },
required: ["location"],
additionalProperties: false
},
strict: true
}];
const response = await client.responses.create({
model: "gpt-5",
tools,
input: "What is the weather in Paris?"
});
console.log(response.output);Supplies a function tool to the Responses API so the model can request application-side weather retrieval.
Expose application-owned operations such as weather lookup, database retrieval, or business actions to a model.
Offer web search when a response needs current external information.
Manage a large catalog of callable capabilities by loading less-common tools only when needed.
tools parameter?The tools array declares capabilities the model may use, including custom functions and built-in tools. With function calling, the application still executes the requested function; the model does not directly run application code.
Follow-up: How does the application complete a function call? It reads the tool call's arguments, runs the function, then makes another model request containing the tool output.
The interaction is multi-step: send tools with the request, receive a tool call, execute it in the application, send the result back, and receive a final response or another call.
Follow-up: Why might another call occur? The model can require multiple tools or successive tool invocations before it has enough information to answer.
A custom function tool uses a schema describing its name, purpose, and parameters. Strict structured parameters help constrain the arguments the model generates.
Follow-up: What should be validated before execution? Validate the tool name and arguments against application-side rules, because the model's request is not itself authorization.
function callingtool callingtool_searchResponses APIweb_searchfile search