If you have ever wired up more than one generative model, you already know the painful part is not the prompt. It is the plumbing: a new key for every vendor, a different request body for video versus images, and a billing model that may be a monthly plan you barely use. NanoAPI takes a simpler shape: one API key, one prepaid USD balance that never expires, and one asynchronous task API for every live model.
This walkthrough follows the public Quickstart. It covers creating a task with POST /v1/tasks, polling GET /v1/tasks/{task_id}, and verifying a signed webhook. Model-specific fields beyond the official examples are left out on purpose; always check the model page in the docs before you send a payload.
What you need
- An API key from Console → API keys. The full key is shown once and starts with
nf_. Keep it on the server. Do not put it in frontend code or commit it to git. - A prepaid balance in the console. There is no subscription. Failed tasks are not charged; the frozen amount is returned.
- The base URL:
https://api.nanoapi.ai/v1. Authenticate withAuthorization: Bearer $NANOAPI_API_KEY.
As of 13 November 2026, video starts from $0.039 per second (Wan 3.0) and images from $0.0117 per image (GPT Image 2.5 / 2.6). Full tables live on the pricing page and may change.
Create a task: POST /v1/tasks
Every model uses the same endpoint. You choose the model with model. The call returns a task id immediately; generation runs in the background. Shared body fields documented for every model are model (required), optional webhook_url, and num_outputs (required for image models, 1–4; omit it for video and editing models). Fields such as mode, prompt, video_url, and image_urls depend on the model and are listed on that model's page.
The official quickstart example is Genjutsu 1.0 motion transfer: one public photo URL plus one source video URL.
curl https://api.nanoapi.ai/v1/tasks \
-H "Authorization: Bearer $NANOAPI_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 5f0c8a2e-3b7d-4c1a-9e6f-2d8b4a1c7e90" \
-d '{
"model": "genjutsu-1.0",
"mode": "motion_control",
"image_urls": ["https://example.com/person.png"],
"video_url": "https://example.com/dance.mp4",
"resolution": "720p",
"webhook_url": "https://example.com/hooks/nanoapi"
}'
A successful create response looks like this (the created_at value below is the example from the docs, not a live timestamp):
{
"code": 200,
"message": "success",
"data": {
"object": "task",
"id": "tk_01jb8z5q4w3e2r1t0y9u8i7o6p",
"model": "genjutsu-1.0",
"status": "queued",
"error": null,
"created_at": "2026-10-22T08:30:00Z"
}
}
Store data.id. Send an Idempotency-Key (ideally a UUID, 1–255 characters) when you create the task so a retry after a timeout does not open a second task.
Other live models use the same endpoint and a different model string, for example kling-4.0, seedance-2.5, veo-3.1, wan-3.0 for video, or nano-banana-2.1, gpt-image-2.6, seedream-5.0-pro for images. Copy the request fields from that model's documentation rather than guessing.
Poll for the result
If you did not set webhook_url, poll GET /v1/tasks/{task_id} at most once every 15 seconds until status is succeeded or failed.
curl https://api.nanoapi.ai/v1/tasks/tk_01jb8z5q4w3e2r1t0y9u8i7o6p \
-H "Authorization: Bearer $NANOAPI_API_KEY"
When data.status is succeeded, download data.outputs[0].url (image models return one item per generated image). data.billing.charged is the amount billed, as a decimal string. Result files are kept for 15 days, then the links return 404, so copy anything you need to your own storage. When the task fails, read data.error.type; nothing is charged.
Signed webhooks (better in production)
Set webhook_url on create (HTTPS only, up to 2048 characters, no private or loopback addresses). NanoAPI sends a POST when the task finishes, with the same JSON body as the retrieve endpoint, so one parser can handle both. Nothing is sent when generation starts; if you need progress, poll the GET endpoint.
The request follows Standard Webhooks. Headers include webhook-id (stable across retries; deduplicate on it), webhook-timestamp (Unix seconds for that attempt), and webhook-signature. A 2xx within 15 seconds counts as delivered. Undelivered calls are retried up to three times. If nothing arrives 60 minutes after you created the task, fetch it once with GET.
Signature verification is optional but recommended if the webhook triggers anything important. The signing secret starts with whsec_ and is viewed in Console → Webhooks. The official algorithm is: signed content {webhook-id}.{webhook-timestamp}.{raw body}; key is the whsec_ prefix stripped and base64-decoded; HMAC-SHA256, then base64. Accept the request if any space-separated v1 signature matches (constant-time compare). Reject timestamps more than five minutes off. Verify the raw body; re-serializing JSON will break the signature.
import base64, hashlib, hmac, time
def verify_webhook(secret: str, headers: dict, body: bytes) -> bool:
msg_id = headers["webhook-id"]
timestamp = headers["webhook-timestamp"]
if abs(time.time() - int(timestamp)) > 300:
return False
key = base64.b64decode(secret.removeprefix("whsec_"))
signed = f"{msg_id}.{timestamp}.".encode() + body
expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
for item in headers["webhook-signature"].split(" "):
version, _, signature = item.partition(",")
if version == "v1" and hmac.compare_digest(signature, expected):
return True
return False
Handle a webhook by verifying the signature, returning 2xx immediately, skipping a webhook-id you already processed, then branching on data.status.
A few billing and product notes
The playground on the site uses the same prices and the same balance as the API. Video is billed per second, images per image. Outputs may be used commercially, subject to the Terms of Service. NanoAPI states that it does not use your content to train AI models. Audio and more models are on the way, on the same key and balance; they are not live yet, so do not build as if they already were.
That is the whole loop: one create call, then poll or a signed webhook, and a file URL that lasts fifteen days. Start with the docs and keep the pricing page open when you estimate cost.
Top comments (0)