Authentication

Authentication in the Nooknear API uses a single header: X-API-Key. This page covers how to send the key, where to store it, how to rotate it, and how to retry requests safely with Idempotency-Key.

API key

Each account (tenant) has an API key. It starts with np_ and goes in the X-API-Key header on every request:

curl https://api.nooknear.com/v1/media \
  -H "X-API-Key: np_..."

If the key is missing or invalid, the API returns 401:

{ "error": "UNAUTHORIZED", "message": "Missing API key" }

Today, keys are created by our team when you sign up and sent to you. A web dashboard for managing keys yourself is coming soon. Along with the key you receive your tenantId (account ID), which you use in the /v1/tenants/:tenantId/... endpoints. A key can only access its own tenantId; trying another ID returns 403.

Keep keys on the server

An API key grants full access to every image in your account, including listing, deleting, exporting data and deleting account data. So:

  • Never ship the key to a browser, a mobile app or a public repository. For browser uploads, let your server call upload-request and return only uploadUrl to the client. See the Quickstart for an example.
  • Store the key in an environment variable or a secret manager, and keep it out of your logs.
  • If you want separate accounts for development and production, get in touch. Per-project keys are coming soon.

CDN URLs (https://cdn.nooknear.com/...?token=...) don’t contain your API key, so they’re safe to put in your pages. Details in Variants and CDN.

Rotating keys

If you suspect a key has leaked, or you rotate keys on a schedule, generate a new one:

curl -X PATCH https://api.nooknear.com/v1/tenants/$TENANT_ID/rotate-key \
  -H "X-API-Key: $NOOKNEAR_API_KEY" \
  -H "Idempotency-Key: rotate-2026-12-06"
{ "apiKey": "np_new..." }

Things to know:

  • The old key stops working immediately. There is no grace period, so be ready to update every server as soon as you get the new key.
  • The new key is shown only once. Store it right away.
  • Each rotation is recorded in the audit log as api_key_rotate.
  • The token in CDN URLs is independent of your API key, so rotating the key doesn’t break existing image URLs.

Safe retries with Idempotency-Key

After a network error or a timeout you can’t tell whether the request reached the server. Blindly retrying could, for example, create two assets for the same image. To avoid that, add an Idempotency-Key header:

curl -X POST https://api.nooknear.com/v1/media/upload-request \
  -H "X-API-Key: $NOOKNEAR_API_KEY" \
  -H "Idempotency-Key: 5d1c8f0e-6a8b-4e3e-9f4a-2b7c1d9e0a11" \
  -H "Content-Type: application/json" \
  -d '{"resourceType":"product","resourceId":"42","filename":"cover.jpg","mimeType":"image/jpeg","sizeBytes":534120}'

How it works:

  • The response to the first successful (2xx) request with a given key and URL is stored. If you send it again, the work is not repeated; you get the stored response back.
  • Keys are scoped to your account and to the request URL.
  • Error responses (4xx, 5xx) are not stored, so you can fix the problem and retry with the same key.
  • Today, Idempotency-Key is honored on POST /v1/media/upload-request, DELETE /v1/media/:assetId and PATCH /v1/tenants/:tenantId/rotate-key. On other endpoints the header is harmless but has no effect.

Generate a UUID per logical operation, or use a value that uniquely identifies it (for example product-42-cover-v3). Don’t reuse a key for requests with different bodies.

For a retry strategy, see Errors and limits.