Menu

Integrations / Model APIs

Cohere

MillionShort search for Cohere's Command models, as a tool whose results go back as documents the answer cites, in Python.

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

RecipePythonNothing of ours to installChecked 2026-11-19

Cohere's Chat endpoint takes function tools: the model asks for a call, your code runs the search, and you send the results back as document items. The model then answers from those documents and returns citations that point at them. Cohere's tool use documentation shows Python, so this page does too.

1Install

Python
pip install cohere requests
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY

The example reads your Cohere key from COHERE_API_KEY. Get a MillionShort key in the dashboard; an agent can ask for a trial key by itself.

2Minimal example

Python
import json
import os

import cohere
import requests


def millionshort_search(query: str) -> list[dict]:
    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 [{"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"]},
}}]
co = cohere.ClientV2(api_key=os.environ["COHERE_API_KEY"])
messages = [{"role": "user", "content": "Find independent blogs about home espresso."}]
response = co.chat(model="command-a-plus-05-2026", messages=messages, tools=tools)
while response.message.tool_calls:
    messages.append(response.message)
    for call in response.message.tool_calls:
        results = millionshort_search(**json.loads(call.function.arguments))
        documents = [{"type": "document", "document": {"data": json.dumps(result)}} for result in results]
        messages.append({"role": "tool", "tool_call_id": call.id, "content": documents})
    response = co.chat(model="command-a-plus-05-2026", messages=messages, tools=tools)
print(response.message.content[0].text)
print(response.message.citations)

Each search result becomes one document, so each citation points at one page. The model may call the tool again after seeing results; the loop runs until it answers.

Cohere searches nothing unless your code does, so there is no built-in search to turn off. Put a line like this in a system message at the start of messages:

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 co.chat call, response.message.tool_calls names millionshort_search with a query; the final answer's citations point at the documents you sent back.

Tools

The function tool above is search alone. For the server's other tools as well (get_domain_info, list_sources and the tools of the other endpoints), use an agent framework that speaks MCP with 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 example above
COHERE_API_KEYYour Cohere key, read by the example 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.

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 answers without calling the toolNothing told it when to searchAdd the line from step 3

This page as Markdown ยท llms.txt