Skip to main content
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. 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:
The $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. 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.
Why doesn’t 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.
  1. 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_search function and has already prepared everything for it;
  2. 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 submit tool_call.function.arguments to Kimi large language model as they are, and Kimi large language model will execute the corresponding online search process;
  3. When the user submits tool_call.function.arguments using a message with role=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 a message with finish_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 original tool_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:
  1. Modify the tool definition of $web_search to your own implementation (including name, description etc.). You may need to add additional information in tool.function to inform the model of the specific parameters it needs to generate. You can add any parameters you need in the parameters field;
  2. Change the implementation of the search_impl function: when using Kimi’s $web_search, you just need to return the input arguments as they are; if you use your own online search service, you may need to fully implement the search and crawl functions — 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;
After completing the above steps, you will have successfully migrated from Kimi’s online search function to your own implementation.

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:
Running the above code yields the following output:

About Model Size Selection

Enabling web search significantly increases context length because search results are appended to the conversation. To avoid triggering Input token length too long, we recommend using kimi-k3, which has a 1M-token context window:

Web search billing

In addition to token consumption, we also charge a call fee for each web search. For details, see Pricing.