Authentication
API keys, spending limits and checking your balance.
Every request to /api/v1 carries your API key as a bearer token:
Authorization: Bearer sk-...Requests are JSON in and JSON out. Send Content-Type: application/json with a body.
Keys
Create and revoke keys in the console under API keys.
- A key is shown once, when you create it. We store only a one-way hash, so we cannot show it again. If you lose it, revoke it and create a new one.
- You can have up to 20 active keys. Use a separate key for each app or environment, so you can revoke one without touching the others.
- Revoking a key takes effect immediately. Requests using it get
401 invalid_api_key. - Keep keys on your server. Never put one in browser code or a mobile app.
Spending limits
Each key can have its own total spending limit. Once the key has spent that much, requests with it are rejected with 403 key_quota_exceeded. A refund gives the amount back to the key's allowance as well as to your balance.
A limit does not reset by itself. Raise or remove it in the console when you want the key to keep going. Setting a limit on every key is the cheapest protection against a leaked key or a runaway loop.
Check your balance
curl https://nsfwapi.io/api/v1/balance \
-H "Authorization: Bearer $NSFWAPI_KEY"{
"balance": "12.345000",
"currency": "USD",
"key": { "quota": "50.000", "used": "3.250" }
}balanceis the account balance in USD, up to six decimals.key.quotais this key's spending limit, ornullwhen it has none.key.usedis what it has spent.
Money in the API
Amounts are always strings holding a decimal number, such as "0.025", never floating-point numbers. Task prices are multiples of 0.001. Parse them with a decimal type, not a float.
What you will see when something is wrong
| Status | Code | Meaning |
|---|---|---|
| 401 | invalid_api_key | The key is missing, wrong or revoked. |
| 402 | insufficient_balance | Your balance is lower than the price of the task. |
| 403 | key_quota_exceeded | This key reached its spending limit. |
| 403 | key_disabled | This key has been disabled. |
The full list is in Errors and idempotency.