Documentation menu

Docs

Keys and credentials

Two kinds of key, and the prefix always tells you which one you are holding. A publishable key goes in your web page. A secret key goes on your server. Everything else on this page follows from that one difference.

The two kinds

KeyLooks likeBelongs toWhere it may be usedStored as
Publishablepk_live_…
pk_test_…
one characterA browser, on the domains you listed for that character. Public by design — paste it into your HTML.in clear (we can show it again)
Secretsk_live_…
sk_test_…
your accountYour server, your game build, your kiosk app. Never a browser — a request carrying one together with an Origin header is refused.a hash (shown once, never again)
Older accounts have embed keys that look like ek_…. Those are publishable keys with an older prefix. They keep working exactly as before — there is nothing you have to change.

Why publishable keys are per character, and secret keys per account

A publishable key answers “which character does this page show, and may this page show it?”. Both halves of that question belong to the character: it is the character that has a name, a persona and a list of allowed domains. Two characters means two keys with two allowlists, and revoking one never touches the other.

A secret key answers a different question — “is this caller the account?” — and there is no browser and no domain involved, so there is nothing character-shaped about it. It is an account credential. You may still pin one to a character (then /api/chat always speaks as that character), and you can override that per request with avatarId.

Using them

In the browser
<!-- Publishable key: safe in a page anyone can read. -->
<script src="https://live2d.noiselimited.com/v1/nikoori.js" data-key="pk_live_your_key"></script>
On a server, in a game, in a kiosk
# Secret key: on your server, in your game build, in your kiosk app — never in a page.
curl https://live2d.noiselimited.com/api/chat \
  -H "Authorization: Bearer sk_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"Do you ship to Japan?"}]}'

A secret key travels in the Authorization header and nowhere else. Putting one in a URL is refused with 400 secret_key_in_url, because URLs end up in logs, proxies and Referer headers — by the time it is in a URL it has already leaked.

What a secret key in a page gets
# The same secret key, sent from a browser. Always refused, whatever else is right.
HTTP/1.1 403 Forbidden
{"error":"browser_origin",
 "message":"A secret key may not be used from a browser — anyone viewing the page could read it. …"}

Test mode

Every key has a live and a test version. A pk_test_ or sk_test_ key behaves exactly like its live twin — same character, same domain rules, same rate limits — with one difference:

  • test traffic is not counted against your plan's monthly allowance;
  • test traffic is not recorded in analytics, so your dashboard numbers stay true;
  • the character never “rests” on a test key, because there is no allowance to run out of.

Chat still calls your own AI provider with your own key, so your provider still bills you for the tokens. Test mode is about our meter, not theirs. Use a test key on staging, in CI and on your own machine.

Everything that answers a key tells you which mode it was in, in the X-Nikoori-Key-Mode response header, and the dashboard badges every key.

If a key leaks

A publishable key

Usually nothing to do. It is meant to be public; a copy of it only works on the domains you listed. Check that list first. Rotate it if you want the copies to stop working — see below.

A secret key

Act. A secret key is your account: it can chat on your AI key and download your character files. Rotate it, do not revoke it — revoking is instant and total, so it takes your own integration down at the very moment you are trying to fix things.

  1. Rotate the key in the dashboard, choosing how long the old one should keep working.
  2. Copy the new secret. It is shown once.
  3. Deploy it wherever the old one lives.
  4. If the key is already in someone else's hands, rotate with a grace period of 0 hours — that is a revoke with a replacement, and the old key dies immediately.
  5. Then check your characters for the period the key was out, and rotate your AI provider's key too if the chat scope was on it.

Rotation

Rotation issues a new key first, and you choose how long the old one keeps working: never (it stops the moment you rotate) or 1 hour, 24 hours, 72 hours. The default is never, because the reason people rotate is that a key is somewhere it should not be — a grace period answers the planned replacement, which is the rarer case. Choose one when you are rotating on a schedule and need a release to go out before the old key stops.

Rotating a secret key
# 1. Rotate. The new secret is in this response and nowhere else.
POST https://live2d.noiselimited.com/api/keys/<id>/rotate   {"graceHours": 24}

# 2. Both keys work now. Deploy the new one wherever the old one lives.
#    Every response on the old key carries the deadline:
X-Nikoori-Key-Rotated: true
X-Nikoori-Key-Expires: 2026-09-23T09:00:00.000Z

# 3. When the grace period ends, the old key answers 401 key_expired. Nothing to clean up.

Publishable keys rotate the same way, from the character's own Security page. With a grace period the old key keeps serving your existing pages while you deploy the new snippet — worth choosing when the key is in HTML you cannot redeploy in one minute, and worth skipping when the key has already got out.

While a key is in its grace period every response it gets carries X-Nikoori-Key-Rotated: true and X-Nikoori-Key-Expires. If you log response headers anywhere, that is your alarm for a deploy that did not land. After the deadline the old key answers 401 key_expired with a sentence saying so.

What a secret key may do

Scopes are chosen when you create the key and cannot be widened afterwards (rotation keeps the same scopes). Give each integration only what it needs.

ScopeAllows
chatPOST /api/chat — send messages and stream the reply.
modelsGET /api/models/:id — download the character files your plan includes.
Two scopes, and that is the whole list. There was a third, analytics, and it was checked by no endpoint at all — a key that carried it could call nothing. We have withdrawn it rather than leave a box you could tick and build against. Keys minted before the change still show it and it still grants nothing; their other scopes are unaffected. Read your numbers in the dashboard for now. When there is a real endpoint behind it, the scope comes back in the same release.

Every refusal, and what it means

StatuserrorWhat happened
401missing_authorizationNo bearer token. Send the secret key in the Authorization header.
401malformed_keyNot one of our keys. Ours are `sk_live_<id>_<secret>`.
401invalid_keyUnknown key, or the wrong secret. The same answer for both, deliberately.
401key_revokedYou turned this key off. Create a new one.
401key_expiredRotated, and the grace period is over. Use the key that replaced it.
403browser_originA secret key arrived with an Origin header. Use your publishable key in the browser.
403insufficient_scopeThe key is valid but was not given this scope.
403origin_not_allowedA publishable key used on a domain that is not on the character.
403key_rotatedA publishable key whose grace period has ended. Update your snippet.
400secret_key_in_urlA secret key in a query string. Treat it as leaked and rotate it.
429rate_limitedToo many requests for this key this minute. Retry-After says when.

The short version

  • pk_ in the page, sk_ on the server. If it is in HTML it must start with pk_.
  • A publishable key belongs to a character; a secret key belongs to your account.
  • _test_ never touches your plan counters or your analytics.
  • A secret key that leaked is rotated, not revoked — unless someone already has it, then rotate with 0 hours.
  • We show a secret once. We store a hash, so we could not show it again if we wanted to.