OpenRouter
MillionShort search for any OpenRouter model that takes tools, as a function tool in Python or a tool and the hosted MCP server in OpenRouter's TypeScript Agent 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
OpenRouter's API is compatible with OpenAI's, so in Python the OpenAI SDK runs a function tool loop against it. In TypeScript, OpenRouter's Agent SDK (@openrouter/agent) runs the loop for you, and its @openrouter/mcp package connects our hosted MCP server. Either way, pick a model that supports tool calling: OpenRouter's model list filters for them.
1Install
pip install openai requests
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEYnpm install @openrouter/agent @openrouter/mcp zod
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEYThe examples read your OpenRouter key from OPENROUTER_API_KEY. Get a MillionShort key in the dashboard; an agent can ask for a trial key by itself.
2Minimal example
import json
import os
import requests
from openai import OpenAI
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",
"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 = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"])
items = [{"role": "user", "content": "Find independent blogs about home espresso."}]
while True:
response = client.responses.create(model="google/gemini-3-flash-preview", tools=tools, input=items)
items += response.output
calls = [item for item in response.output if item.type == "function_call"]
if not calls:
break
for call in calls:
items.append({"type": "function_call_output", "call_id": call.call_id, "output": millionshort_search(**json.loads(call.arguments))})
print(response.output_text)import { OpenRouter, tool } from '@openrouter/agent';
import { callModel } from '@openrouter/agent/call-model';
import { z } from 'zod';
const millionshortSearch = tool({
name: 'millionshort_search',
description: 'Search the web with MillionShort, leaving out the 1,000 most popular sites.',
inputSchema: z.object({ query: z.string().describe('What to search for') }),
execute: async ({ query }) => {
const res = await fetch('https://api.millionshort.com/v1/search', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ query, remove_top_sites: 1000, num_results: 5 }),
});
if (!res.ok) throw new Error(`search failed: ${res.status}`);
const { data } = (await res.json()) as { data: { results: { title: string; url: string; snippet?: string }[] } };
return data.results.map(({ title, url, snippet }) => ({ title, url, snippet }));
},
});
const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });
const result = callModel(client, {
model: 'google/gemini-3-flash-preview',
input: 'Find independent blogs about home espresso.',
tools: [millionshortSearch],
});
console.log(await result.getText());The Agent SDK calls the tool and feeds the result back for as many turns as the model needs.
3Tell it when to search
OpenRouter's own web search is a server tool (openrouter:web_search) that runs only when you list it in tools, so leave it out. Then put a line like this in instructions (a field of both responses.create and callModel):
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.
In Python, the first response's output has a function_call item named millionshort_search. In TypeScript, await result.getToolCalls() lists the calls from the first response, with their parsed arguments.
With MCP: the hosted server
@openrouter/mcp connects to a remote MCP server over streamable HTTP and turns its tools into Agent SDK tools, so the model gets the server's tools: search, get_domain_info, list_sources and the tools of the other endpoints (the MCP page lists them all). OpenRouter documents this for TypeScript only. Without a key, leave auth out.
import { OpenRouter } from '@openrouter/agent';
import { callModel } from '@openrouter/agent/call-model';
import { createMCPTools } from '@openrouter/mcp';
const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });
const mcp = await createMCPTools({
url: 'https://mcp.millionshort.com/mcp',
auth: { kind: 'bearer', token: process.env.MILLIONSHORT_API_KEY ?? '' },
});
const result = callModel(client, {
model: 'google/gemini-3-flash-preview',
input: 'Find independent blogs about home espresso, without the 1,000 most popular sites.',
tools: mcp.tools,
});
console.log(await result.getText());
await mcp.close();MCP configuration
The same address for every client: https://mcp.millionshort.com/mcp, streamable HTTP.
| Mode | How | What the agent gets |
|---|---|---|
| API key | Send Authorization: Bearer ms-YOUR_API_KEY | Every tool, at your plan's limits; calls use your credits |
| No key | Send no Authorization header | search, list_sources and a few more; one source and up to 5 results a search, 10 free searches a day |
Tools
| Tool | What it does | Without a key | Cost |
|---|---|---|---|
search | Searches the web and the specialist sources, with the popularity, domain, page-type, topic, site and date filters | Yes: one source, up to 5 results | 1 credit per source searched, first 10 results |
get_domain_info | Popularity and risk for up to 25 sites | No | 1 credit |
list_sources | The sources, page types and topics search accepts | Yes: source names | Free |
| The tools of the other endpoints | extract, map, crawl, places and more: the MCP page lists them | A few, such as places | What the API call behind each costs |
The function tool in step 2 is search alone; the MCP handle gives the model every tool of the server.
Settings
| Variable | Meaning |
|---|---|
MILLIONSHORT_API_KEY | Your key, read by the examples above |
| OPENROUTER_API_KEY | Your OpenRouter 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.
When it fails
| What you see | Why | Fix |
|---|---|---|
401 AUTH_MISSING_KEY or AUTH_INVALID_KEY | The key is missing or wrong | Set MILLIONSHORT_API_KEY; keys start with ms- |
400 INVALID_PARAM | A field name or value the API does not take | The message names the field; the search reference lists them all |
429 RATE_LIMITED or CAPACITY | Too many calls a minute, or no free capacity right now | Wait the Retry-After seconds, then retry |
429 INSUFFICIENT_CREDITS | The plan's credits are used up | Stop and add credits; do not retry |
| The model never calls the tool | The model does not support tool calling, or nothing told it when to search | Pick one from the model list filtered for tools, and add the line from step 3 |
Related
- Agent tool use: when to give a model tools, and what to tell it.
- Other model APIs: OpenAI, Anthropic, Gemini, Ollama.
- Search API reference and MCP server.
- OpenRouter's own documentation, read on 2026-11-19: Tool calling, Agent SDK tools, MCP tools, Web search.