Errors
The error format of the mlab.sh REST API, every status code it returns with its cause and fix, and which errors to retry.
The mlab.sh API answers errors with an HTTP status code and a JSON body that carries an error field. This page lists every status the API returns, what causes it and what to do, and which errors are worth retrying. For authentication and quotas themselves, see the API Guide.
Error body
Every error under /api/v1 is JSON with an error field holding a message meant for a person:
{
"error": "This API key does not have the 'cases.write' permission (Write cases). An owner or admin can add it in the organization settings."
}A few variants exist. Read error first and treat the other fields as optional:
| Shape | Where | Example |
|---|---|---|
{"error": "..."} | Almost every error | {"error": "Not found"} |
{"status": "error", "message": "...", "error": "..."} | Some 400 responses (monitoring triage and reads, among others). error is always set to the same text as message. | {"status": "error", "message": "Unknown status.", "error": "Unknown status."} |
{"success": false, "error": {"code": ..., "message": "..."}} | POST /upload/file only, which lives outside /api/v1 | {"success": false, "error": {"code": 413, "message": "file_too_large"}} |
200 with "status": "failed" | GET /api/v1/scan/file/results when a file scan could not complete: the request worked, the scan did not | {"status": "failed", "error": {"kind": "scan_failed", "message": "The scan could not be completed.", "reason": "..."}} |
There are no machine-readable error codes on /api/v1: the status code is the contract, the message is for humans and can change wording. Branch on the status, log the message.
Status codes
| Status | Cause | Fix |
|---|---|---|
400 Bad Request | A required parameter is missing or invalid ("Provided domain is invalid.", "Please provide a valid sha256."), the request is not allowed on your plan ("Cases are part of the Team plan.", "Security monitoring is part of the Team and Enterprise plans."), or one of the quotas that still answers 400 is spent (crypto lookups, RedKit credits, see below). One upstream failure also lands here: GET /api/v1/scan/ip answers 400 "Failed to fetch data for IP: ..." when the IP data could not be fetched. | Fix the input or the plan. Do not retry unchanged, except the IP fetch failure, which is transient. |
401 Unauthorized | The Authorization header carries a key mlab does not know: mistyped, deleted, or expired (keys expire after 90 days by default). Also returned by routes that need an organization (cases, scheduled scans, monitoring) when no key is sent. Body: {"error":"Unauthorized"}. | Check the header is Bearer <key> or token <key>, and that the key still exists in Organization settings → API keys. |
403 Forbidden | The key lacks the permission the route needs (the message names it), the route is closed to API keys ("API keys cannot use this endpoint."), or the organization is locked ("This organization is locked."). | Add the permission to the key, or call the route from a member session. A locked organization needs support. |
404 Not Found | Unknown route, no result for this input (an unknown or private file hash, a case that is not yours), or a POST whose body is not valid JSON (see below). Body: {"error":"Not found"}. | Check the path and method, and that the body parses as JSON. |
413 Payload Too Large | POST /upload/file only: the file is over the size limit. | Upload a smaller file. |
429 Too Many Requests | A scan quota is spent (domain scans, IP lookups, file scans). Carries Retry-After. | See Quotas. |
502 Bad Gateway | An upstream source mlab depends on could not be reached ("The IP data provider could not be reached. Nothing was charged, please try again later."). Your input was fine. | Retry with backoff. |
500 and other 5xx | Not produced by the API's own result types; can come from the infrastructure in front of it. | Retry with backoff, then contact support. |
Calling without a key
A request with no Authorization header is not refused: it is served as an anonymous visitor, with the anonymous quotas counted per IP address (2 domain scans, 5 IP lookups, 2 file scans, 3 crypto lookups). Lookups seem to work, then hit 429 quickly. Routes that need an organization answer 401. If your integration sees anonymous-sized quotas, the header is not reaching the API.
A header with an unknown key never falls back to anonymous: it answers 401, so a typo or a revoked key fails loudly.
A 404 on a POST
The API reads a POST body as JSON. A body that does not parse, an empty body, or a body over 2 MB is read as no body at all, and the POST routes under /scan/ and /cases then answer 404, not 400. If a POST you know exists returns 404, check Content-Type: application/json and that the body is valid JSON.
Quotas: 429 and 400
Scan quotas are counted per organization over a rolling 24-hour window, not a calendar day. When one is spent:
| What ran out | Status | Message |
|---|---|---|
Domain scans (POST /api/v1/scan/domain) | 429 | Scan limit reached. Please try again later. |
IP lookups (GET /api/v1/scan/ip) | 429 | IP lookup limit reached. Please try again later. |
File scans (POST /upload/file) | 429 | {"success": false, "error": {"code": 429, "message": "rate_limited"}} |
Crypto lookups (GET /api/v1/scan/crypto) | 400 | Crypto lookup limit reached. Please try again later. |
RedKit credits (POST /api/v1/scan/redkit) | 400 | For example You have used your 5 RedKit credits this month. Upgrade to Team for more. |
Crypto lookups and RedKit credits still answer 400 when spent, unlike the other quotas. Match on the message, or check /api/v1/limit/crypto and /api/v1/scan/redkit/quota before a batch.
Headers
Every 429 from /api/v1 carries:
HTTP/1.1 429 Too Many Requests
Retry-After: 3600
Content-Type: application/json
{"error":"IP lookup limit reached. Please try again later."}Retry-After is a fixed hint of one hour, not the exact moment a slot frees up: the window is rolling, so the first slot comes back 24 hours after the oldest scan in it.
A call made with an API key to an endpoint that spends a quota (domain scans, IP and crypto lookups) also carries the quota it checked, on success and on refusal alike:
| Header | Value |
|---|---|
X-RateLimit-Limit | The plan's limit for this scan type |
X-RateLimit-Remaining | What is left after this call |
X-RateLimit-Resource | The scan type: domain, ip, file or crypto |
X-RateLimit-Window | 86400, the window in seconds |
The headers are left out when the plan has no limit for that scan type. Read them to slow down before you hit 0, or ask GET /api/v1/limit/{domain|ip|file|crypto} at any time (it spends nothing).
There is no per-second or per-minute request rate limit on the API-key endpoints: what limits you is the quota of each scan type. Hash, URL, MAC, email and phone lookups spend no quota.
Retry guidance
| Status | Retry? | How |
|---|---|---|
400, 401, 403, 404, 413 | No | The same request fails the same way. |
429 | Not right away | A spent quota does not come back in seconds. Stop sending that scan type, wait at least Retry-After, or poll /api/v1/limit/* and resume when remaining is above 0. |
502 | Yes | Exponential backoff with jitter, for example 2 s, 4 s, 8 s, up to 5 attempts. An IP lookup that answers 502 charged nothing. |
5xx | Yes, a few times | Same backoff, then give up and report. |
| Network error or timeout | Yes for reads | A GET is safe to repeat. A retried POST /api/v1/scan/domain starts the scan again and spends another domain scan. |
Polling a running scan (/api/v1/scan/domain/status, /api/v1/scan/file/results) spends no quota. See Code examples for a client that applies these rules.