Menu

Integrations / Model APIs

Ollama

MillionShort search for local models in Ollama, as a function tool in Python and TypeScript.

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

RecipePython and TypeScriptNothing of ours to installChecked 2026-11-19

Ollama's libraries take tools in chat: the model asks for a call, your code runs the search, and the loop sends the results back until the model answers. The model must support tools; Ollama's own examples use qwen3. The model runs on your machine, and only the search goes out to MillionShort.

1Install

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

Pull a model that supports tools before you start (ollama pull qwen3). Both libraries talk to your Ollama with their default settings, so the examples set no address. Get a MillionShort key in the dashboard; an agent can ask for a trial key by itself.

2Minimal example

Choose one
Python
import json
import os

import requests
from ollama import chat


def millionshort_search(query: str) -> str:
    """Search the web with MillionShort, leaving out the 1,000 most popular sites.

    Args:
        query: What to search for.
    """
    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"]])


messages = [{"role": "user", "content": "Find independent blogs about home espresso."}]
while True:
    response = chat(model="qwen3", messages=messages, tools=[millionshort_search])
    messages.append(response.message)
    if not response.message.tool_calls:
        break
    for call in response.message.tool_calls:
        result = millionshort_search(**call.function.arguments)
        messages.append({"role": "tool", "tool_name": call.function.name, "content": result})
print(response.message.content)

The Python library builds the tool's schema from the function's type hints and its docstring (with the Args: section), so keep both. A model can ask for several searches in one turn; the loop runs each of them. Models that think, such as qwen3, also take think=True (think: true), as in Ollama's examples.

Ollama searches nothing unless your code does, so there is no built-in search to turn off. Small models call tools less readily: add a system message with a line like this:

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 chat call, response.message.tool_calls should name millionshort_search with a query. If it is empty every time, the model probably does not support tools: try another.

Tools

The function tool above is search alone. For the server's other tools as well (the MCP page lists them), run Ollama behind an agent framework that speaks MCP and connect our MCP server:

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

Settings

VariableMeaning
MILLIONSHORT_API_KEYYour key, read by the examples above

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.

The model itself runs on your machine and costs nothing per call.

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 model never calls the toolThe model does not support tools, or nothing told it when to searchPull a model that does, such as qwen3
The call to the model cannot connectOllama is not running, or runs somewhere other than the libraries' defaultStart Ollama, or pass its address to the client as Ollama's library docs describe

This page as Markdown ยท llms.txt