tool_search tool in the Azure OpenAI Responses API.
Tool search is supported on
gpt-5.4 and later models. In the examples that follow, replace gpt-5.5 with the name of your model deployment.Prerequisites
- An Azure OpenAI model deployment that supports tool search.
-
An authentication method:
- API key, or
- Microsoft Entra ID (recommended).
-
Install the client libraries for your language:
-
Python:
-
JavaScript:
-
Python:
-
For REST requests, set
AZURE_OPENAI_API_KEYfor API key authentication orAZURE_OPENAI_AUTH_TOKENfor Microsoft Entra ID authentication.
Understand how tool search works
To activate tool search:- Add
tool_searchto thetoolsarray. - Mark the tools that you want to defer with
defer_loading: true.
Use namespaces where possible
You can use tool search with deferred functions, namespaces, or MCP servers. Use namespaces or MCP servers when possible. Models are primarily trained to search these surfaces, and they usually provide greater token savings. For namespaces,defer_loading applies to the functions inside the namespace, not to the namespace object itself.
At the start of a request, the model still sees the name and description of each searchable surface. For a namespace or MCP server, the model sees only the namespace or server name and description. It doesn’t see the individual function definitions until tool search loads them. For an individually deferred function, the model still sees the function name and description, so tool search primarily defers the parameter schema.
For the greatest token savings, group deferred functions into namespaces or MCP servers. Give each surface a clear, high-level description that summarizes its contents. The model can then search and load only the relevant functions.
The following tool configuration defines a namespace with one deferred function:
defer_loading: true are callable immediately. Deferred tools in the same namespace are loaded through tool search.
Choose a tool search type
Tool search supports two execution types:- Hosted tool search: Azure OpenAI searches the deferred tools that you declare in the request and returns the loaded subset in the same response.
- Client-executed tool search: The model emits a
tool_search_call. Your application performs the lookup and returns a matchingtool_search_output.
Use hosted tool search
Hosted tool search is the simplest option when you know the full inventory of functions, namespaces, or MCP servers that the model can search. Declare the inventory, add{"type": "tool_search"}, and let Azure OpenAI decide which tools to load.
Authenticate with Microsoft Entra ID
The following example defines a namespace that contains an immediately available function and a deferred function. The prompt requires the deferred function, so the model searches the namespace before it creates a function call.Authenticate with an API key
The API key example uses the same namespace and prompt:tool_search_callrecords the hosted search step.tool_search_outputcontains the loaded subset that becomes callable.
execution is server and call_id is null.
For complex tasks, the model can load multiple namespaces or MCP servers in one tool_search_call. For example, if a task requires functions from different namespaces, the model can search and load those surfaces together before it creates the function calls.
Use client-executed tool search
Client-executed tool search gives your application full control over tool discovery. Use it when available tools depend on information that isn’t practical to declare in the initialtools list.
Configure the tool_search tool with execution: "client" and a schema for the search arguments that your application expects:
tool_search_call and stops:
tool_search_output that contains the tools to load:
execution is client and call_id is defined. Echo the same call_id from tool_search_call in the corresponding tool_search_output.
Apply advanced usage patterns
Use the following patterns to improve discovery quality and control how tools are added to the context.Keep namespace descriptions clear
Write concise namespace descriptions that describe the use case. The model uses this description to decide when to load functions from the namespace. Put richer detail in the deferred function descriptions, which load only when needed.Understand what gets loaded
Thetool_search_output.tools array contains the tools that the model dynamically loads. The model can call these tools in later turns, so client mode doesn’t need to load the same tool again across turns. Tools that aren’t in this array aren’t available to the model.
To disable a loaded tool, remove it from the tool_search_output item where you define the loaded tool set. Changing the loaded tool set breaks the model’s cache from that point forward.
Use advanced injection patterns
Most integrations declare tools in the request’stools parameter. Client-executed tool search also supports advanced patterns where your application returns tools that weren’t present in the original request. Validate returned schemas carefully, and expose only trusted tool definitions.
Preserve caching
Both hosted and client-executed tool search load tools at the end of the model’s context window. This placement preserves the model’s cache between requests, which can lower costs and improve speed.Add tools at a specific point in the input
Use anadditional_tools input item to make tools available at a specific point in a conversation. This pattern is useful when your application loads tools outside the normal tool search flow or needs to preserve the ordering of tools added during a previous response.
Set role to developer and include the tools in the item’s tools array:
additional_tools item become available only after that item appears in the input. When you manually send conversation items in later requests, preserve the item’s position so the model sees the same tools at the same point in the conversation.