Getting started

One API key reaches public data from 31 platforms through 273 endpoints, and every platform answers in the same JSON envelope. You pay per successful call, from $0.01. Failed calls are free.

Base URL

Base URL
https://api.mofa-ai.com

Every endpoint lives under /v1, over HTTPS only. Each one has an ID in the form platform.name (such as xiaohongshu.search_note_v2) and a matching path, /v1/platform/name.

Authentication

Create an API key in the console (it starts with mk_live_) and send it in a request header. Either form works:

HTTP
Authorization: Bearer mk_live_…
X-API-Key: mk_live_…

A key spends your balance, so keep it on your server and out of browser or app code. You can give each key a spending limit and revoke it in the console the moment it leaks.

Your first request

Export your key as MOFA_API_KEY, then call Note Search v2 (xiaohongshu.search_note_v2, $0.03 per call):

curl -G "https://api.mofa-ai.com/v1/xiaohongshu/search_note_v2" \
  -H "Authorization: Bearer $MOFA_API_KEY" \
  --data-urlencode 'keyword=咖啡' \
  --data-urlencode 'page=1' \
  --data-urlencode 'sort=general' \
  --data-urlencode 'note_type=_0' \
  --data-urlencode 'note_time=ONE_DAY'

GET and POST

Every endpoint can be called three equivalent ways, with the same parameters:

HTTP
# 1. GET with a query string
GET /v1/xiaohongshu/search_note_v2?keyword=咖啡

# 2. POST with a JSON (or form) body
POST /v1/xiaohongshu/search_note_v2
Content-Type: application/json

{"keyword": "咖啡"}

# 3. POST /v1/call with the endpoint ID
POST /v1/call
Content-Type: application/json

{"endpoint": "xiaohongshu.search_note_v2", "params": {"keyword": "咖啡"}}
  • Parameter values are strings. Numbers and booleans are converted for you.
  • A missing required parameter returns 400 missing_parameter and is not billed.
  • Parameters an endpoint doesn't take are ignored and listed in ignored_params.
  • GET is simplest. POST with JSON is handier for long values or special characters.

Response envelope

Every endpoint answers with the same envelope, and the platform's data is in data. On success:

JSON
{
  "success": true,
  "code": 0,
  "message": "success",
  "request_id": "req_5f1c2a9be04d7c3a81f6e2d0",
  "endpoint": "xiaohongshu.search_note_v2",
  "cost_usd": 0.03,
  "data": { … }
}

On failure success is false, code is the HTTP status and error is one of the codes in the table below:

JSON
{
  "success": false,
  "code": 402,
  "error": "insufficient_balance",
  "message": "Your balance is too low for this call. Top up at https://api.mofa-ai.com/console/billing."
}

Errors

A failed call is never billed. For errors marked retryable, wait and retry with exponential backoff, and honour Retry-After when the response carries it.

ErrorHTTPMeaningRetry
invalid_api_key401Missing or invalid API key. Send it as 'Authorization: Bearer mk_live_…'.No
account_suspended403This account is suspended. Contact contact@mofa-ai.com.No
unknown_endpoint404Unknown endpoint. See GET /v1/endpoints or https://api.mofa-ai.com/docs.No
missing_parameter400A required parameter is missing.No
invalid_parameter400A parameter value is invalid.No
invalid_body400The request body must be a JSON object or a form.No
insufficient_balance402Your balance is too low for this call. Top up at https://api.mofa-ai.com/console/billing.No
key_budget_exceeded402This API key reached its spending limit. Raise it in the console.No
rate_limited429Too many requests for this API key. Slow down and retry.Yes
too_many_concurrent429Too many calls in flight for this account. Retry when some finish.Yes
upstream_rejected422The data source rejected the request (not billed).No
upstream_error502The data source failed (not billed). Retry shortly.Yes
upstream_timeout504The data source timed out (not billed). Retry shortly.Yes
service_unavailable503The data service is temporarily unavailable (not billed). Retry shortly.Yes
internal_error500Internal error (not billed).Yes

Billing headers

Each call reserves the endpoint's price from your balance when it starts. If it fails, timeouts and data source errors included, the charge is refunded at once. Every call that reaches the data source, successful or not, answers with these headers:

HeaderMeaning
X-Request-IdThe id of this call, the same as request_id in the body. Quote it when you contact support.
X-MOFA-Cost-USDWhat this call cost in USD. 0 when it was not billed.
X-MOFA-Balance-USDYour account balance in USD after this call.

A call your balance can't cover returns 402 insufficient_balance, and a key over its spending limit returns 402 key_budget_exceeded. GET /v1/account shows your balance and what the calling key has spent, for free. Every endpoint's price is on the pricing page.

Rate limits

  • Each API key can make up to 300 requests per minute. Beyond that you get 429 rate_limited.
  • Each account can have up to 15 calls in flight. Beyond that you get 429 too_many_concurrent.
  • Both 429s carry a Retry-After header and are not billed.
  • A slow data source can take a few seconds to tens of seconds, so set your client timeout to about 60 seconds.
  • For higher limits, email contact@mofa-ai.com.

Discovery

These need no key (except the last), so programs and AI agents can discover endpoints on their own:

GET /v1/endpointsEvery endpoint with its parameters and price. Add ?platform= and ?lang=zh|en.
GET /v1/endpoints/{id}One endpoint with an example response.
GET /v1/platformsThe list of platforms.
/openapi.jsonThe OpenAPI 3.1 document.
/llms.txtA summary written for AI agents.
GET /v1/accountYour balance and the calling key. Needs a key, costs nothing.

All platforms

↑↓ to move, Enter to open, Esc to close