defer_loading: true and return tool_reference blocks for the matches. On Responses, you declare a client-side tool_search tool and return the matching definitions in tool_search_output. The model starts with the tools whose schemas are loaded and gets each deferred schema only when it asks for it.
Use it when a request carries more tools than the model needs at once, such as an agent connected to several MCP servers or a shared internal tool catalog. Deferring unused schemas lowers input tokens and lets the model work with a catalog that would consume too much of the context window if you sent every schema up front.
Baseten handles the schema work: the API keeps deferred schemas out of the prompt, loads a schema when the model asks for it, and keeps earlier turns unchanged for prefix caching. You provide the search tool and decide which tools it can return.
How deferred loading works
Deferred schemas don’t count as input tokens until the model asks for them. On Chat Completions and Messages, when the model references a tool, the server loads that tool’s schema. A referenced schema counts once. On Responses, the definitions intool_search_output are the schemas the server loads for the next turn.
Model support
The table lists the models tested for deferred tool loading. Models that aren’t listed haven’t been verified; don’t sendtool_reference blocks or tool_search_output definitions for them unless you confirm support.
GLM 5.3 and GLM 5.3 Flash support deferred tool loading on all three surfaces. Kimi K3 and the DeepSeek V4.1 Flash models support it on Chat Completions and Messages. On Responses, they call
tool_search, but the definitions in tool_search_output don’t become callable tools, so the model often doesn’t call them. GLM 5.3 Fast supports it on Chat Completions only. On Messages, defer_loading removes its schema but a tool_reference doesn’t restore it; GLM 5.3 Fast doesn’t call tool_search on Responses. GLM 5.2, Kimi K3.1 Pro, and DeepSeek V4 Pro 0813 ignore defer_loading on Chat Completions and Messages but support tool_search on Responses. DeepSeek V4 Flash 0731 ignores defer_loading and doesn’t call tool_search on Responses.
Define deferred tools
On Chat Completions and Messages, setdefer_loading: true on each tool you want to defer. The field is a sibling of function on Chat Completions and a top-level field alongside name, description, and input_schema on Messages. Set it on the tool object, not inside function; a nested defer_loading is ignored.
- Chat Completions
- Messages
Add the field beside
function:Return tool references
On Chat Completions and Messages, when the model calls your search tool, run the search and return a tool result that references the matching deferred tools. Settool_name to the tool’s name. On Chat Completions, the field is tool_name, not name; a reference without it fails with a 400.
- Chat Completions
- Messages
Append a tool message:
tools array, so referenced tools must stay there.
Use the Responses API
The Responses API doesn’t usedefer_loading. Declare a tool_search tool with execution: "client", then return the matching function definitions in tool_search_output.
To load tools with the Responses API:
-
Declare the search tool and force the first turn to call it:
-
When the response contains a
tool_search_call, run your search and append atool_search_outputwith the matching definitions:The model may return an emptyargumentsobject; use the conversation as the search input in that case. - Continue the response. The model can call the returned tools on the next turn.
call_id in tool_search_output must match the tool_search_call. The returned definitions use the Responses function-tool shape, not tool_reference.
Run an end-to-end example
To see deferred loading in action, run one of the following examples. Each one declares atool_search tool, returns the matching tools, and stops after the model requests get_weather:
- The model calls
tool_search. - The client returns the matching tools:
tool_referenceblocks on Chat Completions and Messages, or definitions intool_search_outputon Responses. - The model calls the discovered
get_weathertool.
pip install openai or pip install anthropic), and set BASETEN_API_KEY as described above. On Chat Completions and Messages, list the deferred tool names and one-line descriptions in the system prompt so the model knows what to search for.
get_weather; run that tool as you would any other function call.
Limits
On Messages, keep at least one tool non-deferred. A request where every tool setsdefer_loading: true fails with At least one tool must have defer_loading=false. Don’t set cache_control on a deferred tool either; combining defer_loading with cache_control on the same tool returns a 400.
Token usage
On Chat Completions,usage.prompt_tokens counts the whole prompt, including the schemas that rendered; deferred schemas the model doesn’t reference don’t count. On Messages, usage.input_tokens counts only uncached input; add cache_read_input_tokens and cache_creation_input_tokens for the total prompt. On Responses, usage.input_tokens and usage.output_tokens report the turn; cache details are under usage.input_tokens_details.
Related
- Function calling: the basics of tool calling on Baseten.
- Responses API: the request and response shape for Responses.
- Coding agents: connect Claude Code or Codex CLI to Model APIs.