Mistral + Web Serach

You are looking for the simplest way to add real-time Web Search capability to your existing Mistral completions API call.

Mistral uses a feature called “Agents” or “Tools” to enable web search. The good news is that you don’t have to create a formal “Agent” first; you can directly specify the built-in tool in your Chat Completions request.

Here is the minimal update you need for your API request, shown in a standard JSON format for the REST API.


##🛠️ The Minimal Update: Adding the tools ArrayYou only need to add two key parameters to your existing JSON payload:

  1. The tools array, specifying the built-in web_search tool.
  2. The tool_choice parameter, which is recommended to ensure the model uses the tool when appropriate.

###Minimal JSON Request Example (cURL/REST)This example assumes you are using the standard /v1/chat/completions endpoint and a model that supports tool use (like mistral-large-latest or mistral-medium-latest).

{
  "model": "mistral-large-latest", 
  "messages": [
    {
      "role": "user",
      "content": "What is the capital of France and who won the last World Cup in soccer?"
    }
  ],
  "tools": [
    {
      "type": "web_search"
    }
  ],
  "tool_choice": "auto" 
}
###Key Components Explained Parameter Value Purpose
model mistral-large-latest (or mistral-medium-latest) Must be one of Mistral’s recent models that support the tool-calling/agent feature.
tools [{"type": "web_search"}] This is the most crucial addition. It tells the model the web_search tool is available to use.
tool_choice "auto" This is recommended. It allows the model to decide whether or not to use the web_search tool based on the user’s question (e.g., it won’t use it for a simple math problem).

###The ResponseThe model will internally use the web search tool for up-to-date information (like the World Cup winner) and then return a single, grounded response.

The response from the API will look similar to a normal completion, but the generated text will be backed up by citations, which appear in the content of the final message. The citation objects will typically contain the title, url, and source of the information found.

You will see the final response text structured as chunks, with references interleaved:

{
  // ... other response fields
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": [
          {
            "type": "text",
            "text": "The capital of France is Paris."
          },
          {
            "type": "text",
            "text": "The winner of the most recent FIFA World Cup was"
          },
          {
            "type": "tool_reference",
            "tool": "web_search",
            "title": "Argentina wins World Cup Final 2022",
            "url": "https://example.com/worldcup-final",
            "source": "Search Engine"
          },
          {
            "type": "text",
            "text": "Argentina in 2022."
          }
        ]
      }
    }
  ]
}

(Note: The exact structure of the content with tool_reference chunks might vary slightly, but this is the general approach for RAG/Tool-augmented responses.)

Would you like to see the equivalent code for a specific programming language (e.g., Python or Node.js)?