Menu

Integrations / Model APIs

Mistral

MillionShort search for Mistral models, as a function tool with the Mistral SDKs in Python and TypeScript, or the hosted MCP server in Mistral's Agents SDK.

Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)

RecipePython and TypeScriptNothing of ours to installWorks with no keyChecked 2026-11-19

With the Mistral SDKs, chat.complete takes function tools: the model asks for a call, your code runs the search, and the loop sends the results back until the model answers. Mistral's separate Agents SDK for Python (the mistralai-agents package) can also reach our hosted MCP server itself, which gives the agent every tool of the server (the MCP page lists them).

1Install

Choose one
Shell
pip install mistralai mistralai-agents requests
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY

The examples read your Mistral key from MISTRAL_API_KEY. Get a MillionShort key in the dashboard; an agent can ask for a trial key by itself. mistralai-agents is only for the MCP section further down.

2Minimal example

Choose one
Python
import json
import os

import requests
from mistralai.client import Mistral


def millionshort_search(query: str) -> str:
    r = requests.post(
        "https://api.millionshort.com/v1/search",
        headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"},
        json={"query": query, "remove_top_sites": 1000, "num_results": 5},
        timeout=30,
    )
    r.raise_for_status()
    return json.dumps([{"title": x["title"], "url": x["url"], "snippet": x.get("snippet")} for x in r.json()["data"]["results"]])


tools = [{"type": "function", "function": {
    "name": "millionshort_search",
    "description": "Search the web with MillionShort, leaving out the 1,000 most popular sites.",
    "parameters": {"type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"]},
}}]
client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
messages = [{"role": "user", "content": "Find independent blogs about home espresso."}]
while True:
    message = client.chat.complete(model="mistral-large-latest", messages=messages, tools=tools).choices[0].message
    messages.append(message)
    if not message.tool_calls:
        break
    for call in message.tool_calls:
        args = call.function.arguments  # a JSON string or an already parsed dict
        content = millionshort_search(**(json.loads(args) if isinstance(args, str) else args))
        messages.append({"role": "tool", "name": call.function.name, "tool_call_id": call.id, "content": content})
print(message.content)

Mistral's built-in web search is a tool of its Agents and Conversations APIs that runs only when you add it, and chat.complete has only the tools you pass. Put a line like this in a system message at the start of messages (or in instructions= on an Agents SDK agent):

Use the MillionShort search tool for anything recent, niche, or that needs a source. To reach lesser-known sites, set remove_top_sites (for example 1000). Cite the URLs it returns.

4Check it works

Run the example, then ask:

Search MillionShort for forum threads about restoring a cast iron skillet, with the 1,000 most popular sites removed. List the five most useful with their links.

After the first call, the message's tool calls (tool_calls in Python, toolCalls in TypeScript) name millionshort_search with a query.

With MCP: the Agents SDK

In the Agents SDK, agents.RemoteMCP is an MCP server the agent reaches over HTTP. It does not take the key itself: auth_header_env_vars maps a header to the name of an environment variable that holds the header's full value, so put the whole Bearer value in one (here MILLIONSHORT_AUTH_HEADER). Without a key, leave auth_header_env_vars out. The Agents SDK needs Python 3.12 or later.

Python
# export MILLIONSHORT_AUTH_HEADER="Bearer ms-YOUR_API_KEY"
import asyncio

from mistralai import agents

agent = agents.Agent(
    model="mistral-large-4",
    instructions="Use the millionshort search tool for anything recent or niche, and cite the URLs.",
    mcps={"millionshort": agents.RemoteMCP(url="https://mcp.millionshort.com/mcp", auth_header_env_vars={"Authorization": "MILLIONSHORT_AUTH_HEADER"})},
)


async def main() -> None:
    result = await agent.run("Find independent blogs about home espresso, without the 1,000 most popular sites.")
    if isinstance(result, agents.Completed):
        print(result.text)
        print([call.name for call in result.tool_calls])  # e.g. millionshort.search


asyncio.run(main())

The tools are named <key>.<tool>, so the agent sees millionshort.search, millionshort.get_domain_info, millionshort.list_sources and so on. A missing variable fails before the run starts.

MCP configuration

The same address for every client: https://mcp.millionshort.com/mcp, streamable HTTP.

ModeHowWhat the agent gets
API keySend Authorization: Bearer ms-YOUR_API_KEYEvery tool, at your plan's limits; calls use your credits
No keySend no Authorization headersearch, list_sources and a few more; one source and up to 5 results a search, 10 free searches a day

Tools

ToolWhat it doesWithout a keyCost
searchSearches the web and the specialist sources, with the popularity, domain, page-type, topic, site and date filtersYes: one source, up to 5 results1 credit per source searched, first 10 results
get_domain_infoPopularity and risk for up to 25 sitesNo1 credit
list_sourcesThe sources, page types and topics search acceptsYes: source namesFree
The tools of the other endpointsextract, map, crawl, places and more: the MCP page lists themA few, such as placesWhat the API call behind each costs

The function tool in step 2 is search alone; the Agents SDK server gives the agent every tool of the server.

Settings

VariableMeaning
MILLIONSHORT_API_KEYYour key, read by the function tool
MILLIONSHORT_AUTH_HEADERThe full header value, Bearer ms-..., read by the Agents SDK for RemoteMCP
MISTRAL_API_KEYYour Mistral key

Costs and limits

A tool call costs what the API call behind it costs: 1 credit per source searched for the first 10 results, 1 credit for a domain lookup, nothing for the list of sources, the price of the endpoint for the other tools, and nothing at all in the no-key mode. An agent that loops can make many calls: give it a step limit, and ask for fewer results when a few will do. Credits and limits has the numbers.

When it fails

What you seeWhyFix
401 AUTH_MISSING_KEY or AUTH_INVALID_KEYThe key is missing or wrongSet MILLIONSHORT_API_KEY; keys start with ms-
400 INVALID_PARAMA field name or value the API does not takeThe message names the field; the search reference lists them all
429 RATE_LIMITED or CAPACITYToo many calls a minute, or no free capacity right nowWait the Retry-After seconds, then retry
429 INSUFFICIENT_CREDITSThe plan's credits are used upStop and add credits; do not retry
The Agents SDK stops before the run with a missing variableThe variable named in auth_header_env_vars is not set where the agent runsExport it with the full Bearer ms-... value
401 from the MCP server with the Agents SDKThe variable holds the bare key without Bearer Put Bearer in front of the key in the variable

This page as Markdown ยท llms.txt