Pinin API reference
Restore, colorize and upscale photographs programmatically. One credit per image, charged when the job settles, refunded when it fails.
Quickstart
Four steps from zero to a restored file. The first three take a few minutes; the fourth is a poll or a webhook, depending on how you like to work.
- 1
Create an API key
Open the console, create a key and copy it — it is shown once. Give it the scopes the integration needs and, for anything customer-facing, a monthly credit cap.
- 2
Submit an image
Send a public image URL. Multipart uploads and base64 work too, if you would rather not host the file.
bashcurl -X POST https://pinin.ai/api/v1/restorations \ -H "Authorization: Bearer $PININ_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "image_url": "https://example.com/family-photo.jpg", "mode": "all-in-one" }' - 3
Wait for it to settle
Poll the job, or register a webhook and stop polling entirely. Most restorations finish in under a minute.
typescript// Poll until the job settles, then download the restored file. // The API sends Retry-After on every response, so back off the way it asks. async function waitFor(id: string) { let delay = 2; for (;;) { const res = await fetch(`https://pinin.ai/api/v1/restorations/${id}`, { headers: { Authorization: `Bearer ${process.env.PININ_API_KEY}` }, }); const job = await res.json(); if (job.status === "completed") return job.images.restored.url; if (job.status === "failed") throw new Error(job.error.message); delay = Math.min(Number(res.headers.get("retry-after")) || delay * 2, 30); await new Promise((r) => setTimeout(r, delay * 1000)); } } - 4
Download the result
The job carries signed URLs for the original and the restored image. They last at least an hour; re-fetch the job for a fresh link.
const res = await fetch("https://pinin.ai/api/v1/restorations", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.PININ_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
image_url: "https://example.com/family-photo.jpg",
mode: "all-in-one",
}),
});
const job = await res.json();
console.log(job.id, job.status);import os, requests
job = requests.post(
"https://pinin.ai/api/v1/restorations",
headers={"Authorization": f"Bearer {os.environ['PININ_API_KEY']}"},
json={"image_url": "https://example.com/family-photo.jpg", "mode": "all-in-one"},
timeout=60,
).json()
print(job["id"], job["status"])Authentication
Every request carries a key in the Authorization header. Keys are hashed at rest, so a lost key is rotated, never recovered.
Authorization: Bearer pnn_live_<key>A key can only do what its scopes allow:
| restorations:read | Fetch jobs, statuses and download links. |
| restorations:write | Submit images and spend credits. |
| usage:read | Account details, limits and usage analytics. |
| webhooks:manage | Create, edit, test and inspect endpoints. |
| keys:manage | Create, rotate, edit and revoke API keys. |
Credits and limits
One image costs one credit, whatever the mode. Credits come from the Enterprise plan (1,500 every month) and are shared with the web app — the API is another way to spend the same balance, not a separate wallet.
A job is charged when it settles and refunded automatically when it fails. A request that is rejected before it enters the queue costs nothing.
Enterprise allows 500 photos per fifteen-minute batch and 24 restorations in flight. Anything beyond that queues server-side and starts as capacity frees up — it does not fail.
Each key has its own requests-per-minute limit and an optional monthly credit cap, so a compromised key cannot drain the account.
Rate limits
Each key has its own ceiling in requests per minute. Every response carries the three `X-RateLimit-*` headers, and a `429` adds `Retry-After` in seconds.
| Header | Meaning |
|---|---|
| X-Request-Id | The unique id for this request. Quote it when you contact support. |
| X-Pinin-Api-Version | The API version that served the request. |
| X-RateLimit-Limit / X-RateLimit-Remaining / X-RateLimit-Reset | Calls left in the current minute, and the second the window resets. |
| Retry-AfterX-Pinin-Credits-Balance | Seconds to wait before retrying, and the balance left on the account after auth. |
| X-Client-Request-Id | Echo of the `X-Request-Id` you sent, so your own logs can be joined to ours. |
The plan's batch cap counts restorations admitted in the last fifteen minutes. It is separate from the per-minute limit and answers 429 `batch_limit_reached`.
Idempotency
A retried submit must not cost a second credit. Send an `Idempotency-Key` header — a UUID is fine — and the first call wins: every retry returns the jobs that call created, marked `Idempotent-Replay: true`.
The key covers a whole batch, not a single image, so a retried batch of fifty returns the same fifty jobs instead of a second fifty.
A duplicate that arrives while the first call is still uploading answers `409 idempotency_in_progress` with `Retry-After: 2`. That is not an error to fix: wait, then retry the same key.
A settled key keeps answering for seven days. An unsettled one blocks retries for five minutes — longer than an edge call can live — and is then released, so a crashed request cannot lock a key forever.
Reusing a key with different content answers `422 idempotency_key_reused` rather than silently returning the older jobs, which is how a mismatched key stops being a mystery.
curl -X POST https://pinin.ai/api/v1/restorations \
-H "Authorization: Bearer ***" \
-H "Idempotency-Key: 8f2a1c6e-1d4b-4f0a-9c31-2f7be0a51d18" \
-H "Content-Type: application/json" \
-d '{ "images": ["https://example.com/a.jpg", "https://example.com/b.jpg"] }'Data retention
Uploaded and restored images are deleted 30 days after submission. Every job carries `expires_at`, so you can schedule your own copy before it goes, and an expired job answers `410 restoration_expired` rather than a bare 404.
The storage that backs a job is shared, so under heavy load the oldest files may be reclaimed earlier than `expires_at`. If a file matters, download it when the job settles — that is what the webhook is for.
Signed image links are valid for at least an hour; the URL in a webhook payload may already be stale by the time you read it, so fetch the job for a fresh link.
Accounts, keys and usage records are kept for billing. Webhook delivery logs are kept so an event can be redelivered long after it was sent.
Deleting an API key stops its access immediately but does not touch your restorations or your history.
Restoration modes
| Mode | What it does | Credits |
|---|---|---|
| all-in-one | Full restoration. Repairs damage, scratches, fading and blur, then returns a clean high-resolution image. | 1 |
| dust-scratch | Dust and scratch removal. Removes dust, speckling and scratches without altering tone or grain. | 1 |
| colorize | Colorization. Adds natural colour to black-and-white photographs. | 1 |
| deblur-upscale | Deblur and upscale. Recovers soft focus and detail, then enlarges the image. | 1 |
| upscale-only | Upscale. Enlarges the image with detail-preserving upscaling and no restoration pass. | 1 |
Endpoints
All paths are relative to https://pinin.ai/api/v1.
This page and the machine-readable contract come from one source: download openapi.json for Postman, Insomnia or an SDK generator. It needs no key.
Pin a version with the X-Pinin-Api-Version header: a version we no longer serve answers 400 unsupported_version with the supported list, instead of changing shape under you without a word.
/healthHealth check
Reports whether the API and its database can serve requests. No key is required, so a load balancer or an uptime monitor can call it.
{
"status": "ok",
"version": "2026-11-26",
"time": "2026-11-26T20:10:16.188Z",
"retention_days": 30,
"checks": { "database": { "ok": true, "latency_ms": 12 } }
}- `status` is `ok` when every check passed and `degraded` otherwise; a degraded answer is HTTP `503` so a monitor can alert on the status code alone.
- `retention_days` is the same number `expires_at` is computed from, so a client never has to hard-code it.
/restorationsrestorations:writeCreate a restoration
Queue one image or a batch for restoration. Every image costs one credit and is charged when the job settles; a failed job is refunded automatically.
| image_url | string | Public https URL of the image to restore. |
| images | string[] | object[] | Up to 100 images per request, as URLs or objects with `image_url`. Your plan's batch cap applies across requests. |
| image_base64 | string | Inline image as base64 or a data URL (single image). |
| mime_type | string | Content type when you send `image_base64`, for example `image/jpeg`. |
| mode | string | One of the five modes. Defaults to `all-in-one`. |
| seed | integer | Deterministic output: the same seed and image give the same result. |
| idempotency_key | string | Repeat-safe submit for one image or a batch. A repeat returns the jobs the first call created. |
| metadata | object | Your own JSON object, up to 2 KB. Returned on the job and echoed in webhook payloads. |
| dry_run | boolean | Validate and price the request without spending credits. |
{
"object": "restoration",
"id": "0b04150b-f216-4284-b77a-be1b1e0c373e",
"status": "pending",
"mode": "all-in-one",
"credits": 0,
"images": {
"original": { "url": "https://images.pinin.ai/...", "expires_in": 3600 },
"restored": null
}
}- Two doors, both locked: an account needs an active Enterprise plan **and** a positive credit balance. Either one failing answers `403 api_requires_enterprise` or `402 insufficient_credits` before the request is read.
- Multipart uploads are accepted: send the image in a `file` field with `mode` and `metadata` as form fields.
- Reuse the same `Idempotency-Key` header (or `idempotency_key`) to retry a submit without paying twice. The key covers a whole batch, and a duplicate that arrives mid-flight answers `409 idempotency_in_progress`.
- A batch reports every image: `data` holds what was queued, `failures` holds what was refused and why, and `batch` summarises the totals.
- The response carries `Retry-After: 2`, so a poller knows how soon to ask again.
/restorations/:idrestorations:readRetrieve a restoration
Read one job. Poll this while `status` is `pending` or `processing`, or listen for the webhook instead of polling.
{
"object": "restoration",
"id": "0b04150b-f216-4284-b77a-be1b1e0c373e",
"status": "completed",
"mode": "all-in-one",
"credits": 1,
"metadata": { "order_id": "A-10231" },
"expires_at": "2027-02-24T20:10:16.188Z",
"completed_at": "2026-11-26T20:10:16.188Z",
"images": {
"original": { "url": "https://images.pinin.ai/...", "expires_in": 3600 },
"restored": { "url": "https://images.pinin.ai/...", "expires_in": 3600 }
},
"share_url": null
}- Signed image URLs are valid for at least an hour. Re-fetch the job for a fresh link.
- Images are retained for 30 days from submission; `expires_at` says exactly when this job's files are deleted, and an expired job answers `410 restoration_expired`.
- A job that is still `pending` answers in milliseconds. Poll no faster than `Retry-After` suggests.
- The response carries a weak `ETag`. Send it back as `If-None-Match` while polling: an unchanged job answers `304` with no body, so a tight poll loop costs nothing.
/restorationsrestorations:readList restorations
Newest first, cursor paginated. `next_cursor` is the `created_at` value to pass back as `created_before`.
| limit | integer | Page size, 1–100. Default 20. |
| status | string | `pending`, `processing`, `completed` or `failed`. |
| created_before | ISO 8601 | Cursor from the previous page (`next_cursor`). |
| created_before_id | uuid | Tiebreaker for the cursor (`next_cursor_id`), so a shared millisecond cannot skip a job. |
| mode | string | Only jobs run in this mode. |
| updated_since | ISO 8601 | Only jobs touched at or after this instant. This is the sweep a polling client runs to reconcile what it missed. |
{
"object": "list",
"data": [ { "object": "restoration", "id": "..." } ],
"has_more": false,
"next_cursor": null,
"next_cursor_id": null
}/restorations/:id/downloadrestorations:readDownload the image
Redirects to a short-lived signed URL. Pass `?image=original` for the source file.
| image | string | `restored` (default) or `original`. |
HTTP/1.1 302 Found
Location: https://images.pinin.ai/<key>?exp=<unix>&sig=<hmac>/restorations/:id/cancelrestorations:writeCancel a restoration
Cancels a job that has not started. A queued job has not been charged, so cancelling costs nothing; once the pipeline has picked it up the job cannot be stopped.
{
"object": "restoration",
"id": "0b04150b-f216-4284-b77a-be1b1e0c373e",
"status": "failed",
"error": { "code": "cancelled", "message": "Cancelled by the customer." }
}- Only `pending` jobs can be cancelled. `409 too_late_to_cancel` means a credit is already spent on the work.
- Cancelling emits `restoration.failed` with `error_code: cancelled`, so a webhook receiver learns about it without polling.
/accountusage:readAccount and limits
Plan, credit balance, batch cap, concurrency and the limits of the calling key. Stays readable when the balance is empty, so a blocked account can see why it is blocked.
{
"object": "account",
"plan": { "tier": "enterprise", "status": "active", "credits": 998 },
"limits": { "batch_cap": 500, "concurrency": 24, "requests_per_minute": 120 }
}/usageusage:readUsage analytics
Requests, errors, restorations and credits per day, plus the current month by key. Pass `?days=` (1–90, default 30) to choose the window.
{
"object": "usage",
"totals": { "requests": 412, "errors": 3, "restorations": 120, "credits": 120 },
"monthly": { "period": "2026-11", "credits_used": 120, "restorations": 120, "credits_balance": 880 },
"by_key": [ { "id": "...", "name": "Production", "credits_this_month": 120, "restorations_this_month": 120 } ],
"daily": [ { "day": "2026-11-26", "requests": 12, "restorations": 4, "credits": 4 } ]
}/modesrestorations:readAvailable modes
The restoration modes this account can request, with a description of each.
{ "object": "list", "data": [ { "id": "colorize", "name": "Colorization", "credits": 1 } ] }/keyskeys:manageList API keys
Every key on the account with its scopes, limits, last use and this month's spend. Secrets are never included.
{
"object": "list",
"data": [
{ "object": "api_key", "id": "...", "key_prefix": "pnn_live_e5020b1…", "credits_this_month": 120, "restorations_this_month": 120 }
]
}/keys/:idkeys:manageRetrieve an API key
One key, including whether it is revoked and what it has spent this month.
{ "object": "api_key", "id": "...", "scopes": ["restorations:read"], "revoked_at": null }/keyskeys:manageCreate an API key
Mints a key. The plaintext is returned once and never again — store it immediately.
| name* | string | A label you will recognise later. |
| scopes | string[] | Defaults to read + write on restorations. |
| rate_limit_per_minute | integer | 1–300. Default 60. Calls above this are refused, not clamped. |
| monthly_credit_cap | integer | Hard ceiling on credits this key may spend per month. |
| expires_in_days | integer | Optional expiry, up to 730 days. |
{
"object": "api_key",
"id": "78b960cd-547d-4665-9cc7-8b015d6b1899",
"key_prefix": "pnn_live_e5020b1…",
"api_key": "pnn_live_...",
"warning": "Store this key now. It cannot be shown again."
}/keys/:id/rotatekeys:manageRotate an API key
Revokes the key and mints a replacement with the same scopes and limits.
{ "object": "api_key", "id": "...", "api_key": "pnn_live_...", "replaced_key_id": "..." }/keys/:idkeys:manageUpdate an API key
Change a key's label, scopes, expiry, per-minute limit or monthly credit cap. Narrowing scopes takes effect on the next request, so this is the way to cut a key's power during an incident without re-issuing its secret.
| name | string | New label. |
| scopes | string[] | The scopes the key may use. Must be a non-empty subset of the published list. |
| expires_in_days | integer | null | Days from now until the key stops working (max 730), or `null` to remove the expiry. |
| rate_limit_per_minute | integer | 1–300 requests per minute for this key. |
| monthly_credit_cap | integer | null | New ceiling, or `null` to remove it. |
{ "object": "api_key", "id": "...", "rate_limit_per_minute": 240 }/keys/:idkeys:manageRevoke an API key
Revokes a key immediately. Requests that use it start failing with `401 revoked_api_key`.
{ "object": "api_key", "id": "...", "revoked": true }/webhookswebhooks:manageList webhook endpoints
Every endpoint on the account, with its events, active state and recent failure count.
{
"object": "list",
"data": [ { "object": "webhook_endpoint", "id": "...", "url": "https://example.com/hook", "active": true, "failure_count": 0 } ]
}/webhookswebhooks:manageCreate a webhook endpoint
Registers an https endpoint for `restoration.completed` and `restoration.failed`. Deliveries are signed and retried with exponential backoff for six attempts.
| url* | string | Your https endpoint. |
| events | string[] | Subset of the two event types. Defaults to both. |
| description | string | Optional label. |
{
"object": "webhook_endpoint",
"id": "de9cd18e-e73e-4d14-90c6-0f50a3493259",
"signing_secret": "whsec_...",
"events": ["restoration.completed", "restoration.failed"]
}/webhooks/:idwebhooks:manageUpdate a webhook endpoint
Change the URL, the subscribed events or the description, or pause delivery with `active: false`.
| url | string | New https endpoint. |
| events | string[] | Non-empty subset of the event types. |
| active | boolean | `false` pauses delivery without deleting the endpoint. |
| description | string | New label. |
{ "object": "webhook_endpoint", "id": "...", "active": false }/webhooks/:idwebhooks:manageDelete a webhook endpoint
Removes the endpoint and stops future deliveries. The delivery log is kept for your records.
{ "object": "webhook_endpoint", "id": "...", "deleted": true }/webhooks/:id/testwebhooks:manageSend a test event
Delivers a signed `webhook.test` event right now and returns your endpoint's response.
{ "object": "webhook_test", "delivered": true, "response_status": 200 }/webhooks/:id/rotate-secretwebhooks:manageRotate a signing secret
Issues a new `whsec_` secret for the endpoint and retires the old one. Queued deliveries signed with the previous secret are failed rather than sent unverifiable.
{ "object": "webhook_endpoint", "id": "...", "signing_secret": "whsec_..." }- Update your receiver before rotating: the old secret stops verifying immediately.
/webhooks/:id/deliverieswebhooks:manageDelivery log
Delivery attempts for an endpoint, newest first, with response codes and errors.
| limit | integer | Page size, 1–100. Default 20. |
| before | ISO 8601 | Cursor from the previous page. |
{
"object": "list",
"data": [ { "event": "restoration.completed", "status": "delivered", "response_status": 200 } ],
"has_more": false,
"next_cursor": null
}/webhooks/:id/deliveries/:delivery_id/redeliverwebhooks:manageRedeliver an event
Sends a stored delivery again, with the same signed payload and event id, and returns the response your endpoint gave this time.
{ "object": "webhook_delivery", "id": "...", "status": "delivered", "attempts": 1, "response_status": 200 }- A redelivery restarts the retry curve, so it can be retried six more times if it fails again.
Webhooks
Register an https endpoint and receive a signed POST when a job settles. Failed deliveries are retried with exponential backoff, six attempts in total.
| restoration.completed | The restored image is ready to download. |
| restoration.failed | Processing failed; the credit was refunded automatically. |
{
"id": "evt_9f2c...",
"type": "restoration.completed",
"created_at": "2026-11-26T20:12:43Z",
"data": {
"restoration_id": "51efde58-70f3-42b0-916d-74f1c8cf69c2",
"status": "completed",
"mode": "colorize",
"order_number": "API-20261126-337B981565",
"error_code": null,
"error": null,
"settled_at": "2026-11-26T20:12:43Z"
}
}Verify the signature before trusting the body. The header is t=<unix>,v1=<hmac> and the signed string is the timestamp, a dot, then the raw body. Reject a timestamp more than five minutes old.
Redirects are not followed: an endpoint that answers 3xx is recorded as a failure, so a misconfiguration cannot bounce our signed request somewhere you did not register.
The delivery log keeps every attempt. Rotate the signing secret from the API when you need to, and redeliver any stored event without asking support to replay it.
// Verify the signature before trusting the payload.
import crypto from "node:crypto";
export function verifyPininSignature(rawBody: string, header: string, secret: string) {
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
const expected = crypto
.createHmac("sha256", secret)
.update(`${parts.t}.${rawBody}`)
.digest("hex");
// A replayed old delivery is not a new event.
if (Math.abs(Date.now() / 1000 - Number(parts.t)) > 300) return false;
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}Errors
Errors are JSON with a machine-readable code and a request id. Quote the request id in support — it ties the failure to the exact call.
{
"error": {
"type": "invalid_request_error",
"code": "invalid_mode",
"message": "Unknown mode \"nope\". Supported modes: all-in-one, dust-scratch, colorize, deblur-upscale, upscale-only.",
"param": "mode",
"request_id": "req_c05074ff1005e5a5246bf13d"
}
}| 400 empty_file | The uploaded file was empty. |
| 400 image_unreachable | The URL could not be fetched, or does not point at an image. |
| 400 invalid_cursor | `created_before` / `before` is not an ISO timestamp. |
| 400 invalid_expiry | `expires_in_days` is not a positive number. |
| 400 invalid_idempotency_key | The Idempotency-Key is not 1–128 characters of printable ASCII. |
| 400 invalid_json | The request body is not valid JSON. |
| 400 invalid_metadata | `metadata` is not an object, has more than 20 keys, or is larger than 2 KB. |
| 400 invalid_mode | `mode` is not one of the five modes; `GET /modes` lists them. |
| 400 invalid_name | A name (key, webhook) is empty or longer than 60 characters. |
| 400 invalid_rate_limit | `rate_limit_per_minute` is outside 1–300. |
| 400 invalid_monthly_cap | `monthly_credit_cap` is outside 1–100000, and not null. |
| 429 account_rate_limit_exceeded | The account is at its 600 requests-per-minute ceiling across every key. |
| 400 invalid_seed | `seed` is not an integer. |
| 400 invalid_status | `status` is not pending, processing, completed or failed. |
| 400 invalid_url | The URL is not https, resolves to a private address, or was refused. |
| 400 no_images | The request carried no image. |
| 400 nothing_to_update | A PATCH carried no field it can change. |
| 400 too_many_images | More than 100 images in one request. |
| 400 unknown_event | An event name is not `restoration.completed` or `restoration.failed`. |
| 400 unknown_scope | A scope name is not in the published list. |
| 401 expired_api_key | The key passed its `expires_at`. |
| 401 invalid_api_key | The key is unknown, revoked or expired. |
| 401 missing_api_key | No `Authorization: Bearer` header was sent. |
| 401 revoked_api_key | The key was revoked. Create a new one. |
| 402 insufficient_credits | The balance cannot cover this request — or is zero, in which case the whole API is closed except `/account` and `/usage`. Top up to continue. |
| 402 monthly_key_cap_reached | This key hit its own monthly credit cap. |
| 403 api_requires_enterprise | The subscription is not an active Enterprise plan. |
| 403 insufficient_scope | The key does not hold the scope this route needs. |
| 403 subscription_inactive | The plan is not active, so the API is closed to it. |
| 404 delivery_not_found | No webhook delivery with that id. |
| 404 image_not_found | The image is no longer stored for that job. |
| 404 key_not_found | No API key with that id on this account. |
| 404 restoration_not_found | No restoration with that id on this account. |
| 404 unknown_route | No route matches that method and path. Check the version prefix. |
| 404 webhook_not_found | No webhook endpoint with that id. |
| 409 already_completed | The job already finished; there is nothing to cancel. |
| 409 already_failed | The job already failed; there is nothing to cancel. |
| 409 delivery_in_flight | That webhook delivery is being sent right now. |
| 409 idempotency_in_progress | A request with this Idempotency-Key is still running. Retry shortly. |
| 409 key_limit_reached | The account already holds the maximum number of keys. |
| 409 not_ready | The image is not finished yet; nothing to download. |
| 409 too_late_to_cancel | The job is already processing, so it cannot be cancelled. |
| 409 webhook_limit_reached | The account already holds the maximum number of endpoints. |
| 410 restoration_expired | The retention window passed and the files were deleted. Submit the image again. |
| 413 file_too_large | An image is larger than 20 MB. |
| 413 payload_too_large | The request body is larger than 64 MB. Split the batch or send URLs. |
| 415 unsupported_media_type | The file is not a JPEG, PNG, WebP, GIF, TIFF, BMP, HEIC or AVIF image. |
| 422 idempotency_key_reused | This Idempotency-Key was already used for a different request. Use a new key. |
| 429 batch_limit_reached | The plan's per-batch cap was reached. Wait for the queue to drain. |
| 429 rate_limit_exceeded | This key exceeded its requests-per-minute limit. |
| 500 internal_error | Our fault. Keep the request_id for support. |
| 502 fetch_failed | We could not fetch an image from the URL you sent. |
| 502 queue_failed | The job could not be queued. Safe to retry with the same Idempotency-Key. |
| 502 upload_failed | Storing your image failed. Safe to retry. |
| 503 rate_limiter_unavailable | The limiter is briefly unavailable; retry with backoff. |
| 503 service_unavailable | A dependency is briefly unavailable. Retry with backoff. |
| 504 image_timeout | Fetching the image took longer than our 20-second budget. |
Create a key and send your first image in the console.