Skip to content
← Changelog
2.2.122
Feature

Leaked-key protection

Starting today, a key whose spend stops looking like its own history is held to a lower request rate, and an exposed key can be revoked in one step with a notice to its owner.

A stolen key now costs you less while you look into it, and there is nothing to turn on: every key is measured against its own history. The same release lets you revoke a key for good in one step, check a new key's format offline, and cap the worst case in advance with per-key limits.

A key that stops looking like itself is slowed

A leaked key is usually found by the bill. Apertis now measures each key's spend against that key's own history and reacts before the bill arrives. A key is flagged when:

  • its spend rate jumps far above its own recent peak,
  • it starts spending after a long silence, or
  • it was created moments ago and is already spending heavily.

A flagged key is held to a reduced per-key request rate for up to one hour. The hold is deliberately the smallest thing that limits the damage:

During a hold
The flagged keyrequests over the reduced rate answer HTTP 429; requests under it are served normally
Your other keysunaffected
Your balance, limits and settingsuntouched
The key itselfnot disabled and not revoked
Ending the holdautomatic; nothing to appeal or re-enable

A client that already retries on 429 with backoff needs no change. If one key returns sustained 429s while its siblings are fine, open Logs, filter by that key, and look at what it has been asked to do in the last hour.

The baseline is per key, so a batch job that spends a lot every night is that key's normal and is left alone.

Revoke a key for good

Disabling a key was always reversible, which is the wrong property for a key someone else holds. Revoking a key is a separate, terminal state.

The API Keys list filtered to Status: Revoked: one key, shown as Revoked, with its last use
  • Immediate. Requests with a revoked key are refused with 401 from the moment you confirm. The answer is the same one an unknown key gets, so it tells a stranger nothing.
  • Permanent. No path sets a revoked key back to enabled: not Enable, not Rotate, not an API call. Its history stays readable under Status: Revoked until you delete it.
  • Rotation without downtime. Rotate creates the replacement and lets you keep the old key working for a period you choose, or revoke it in the same step.

When Apertis learns that a key was exposed, for example from a report, we revoke it and email the owner. The message is titled "An Apertis API key on your account was revoked". It names the key by id, never by value, gives the UTC time, and links to API Keys for the replacement. For an organization key it also goes to the organization's owners.

Check a key's format offline

Keys issued since late October 2026 use a fixed shape: the prefix sk-apx_, 40 random base62 characters (about 238 bits), and a 6-character checksum of those 40.

KeyShape
Personalsk-apx_ + 46 characters
Subscription plansk-sub_apx_ + 46 characters
Organizationsk-org_apx_ + 46 characters

What that gives you:

  • Secret scanners match it exactly. sk-(sub_|org_)?apx_[0-9A-Za-z]{46} has no false positives from other vendors' sk- keys, and a scanner can verify the checksum before raising an alert.
  • Typos are caught before the network. The checksum is CRC32 of the 40 random characters, written as six base62 digits:
import zlib

ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

def looks_issued(key: str) -> bool:
    body = key.rsplit("apx_", 1)[-1]
    if len(body) != 46:
        return False
    n, check = zlib.crc32(body[:40].encode()), ""
    for _ in range(6):
        n, digit = divmod(n, 62)
        check = ALPHABET[digit] + check
    return check == body[40:]
  • A mistyped key costs no lookup. A key of this shape with a wrong checksum is refused before any cache or database read, with the same 401 as an unknown key.

Keys issued before the change keep working unchanged.

Set limits that bound a leak

Detection reacts after the fact. A limit on the key decides the worst case in advance, and each one answers with its own error so your client can tell them apart.

Limits & routing in the Edit key dialog: a US$500 credit limit, the monthly limit, a spend limit of US$5 per hour, allowed models and an IP allowlist of one range
SettingWhat it boundsWhen it is reached
Spend limit per hourspend in any trailing hour429 api_key_spend_rate_exceeded with Retry-After
Credit limitlifetime spend of the keythe key stops when the limit is used up
Monthly limitthe key's share of your account's monthly limitrefused until the monthly reset
IP allowlistwhere the key can be used from403, naming the allowed subnet
Expireshow long a forgotten key keeps workingrefused as expired
Permissionsall, restricted or read_onlyrefused outside its scope

When the hourly spend limit is reached, the error body looks like this:

{
  "error": {
    "message": "This API key has reached its spend limit of US$5.00 per hour. Retry after 1240 seconds, or raise the limit in the key's settings.",
    "type": "rate_limit_error",
    "code": "api_key_spend_rate_exceeded"
  }
}

The Key safety row above your key list counts the enabled keys that have no credit limit, never expire, or have been idle for 90 days or more. Each count is a filter: click it to see exactly those keys.

The Key safety row above five active keys: 3 with no credit limit, 3 never expire, 1 idle 90+ days

If a key leaks

  1. Revoke it in API Keys. Do not disable it: disabled can be undone by anyone with access to the account.
  2. Create the replacement with a spend limit per hour and, where the caller has a fixed address, an IP allowlist.
  3. Read what it did. Logs filtered by that key shows every request it made, with model, tokens and cost.
  4. Find the exposure: a public repository, a shared CI log, a client-side bundle.