# API reference

The base address, the shape of every request and response, and where each endpoint's fields are listed.

```text
https://api.millionshort.com
```

The API is JSON over HTTPS. Every path starts with `/v1`. This is version 1.0.0.

## Endpoints

| Endpoint | What it does | Credits |
|---|---|---|
| [`POST /v1/search`](https://millionshort.com/docs/search/parameters) | Search one to five sources and get one ranked list | 1 per source, plus 0.5 per 10 results after the first 10 |
| [`GET /v1/sources`](https://millionshort.com/docs/api-reference/sources) | The sources, page types and topics a search accepts | Free |
| [`POST /v1/domain`](https://millionshort.com/docs/api-reference/domain) | Popularity and risk for up to 25 sites | 1 per call |
| [`POST /v1/keys/agent`](https://millionshort.com/docs/api-reference/agent-key) | A short-lived trial key for an agent. Needs no key | Free |

The fields of an endpoint are listed on the Parameters page of its own section: [Search](https://millionshort.com/docs/search/parameters), [Extract](https://millionshort.com/docs/extract/parameters), [Monitor](https://millionshort.com/docs/monitor/parameters), [Map](https://millionshort.com/docs/map/parameters), [Crawl](https://millionshort.com/docs/crawl/parameters), [Places](https://millionshort.com/docs/places/parameters), [Agent](https://millionshort.com/docs/agent/parameters).

The other endpoints and building blocks, each described with its section:

| Endpoint | What it does |
|---|---|
| [`POST /v1/extract`](https://millionshort.com/docs/extract/parameters) | A page as clean text |
| [`POST /v1/extract/batch`](https://millionshort.com/docs/extract/batch) | The same for up to 1,000 pages, as a job |
| [`/v1/monitors`](https://millionshort.com/docs/monitor/parameters) | Watch a search or a page and be told what changed |
| [`/v1/webhooks`](https://millionshort.com/docs/webhooks) | Where monitors, batches, crawls and agent runs deliver events |
| [`/v1/spaces`](https://millionshort.com/docs/spaces) | Saved scopes for search: create, list, read, change, delete and import. Free |
| [`space` on `POST /v1/search`](https://millionshort.com/docs/spaces#using-a-space-on-a-search) | Search with a saved scope |
| [`POST /v1/map`](https://millionshort.com/docs/map/parameters) | The URLs of a site, from its sitemaps, its links and our index |
| [`POST /v1/crawl`](https://millionshort.com/docs/crawl/parameters) | A site's pages as clean text, as a job: start, poll, list and cancel |
| [`POST /v1/places`](https://millionshort.com/docs/places/parameters) | Businesses and points of interest by what they are and where, as data |
| [`POST /v1/agent`](https://millionshort.com/docs/agent/parameters) | A question in, an answer with a checked quote for every statement out, as a job you start and then poll |

[The endpoints](https://millionshort.com/docs/endpoints) has all six at a glance.

[openapi.json](https://millionshort.com/docs/openapi.json) is the machine-readable description of the four endpoints in the first table. The others are described field by field on their Parameters pages.

## Authentication

Send your key as a bearer token on every call:

```bash
curl https://api.millionshort.com/v1/sources \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY"
```

```python
import os

import requests

r = requests.get(
    "https://api.millionshort.com/v1/sources",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/sources', {
  headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
});
if (!res.ok) throw new Error(`GET /v1/sources failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

The same call as a tool of the MCP server:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "list_sources",
    "arguments": {}
  }
}
```

Keys start with `ms-`. [Authentication](https://millionshort.com/docs/authentication) covers creating and revoking keys, the trial key, and what works with no key.

## Requests

- `POST` bodies are JSON, with `Content-Type: application/json`.
- **A field the endpoint does not list is refused** with `400 INVALID_PARAM`. A typo in a field name is an error, not a silent default.
- A field you leave out takes the default shown in the endpoint's table.
- Calls are synchronous: the answer to a search is the response to the request.
- A search changes nothing, so sending it again after a failure is always safe.

## Responses

Every success has the same four parts:

```json
{
  "data": { "sources": [], "page_types": [], "topics": [] },
  "usage": { "credits": 0, "cost_usd": 0, "breakdown": { "sources": 0 } },
  "warnings": [],
  "request_id": "req_..."
}
```

| Part | What it is |
|---|---|
| `data` | The answer. Its shape depends on the endpoint |
| `usage` | What the call cost: `credits`, `cost_usd`, and a `breakdown` by line item |
| `warnings` | Notices that did not fail the call, each with a `code` and a `message` |
| `request_id` | Identifies the call. Quote it when you contact us |

The SDKs unwrap `data`: `results` and `summary` sit directly on the object a search returns, with `usage`, `warnings` and the request id beside them.

Every failure has one shape too, with a stable `code` to branch on:

```json
{
  "error": {
    "code": "RATE_LIMITED",
    "message": "Too many requests. Try again in 12 seconds.",
    "retry_after_seconds": 12,
    "details": {}
  },
  "request_id": "req_..."
}
```

[Errors](https://millionshort.com/docs/errors) lists every code and says which to retry. A call that ends in an error is never charged.

## Status codes

| Status | Meaning |
|---|---|
| `200` | Success. Read `warnings` as well as `data` |
| `400` | The request is wrong: `INVALID_PARAM` or `UNSUPPORTED_OPTION`. Do not retry it unchanged |
| `401` | No key, or a key that is malformed, revoked or expired |
| `403` | Dashboard sign-up only (`ACCOUNT_NOT_ELIGIBLE`). Not returned by `/v1` calls |
| `404` | No such endpoint or resource |
| `429` | `RATE_LIMITED` or `CAPACITY`: wait `Retry-After` seconds. `INSUFFICIENT_CREDITS`: add credits |
| `500` | Our fault. Retry with a growing pause |
| `502` | `SEARCH_UNAVAILABLE`: search could not be served right now. Retry after `Retry-After` seconds |

## Headers

Every `/v1` response that passed the rate limiter carries these headers:

| Header | Meaning |
|---|---|
| `X-RateLimit-Limit` | Requests allowed per minute |
| `X-RateLimit-Remaining` | Requests left in the current window |
| `X-RateLimit-Reset` | Unix time at which the window is full again |
| `Retry-After` | On a `429` or a `502`: seconds to wait before sending the call again |

[Credits and limits](https://millionshort.com/docs/credits-and-limits) has each plan's numbers.

## Credits

One credit is $0.001. Each endpoint's page says what a call costs, every response says what it did cost in `usage`, and a call that fails costs nothing. [Credits and limits](https://millionshort.com/docs/credits-and-limits) has the rules and worked examples.

## Clients

- [Python SDK](https://millionshort.com/docs/sdks/python) and [TypeScript SDK](https://millionshort.com/docs/sdks/typescript): thin clients, one method per endpoint. Not published to a package registry yet.
- [MCP server](https://millionshort.com/docs/mcp): the same endpoints as tools, for any MCP client.
- [LangChain](https://millionshort.com/docs/integrations/langchain) and [Vercel AI SDK](https://millionshort.com/docs/integrations/vercel-ai-sdk) tool packages. Not published yet.
- Anything that can send an HTTPS request.

Call the API from a server. Do not put a key in code that runs in a browser or a mobile app.
