# HTTP API quickstart > Make your first calls to the Megido HTTP API in a few minutes, with curl, Python or JavaScript: start without a key, then get a key your user allows. The API is at `https://api.megido.io/v1`. Each tool is `POST /v1/tools/` with its arguments as a JSON body, and its answer holds `summary`, `data` and `meta`. There is no SDK: the examples use curl, Python with `requests` (`pip install requests`), and JavaScript with `fetch` as an ES module (a `.mjs` file) in Node 18 or later. The [examples on GitHub](https://github.com/megido-io/megido-mcp/tree/main/examples) run the same steps as scripts. ## 1. Call without a key The index tools, `search_cohorts`, `get_cohort`, `search_projects` and `get_project_card`, work without a key or sign-in within a free quota of your network each calendar month; `capabilities`, `usage` and `guide` are free. See what is left of the quota with `usage`: curl: ```bash curl -X POST https://api.megido.io/v1/tools/usage ``` Python: ```python import requests answer = requests.post("https://api.megido.io/v1/tools/usage").json() print(answer["summary"]) ``` JavaScript: ```javascript const response = await fetch("https://api.megido.io/v1/tools/usage", { method: "POST" }); const answer = await response.json(); console.log(answer.summary); ``` Then ask a market question: which niches a topic falls into, for a map of its players. curl: ```bash curl -X POST https://api.megido.io/v1/tools/search_cohorts \ -H "Content-Type: application/json" \ -d '{"text": "invoicing for freelancers", "limit": 3}' ``` Python: ```python import requests answer = requests.post( "https://api.megido.io/v1/tools/search_cohorts", json={"text": "invoicing for freelancers", "limit": 3}, ).json() print(answer["summary"]) ``` JavaScript: ```javascript const response = await fetch("https://api.megido.io/v1/tools/search_cohorts", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text: "invoicing for freelancers", limit: 3 }), }); const answer = await response.json(); console.log(answer.summary); ``` Each niche in `data` comes with its `cohort_id`. Open one with `get_cohort` and `"parts": ["distributions"]` to see how its players spread by size, growth and country, without naming a site. Answers say in `meta.notes` when the free quota is about to run out; past it, a call is refused with `quota_exhausted`, and a key is the way on. ## 2. Get a key through a link For more than the free quota of your network, ask your user for a key. Request a link and a code, with the name your user knows your app by: curl: ```bash curl -X POST https://api.megido.io/v1/keys/request \ -H "Content-Type: application/json" \ -d '{"client_name": "My research script"}' ``` Python: ```python import requests request = requests.post( "https://api.megido.io/v1/keys/request", json={"client_name": "My research script"}, ).json() print("Open", request["link"], "and check that it shows the code", request["code"]) ``` JavaScript: ```javascript const response = await fetch("https://api.megido.io/v1/keys/request", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ client_name: "My research script" }), }); const request = await response.json(); console.log(`Open ${request.link} and check that it shows the code ${request.code}`); ``` The answer gives a `link` and a `code` for your user and a `device_code` for you. Show your user the link and the code: they sign in to Megido, or continue without registration, check that the code matches and allow the key. Meanwhile, ask for the key every `interval` seconds until it comes: curl: ```bash curl -X POST https://api.megido.io/v1/keys/token \ -H "Content-Type: application/json" \ -d '{"device_code": ""}' ``` Python: ```python import time while True: time.sleep(request["interval"]) answer = requests.post( "https://api.megido.io/v1/keys/token", json={"device_code": request["device_code"]}, ) if answer.ok: key = answer.json()["key"] break error = answer.json()["error"] if error["code"] not in ("authorization_pending", "slow_down"): raise SystemExit(error["message"]) ``` JavaScript: ```javascript let key; while (!key) { await new Promise((resolve) => setTimeout(resolve, request.interval * 1000)); const answer = await fetch("https://api.megido.io/v1/keys/token", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ device_code: request.device_code }), }); const body = await answer.json(); if (answer.ok) key = body.key; else if (!["authorization_pending", "slow_down"].includes(body.error.code)) throw new Error(body.error.message); } ``` Until your user answers, the poll gives `authorization_pending`. The key comes once: keep it on your server, never in a web page. Niche and project ids found before you had the key do not work with it: search again. A registered account can also create keys itself in the [Megido portal](https://portal.megido.io/login?src=api-quickstart), under Keys and apps. ## 3. Call with your key Send the key in the `Authorization` header; the examples read it from the `MEGIDO_API_KEY` environment variable. A call that may charge takes `estimate: true` first: the estimate is free, says what the call will charge and returns a `quote_token`, which runs exactly what was estimated, for no more. Here the products closest to an idea, its competitors, anonymously: what each site does, its size and growth, without its domain. curl: ```bash curl -X POST https://api.megido.io/v1/tools/search_projects \ -H "Authorization: Bearer $MEGIDO_API_KEY" \ -H "Content-Type: application/json" \ -d '{"text": "invoicing for freelancers", "limit": 5, "estimate": true}' curl -X POST https://api.megido.io/v1/tools/search_projects \ -H "Authorization: Bearer $MEGIDO_API_KEY" \ -H "Content-Type: application/json" \ -d '{"quote_token": ""}' ``` Python: ```python import os import requests url = "https://api.megido.io/v1/tools/search_projects" headers = {"Authorization": f"Bearer {os.environ['MEGIDO_API_KEY']}"} estimate = requests.post( url, headers=headers, json={"text": "invoicing for freelancers", "limit": 5, "estimate": True}, ).json() print(estimate["summary"]) answer = requests.post( url, headers=headers, json={"quote_token": estimate["data"]["quote_token"]} ).json() print(answer["summary"]) ``` JavaScript: ```javascript const url = "https://api.megido.io/v1/tools/search_projects"; const headers = { Authorization: `Bearer ${process.env.MEGIDO_API_KEY}`, "Content-Type": "application/json", }; const estimate = await ( await fetch(url, { method: "POST", headers, body: JSON.stringify({ text: "invoicing for freelancers", limit: 5, estimate: true }), }) ).json(); console.log(estimate.summary); const answer = await ( await fetch(url, { method: "POST", headers, body: JSON.stringify({ quote_token: estimate.data.quote_token }), }) ).json(); console.log(answer.summary); ``` Within the free quota the call charges nothing. Revealing a domain and buying parts of a site's profile are paid from your organization's credits: [What costs what](https://megido.io/guide/what-costs-what) gives the prices. ## When a call is refused A refusal charges nothing, and its `message` says what to do: - `401` with `unauthorised`: the key is wrong, revoked or expired, or the `Authorization` header holds no key. - `402` with `quota_exhausted`: the free quota does not cover the call; without a key, get one through a link. - `403` with `sign_up_required`: the tool is open to registered accounts; the refusal gives the page where your user registers. - `429` with `rate_limited`: too many calls; call again after `Retry-After` seconds. [Errors](https://megido.io/guide/the-http-api#errors) in the client guide lists every code. ## Quoting and embedding Wherever you quote or show data from the API, give a link to https://megido.io. You may build Megido into a product for your own users: call the API for each request of a user and show that user the answer, without storing, accumulating or republishing domains or figures beyond it. These calls are paid from your organization's credits like any other. Section 5 of the [Terms of Service](https://megido.io/terms#5-how-you-may-use-the-data) sets these rules. ## Next - The [API reference](https://megido.io/docs/api): every tool's arguments, answers and errors, and the OpenAPI document. - [The HTTP API](https://megido.io/guide/the-http-api) in the client guide: keys, estimates and retries, limits. - The [Postman collection](https://www.postman.com/megido-io/megido-http-api), with the same calls and a key through a link.