- Set the
x-baseten-server-toolsrequest header totrue. - Add one or more
baseten__*selectors totools. Only thetypeis needed. Baseten expands the schema automatically. - Add
baseten.tool_settingswhen you want to change the loop limits.
Inference with web search grounding
SetBASETEN_API_KEY. Pick a provider for the examples:
Tools are available on three API protocols. For multi-turn integrations with echo-back and KV-cache stability, Baseten recommends
Messages or Responses.
Chat Completions works fine for single-turn but requires extra care for multi-turn.
- Messages
- Responses
- Chat Completions
To search the web with the Messages API:
-
Install the Anthropic SDK:
-
Create an Anthropic client that sends
x-baseten-server-tools: true. Add the server-side tool selectors and loop limits to the request. Save the code asweb_search_messages.py:Callweb_search_messages.pycontinue_conversation()for a follow-up. The helper appends the completeresponse.contentarray, including the search calls and results that the printed text omits. -
Run the request. The example output is abbreviated because search results and wording change over time:
Search provider selection
For a list of search and fetch tools, see the server-side tool execution reference. The reference also covers provider-specific selectors, loop limits, andtool_choice formats for each API protocol.
Use the system prompt to control search policy. Tell the model when to search, whether to fetch primary sources, and how to cite conflicting evidence.
Mixed server-side and client-side tools
You can configure both tool types when the model needs web results and data that only your application can access, such as private company documentation. Baseten executes tools selected withbaseten__* server-side. Your application executes the functions you define.
Define each application tool with the schema for your API protocol:
- Messages
- Responses
- Chat Completions
Mixed tools
search_company_docs, Baseten returns the open call to your application. Execute the function and return its result through the protocol’s tool-calling loop. Baseten executes a server-side call as soon as the model makes it, and results keep the model’s declaration order in the response. A turn that ends on an open client call reports the protocol’s tool-calling stop condition. Messages reports stop_reason: "tool_use", Responses has no stop field and carries the open call as a function_call item in output, and Chat Completions reports finish_reason: "tool_calls".
The server-side tool execution reference shows where each protocol returns open application calls. For a complete client-side execution loop, see Function calling.
Failures
A provider error usually becomes a tool result that the model can inspect. The model can retry, change its query, choose another offered tool, or answer without that result. You can offer multiple search providers and use the system prompt to tell the model which provider to prefer.Streaming errors
An error after a streaming response starts arrives as an SSE error frame, because the HTTP status is already200. Streaming clients must handle that frame. Each protocol uses its native error frame:
- Messages: an
errorevent with Anthropic’s error body, for example{"type":"error","error":{"type":"api_error","message":"..."}}. The Anthropic SDK raises it asanthropic.APIStatusError. - Responses: a terminal
response.failedevent whoseresponse.errorcarriescodeandmessage. - Chat Completions: a final
{"error": {...}}data frame without an event name. The OpenAI SDK raises it asopenai.APIError.
Status codes
Invalid selectors, settings, or Baseten-specific fields return400. Limits and errors lists every early rejection, including an organization or model without the feature.
A 429 is either the server-tools early-access limit (25 requests per minute per organization) or the standard Model API rate limit. The error body says which. 500, 502, and 529 are model-plane failures with the same semantics as Model APIs. Retry with exponential backoff. A 503 comes from the tool-execution fleet at capacity, not from the search provider. Retry with exponential backoff.
For errors outside server-side tool execution, see Inference errors.
Next steps
Server-side tool execution
Review every tool, configuration field, response field, and limit.
Function calling
Define and run tools in your own application.