When using web search with
kimi-k3, we recommend the Formula API official tools channel (OpenAI protocol, standard function tool); see How to Use Official Tools in Kimi API.$web_search (of type builtin_function) is Kimi’s built-in web search tool function, implemented on top of the tool_calls usage: the model only generates the search arguments, while the search itself is defined and executed by the Kimi large language model. When you don’t want to implement search-engine calls, page fetching, and content cleanup yourself, declare this built-in tool to get out-of-the-box web search.
Its basic usage and flow are the same as a regular tool_calls tool call — define the tool, submit it via tools, let the model generate the arguments, return the execution result, and get the model’s reply. For the full flow, see Use Kimi API to Complete Tool Calls; this page only highlights where $web_search differs from a regular function.
Declare $web_search
Unlike an ordinary tool, the $web_search function does not require specific parameter descriptions — declaring only type and function.name in tools is enough to register it:
$web_search function is prefixed with a dollar sign $, which is our agreed way to indicate Kimi built-in functions (in ordinary function definitions, the dollar sign $ is not allowed), and if there are other Kimi built-in functions in the future, they will also be prefixed with the dollar sign $.
$web_search works directly with each model’s reasoning behavior: kimi-k3 always reasons, and kimi-k2.6 can also perform web search with thinking enabled.
$web_search can coexist with other ordinary function tools: within the same tools declaration, you can freely mix tools with type=builtin_function and type=function.
Run the web search
When using the$web_search function, the basic flow is no different from that of a regular function — developers don’t even need to modify the original code for executing tool_calls. The following example shows the complete flow: declare $web_search, ask a question, and loop over tool_calls until the model returns its final reply, where search_impl simply returns the model-generated arguments as-is:
The examples on this page use the latest model
kimi-k3 by default. K3 configures reasoning effort with the top-level reasoning_effort request field (supports "low" / "high" / "max", default "max"). To use another model such as kimi-k2.6 or kimi-k2.5, just replace the model field — parameter configurations differ across models. See the Model Parameter Reference.- python
- node.js
search_impl need any logic for searching, parsing, or obtaining web content? As the name builtin_function suggests, $web_search is a built-in function of the Kimi large language model: it is defined by the Kimi large language model and executed by it as well.
- When Kimi large language model generates a response with
finish_reason=tool_calls, it means that Kimi large language model has realized that it needs to execute the$web_searchfunction and has already prepared everything for it; - Kimi large language model will return the necessary parameters for executing the function in the form of
tool_call.function.arguments. However, these parameters are not executed by the caller. The caller just needs to submittool_call.function.argumentsto Kimi large language model as they are, and Kimi large language model will execute the corresponding online search process; - When the user submits
tool_call.function.argumentsusing amessagewithrole=tool, Kimi large language model will immediately start the online search process and generate a readable message for the user based on the search and reading results, which is amessagewithfinish_reason=stop;
Switch to your own search implementation
The online search function provided by the Kimi API aims to offer a reliable large language model online search solution without breaking the compatibility of the original API and SDK, and it is fully compatible with the originaltool_calls feature of the Kimi large language model. If you want to switch from Kimi’s online search function to your own implementation, you can do so in just two simple steps without disrupting the overall structure of your code:
- Modify the
tooldefinition of$web_searchto your own implementation (includingname,descriptionetc.). You may need to add additional information intool.functionto inform the model of the specific parameters it needs to generate. You can add any parameters you need in theparametersfield; - Change the implementation of the
search_implfunction: when using Kimi’s$web_search, you just need to return the inputargumentsas they are; if you use your own online search service, you may need to fully implement thesearchandcrawlfunctions — call search engine APIs (or implement your own content search) to retrieve URLs and summaries, fetch web page content based on URLs (which might require different reading rules for different websites), clean and organize the fetched web page content into a format that the model can easily recognize, such as Markdown, and handle various errors and exceptions, such as no search results or failure to fetch web page content;
Track web search token usage
When using the$web_search function provided by Kimi, the search results are also counted towards the tokens occupied by the prompt (i.e., prompt_tokens). Typically, since the results of web searches contain a lot of content, the token consumption can be quite high. To avoid unknowingly using up a large number of tokens, an extra total_tokens field is added under the usage object inside the generated arguments (read it as arguments.usage.total_tokens), informing the caller of the total number of tokens occupied by the search content. These tokens will be included in the prompt_tokens once the entire web search process is completed.
The following example shows how to read the total_tokens occupied by the search results, along with the token consumption of the whole conversation:
About Model Size Selection
Enabling web search significantly increases context length because search results are appended to the conversation. To avoid triggeringInput token length too long, we recommend using kimi-k3, which has a 1M-token context window: