Development Guide
The Quick Guide gets one request working. This page covers what changes when the code has to keep working in production.
Two shapes of call
BeatAPI has exactly two request lifecycles, and almost every integration mistake comes from treating one as the other.
Text is synchronous: POST /v1/chat/completions, /v1/responses, /v1/messages, or the Gemini-compatible endpoint returns the result. Everything else accepts the work and hands back an ID.
The asynchronous lifecycle
- Submit —
POST /v1/images/tasks(orvideos,effects,video-analysis,music-video,ecommerce-video). A201means accepted, not finished. - Store the ID — persist
data.idanddata.request_idbefore starting any background work. A crash between the response and the write leaves a task you have paid for and cannot find. - Wait — poll
GET /v1/tasks/{task_id}, or register a webhook. - Read the result — on
succeeded, usedata.output.media. Onfailed, readdata.error_codeand the refund fields.
Polling
Three properties of that loop matter:
- It stops on terminal states, not on a guess about elapsed time. A finished task never changes again.
- It waits
poll_after_seconds. The response states the interval for the task’s kind (today 5, 8 or 10 seconds), so read it instead of choosing your own; a little jitter avoids synchronising polls across concurrent tasks. Polling more often does not make a task finish sooner. - It treats a transient error as “wait”, not “fail”. BeatAPI does not apply the request-rate limit to
GET /v1/tasks/{task_id}, so followingpoll_after_secondsnever earns a429; the loop still retries a429,500or503because none of them says anything about the task. HonourRetry-After. - It has a total timeout of 1800 seconds. The slowest models typically finish in about 400 seconds, so 30 minutes leaves room for queueing. The Quick Guide script uses the same value. When your timeout passes, keep the task ID and poll again later instead of resubmitting: BeatAPI stops a task itself only after its processing window, at most 24 hours.
Music Video tasks have non-terminal states that need a decision rather than more polling — storyboard_ready and requires_action. Treating them as “still working” polls forever. The Quick Guide lists every status and the action each one calls for.
Webhooks instead of polling
Register an endpoint with POST /v1/webhooks and BeatAPI posts the terminal state to it. This removes the polling loop entirely, at the cost of needing a reachable HTTPS endpoint.
Verify the signature against the raw request bytes before parsing JSON — re-serialising the body changes it and the signature will not match. The event carries the same task object as GET /v1/tasks/{task_id}; deduplicate by event id. See Webhooks.
Keep a slow reconciliation poll even with webhooks configured. A delivery can fail; a task that has been in processing for far longer than its model’s normal runtime is worth checking directly.
Errors
Every failure carries a stable error.code, an English message that states the cause, retryable, and a request_id. Log the request_id (also the X-BeatAPI-Request-Id response header) — it identifies the exact call when you contact support.
retryable in the error says the same thing per code, so you can branch on it instead of the status. BeatAPI does not answer 502 or 504; one that reaches you came from the network edge and is retried like a 503. Every code is listed in Errors.
A 500 on a submit is ambiguous: the task may or may not have been created. Resubmitting blindly can pay for the same work twice. Send an Idempotency-Key on task creation and reuse it on the retry — BeatAPI returns the original task instead of creating a second one.
Rate limits
BeatAPI limits how often an account calls. It does not cap how many tasks run at once, and the two cases fail differently.
- Request rate — successful requests per minute for the account, answered with
429 rate_limit_exceeded,Retry-Afterandretry_after_seconds. The allowance rises with lifetime top-ups, and a stricter limit can be attached to an individual key. Your current allowance and the next tier are on the Billing page of the dashboard; there is no public API that returns them. Free models have their own, separate limit; see Free models. - Concurrency — there is no per-account cap on tasks in flight.
GET /v1/usagereportsconcurrency.active(tasks being processed now) and aconcurrency.limitof0, which means no cap. When a model itself is at capacity you do not get a rate-limit error on a task create: it answers503 processing_unavailable, which you retry with backoff. A text call to a model at capacity can answer429 rate_limit_exceeded(“This model is receiving too many requests”).
GET /v1/tasks/{task_id} is not subject to the request-rate limit. The list GET /v1/tasks has a limit of its own: 60 requests per minute for the account, however many API keys it has, answered with 429 rate_limit_exceeded, Retry-After and retry_after_seconds. See List tasks.
Retries that do not cost money
- Retry
429and5xx(every5xxfrom BeatAPI is a500or a503) with backoff. Do not retry400,401,402,403,404, or409— they carryretryable: false. - Use exponential backoff with jitter, and a ceiling.
- Put an
Idempotency-Keyon every task creation so a retried submit cannot double-charge. - After a failed submit, poll before resubmitting if you have an ID.
- Cap total attempts. A permanently failing request retried forever is an outage that bills.
Cost control
- Set an output cap on text calls. Output is the expensive half;
max_tokensis the simplest lever there is. - Match the model to the step. Classification and routing do not need the top tier.
- Watch the tiered models. Most GPT-6 models bill a higher rate above 272K input tokens and Grok above 200,000 tokens (each model’s page says which); the two DeepSeek HC (high-cache) models, on weekdays 09:00–12:00 and 14:00–18:00 Beijing time, and Hunyuan
hy3bill a higher rate during published peak windows, while the regular paid DeepSeek models bill one rate at all hours. A long-running agent or a scheduled batch can cross either line invisibly. Each response’s usage record shows which rate was applied. - One key per component.
by_api_keyinGET /v1/usagethen attributes spend without any work on your side. - Reconcile refunds. A failed task is refunded; if your ledger only records the reservation, your numbers will drift from the invoice.
Before going to production
- Use the exact origins:
https://api.beatapi.iofor tasks, files and capabilities,https://direct.beatapi.iofor text calls. - Keep permanent keys server-side. Browsers get a short-lived Realtime
client_secret, never an API key. - Store
data.idandrequest_idbefore starting background work. - Poll with jitter; stop at terminal or action states.
- Verify webhook signatures against raw bytes.
- Record reservations, settlements, refunds, errors, and final output URLs, and download results within 72 hours of completion.
- Alert on
402— it stops every paid operation on the account at once.

