Documentation

Getting started

MOFA Data API serves public data from 31 platforms through 273 endpoints, with one API key and one 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 (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 way 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 revoke a key in the console at any time and give each key a spending limit.

Your first request

Export your key as MOFA_API_KEY, then call Note Search (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; the platform data is in data. 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 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

Failed calls are never billed. For errors marked retryable, wait and retry with exponential backoff, honouring Retry-After when present.

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 before it runs; if the call fails (including timeouts and data source errors) the charge is refunded at once. Every response carries these headers:

HeaderMeaning
X-Request-IdThe id of this call. 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; a key over its spending limit returns 402 key_budget_exceeded. GET /v1/account shows your balance for free.

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. Some calls take a few seconds, so set your client timeout to about 60 seconds.
  • For higher limits, email contact@mofa-ai.com.

Discovery

These need no key, so programs and AI agents can discover endpoints on their own:

All platforms

Social & content

Commerce

Other