Self-serve API keys, token-based billing, and runtime tool endpoints.
All examples target the production Worker at api.amaimedia.com.
Last updated 2026-07-03.
Every request is authenticated with a bearer token:
Authorization: Bearer amai_live_<secret>
amai_live_… string like a password: never commit it
to source control, never paste it into a chat log, never expose it to a
browser client.
Open the same page and click Revoke. Revocation takes effect on the next request — active requests are not interrupted.
Two runtime endpoints cover the billing flow every tool goes through: check the price and available balance, then spend when the work actually happens. Both are JSON in, JSON out.
Quote a token cost against the caller's current balance. Idempotent, does not charge.
POST https://api.amaimedia.com/api/v1/tools/check
Content-Type: application/json
Authorization: Bearer amai_live_...
{
"tool": "chat",
"units": 1
}
Request
| Field | Type | Notes |
|---|---|---|
tool | string | One of chat, image, voice_clone,
dub, music, sfx,
speech2text, translate. See the live
token cost table. |
units | number | Amount of work. For chat a unit is one turn; for
dub a unit is one minute of source video; for
voice_clone a unit is one generated second. Check the
pricing page for each tool. |
Response
{
"ok": true,
"allowed": true,
"cost_tokens": 5,
"balance_after": 9995
}
Charge the account. Call this after the tool successfully produced
its output. The reference string is your idempotency key —
resending the same (tool, reference) pair will not double-charge.
POST https://api.amaimedia.com/api/v1/tools/spend
Content-Type: application/json
Authorization: Bearer amai_live_...
{
"tool": "chat",
"units": 1,
"reference": "req_2026-07-03_abc123"
}
Response
{
"ok": true,
"charged": 5,
"balance_after": 9990
}
Rate limits are enforced per authenticated identity, not per IP. The current production caps (subject to change; see the roadmap) are:
| Bucket | Limit | Window |
|---|---|---|
Referral read (/referral GET) | 60 req | 60 s |
| Referral apply | 10 req | 60 s |
| OTP / sensitive auth | 20 req | 60 s |
Tool endpoints (/tools/check, /tools/spend)
are gated by your token balance rather than a request-rate cap during the
preview. A per-key request cap will be introduced with the GA release —
see the roadmap.
All errors return a JSON body with ok:false and a stable
error string. HTTP status codes follow standard semantics.
auth_required{ "ok": false, "error": "auth_required" }
Missing, malformed, or revoked bearer token.
insufficient_credits{
"ok": false,
"error": "insufficient_credits",
"cost_tokens": 5,
"balance": 2
}
Top up at amaimedia.com/credits.
forbidden{ "ok": false, "error": "forbidden" }
CSRF mismatch, region blocked (OFAC), or account suspended.
rate_limited{ "ok": false, "error": "rate_limited" }
Back off and retry after the window resets (see §3).
KEY="amai_live_your_secret_here"
# 1. Quote the cost before doing the work.
curl -sS https://api.amaimedia.com/api/v1/tools/check \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{"tool":"chat","units":1}'
# => {"ok":true,"allowed":true,"cost_tokens":5,"balance_after":9995}
# 2. Do the actual tool call in your app.
# 3. Charge, idempotent by reference.
curl -sS https://api.amaimedia.com/api/v1/tools/spend \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{"tool":"chat","units":1,"reference":"req_2026-07-03_abc123"}'
# => {"ok":true,"charged":5,"balance_after":9990}
The runtime tool endpoints are marked v0.1 preview. Shapes are stable enough to build against, but a few pieces are still moving:
/tools/* is rolling out — during the
preview these routes may also accept session-cookie auth from the
dashboard.Track breaking changes on the public roadmap. Every change ships with a dated entry there before the API behavior changes.