Improvement

API, CLIBreaking

Balance and spending limit errors now return 402

Running out of balance or hitting a key's spending limit now returns 402 Payment Required, so 429 only ever means slow down.

INSUFFICIENT_BALANCE used to return 422 and SPENDING_LIMIT_EXCEEDED used to return 429. Both now return 402 Payment Required. The code and message in the body are the same.

The old 429 looked like a rate limit, so HTTP clients that retry 429 kept resending a request that could only succeed once the key's period rolled over. Now a 429 means back off and retry, and a 402 means top up, raise the cap, or wait for the period to reset.

If your code checks code, nothing changes. If it checks the status, look for 402 where you looked for 422 or 429:

if (error instanceof MynthAPIError && error.status === 402) {
  // error.code is INSUFFICIENT_BALANCE or SPENDING_LIMIT_EXCEEDED
}

The CLI still exits with 4 for both codes, and now also for any other 402.