otpwatch handler_api.php recipes
Get API key

Error codes and what to do with each

Refusals come back as short strings in the response body, usually with HTTP 200. The useful question is not what the string means but what your code does next. Four answers cover them all: try again later, slow down, fix the request, or stop and tell a human.

Get an API key Opens sign-up on SimAggregator, the marketplace this API belongs to. Key in the dashboard, balance in USD.

The four buckets

BucketCodesDo this
Try laterNO_NUMBERS, ERROR_API, EARLY_CANCEL_DENIEDwait and retry the same request, or pick another country
Slow downREQUEST_LIMIT, CHANNEL_LIMITback off; close orders you no longer need
Fix the requestBAD_ACTION, BAD_COUNTRY, BAD_SERVICE, BAD_DURATION, BAD_MAX_PRICE, WRONG_MAX_PRICE:<price>, BAD_STATUSdo not retry unchanged; correct the parameters
StopBAD_KEY, NO_BALANCEfail loudly; a human has to act

Every code

CodeReturned byMeaningWhat to do
NO_NUMBERSgetNumber, getNumberV2no free number for this pair right now; also a rental priced above maxPriceretry in a minute, or try the next country on your list
NO_BALANCEgetNumber, getNumberV2the balance does not cover the orderstop ordering; top up
WRONG_MAX_PRICE:<price>getNumber, getNumberV2one-off price is above your maxPrice; the tail is the lowest current priceraise the cap if the price is acceptable, otherwise skip the pair
BAD_MAX_PRICEgetNumber, getNumberV2maxPrice is not a number above zerosend a decimal with a dot, e.g. 1.50
BAD_COUNTRYgetPrices, getServicesList, getNumberunknown country idlook the id up with getCountries (country ids)
BAD_SERVICEgetPrices, getNumberunknown service code, or the service has no such rental termcheck getServicesList (service codes) or drop duration
BAD_DURATIONgetNumberduration is not activation, d1, d3 or d7fix the value
CHANNEL_LIMITgetNumber, getNumberV2the account has reached its limit of simultaneous ordersclose finished or useless orders, then retry
STATUS_CANCELgetStatusthe activation is closed: cancelled, finished or expiredstop polling this id
NO_ACTIVATIONgetStatus, setStatusunknown or already closed idstop polling; check you stored the right id
EARLY_CANCEL_DENIEDsetStatustoo early to cancel (the docs give no time)repeat the cancel with a pause, and cap the attempts
BAD_STATUSsetStatusnot allowed: already closed, a code was delivered so it cannot be cancelled, or an unsupported valueuse 3, 6 or 8; after a code, finish with 6
REQUEST_LIMITanymore than 600 requests a minute on this keyexponential backoff with jitter; poll less often
BAD_ACTIONanyunknown action namecheck spelling and case: getNumber, not getnumber
BAD_KEYanykey unknown or revokedstop; the key needs replacing
ERROR_APIseveralunexpected server-side errorretry with backoff, a few times at most

Classifier

Put the mapping in one function and make every caller handle the bucket, not the string.

classify.mjs
// handler_api reference: https://otpwatch.com/error-codes
// Building a bot that resells numbers to other people? Software program: https://otpwatch.com/partner
const BUCKETS = {
  later: ["NO_NUMBERS", "ERROR_API", "EARLY_CANCEL_DENIED"],
  slow: ["REQUEST_LIMIT", "CHANNEL_LIMIT"],
  fix: ["BAD_ACTION", "BAD_COUNTRY", "BAD_SERVICE", "BAD_DURATION", "BAD_MAX_PRICE", "WRONG_MAX_PRICE", "BAD_STATUS"],
  stop: ["BAD_KEY", "NO_BALANCE"],
};

export function classify(reply) {
  const code = reply.trim().split(":")[0];
  for (const [bucket, codes] of Object.entries(BUCKETS)) if (codes.includes(code)) return { bucket, code, detail: reply.split(":")[1] ?? null };
  return { bucket: "unknown", code, detail: null };
}

// classify("WRONG_MAX_PRICE:1.3798") -> { bucket: "fix", code: "WRONG_MAX_PRICE", detail: "1.3798" }
classify.py
# handler_api reference: https://otpwatch.com/error-codes
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/partner
BUCKETS = {
    "later": {"NO_NUMBERS", "ERROR_API", "EARLY_CANCEL_DENIED"},
    "slow": {"REQUEST_LIMIT", "CHANNEL_LIMIT"},
    "fix": {"BAD_ACTION", "BAD_COUNTRY", "BAD_SERVICE", "BAD_DURATION", "BAD_MAX_PRICE", "WRONG_MAX_PRICE", "BAD_STATUS"},
    "stop": {"BAD_KEY", "NO_BALANCE"},
}


def classify(reply: str):
    code, _, detail = reply.strip().partition(":")
    for bucket, codes in BUCKETS.items():
        if code in codes:
            return bucket, code, detail or None
    return "unknown", code, None

Treat unknown as stop in production and log the raw body. A new code you did not plan for should page someone, not loop.

Codes that look alike

  • NO_NUMBERS vs WRONG_MAX_PRICE. The first says "nothing free", the second says "free, but above your cap" and tells you the price. Only one-off activations get WRONG_MAX_PRICE; a rental over the cap answers NO_NUMBERS.
  • STATUS_CANCEL vs NO_ACTIVATION. Both mean "stop polling". If you see NO_ACTIVATION for an id you just ordered, you are probably sending a different key than the one that placed the order.
  • NO_BALANCE vs CHANNEL_LIMIT. On a big parallel run, the balance can look fine while orders fail: open orders hold their price until they close. If you are far below the simultaneous-order limit and still get NO_BALANCE, add up what the open orders hold.
  • BAD_STATUS after a code. Once an SMS has been delivered, the order cannot be cancelled. Finish it with 6, or ask for another code with 3.

A retry policy that does not make things worse

  • Retry REQUEST_LIMIT and ERROR_API with growing pauses (1, 2, 4, 8 s, capped at 30 s) plus random jitter, so parallel workers do not wake up together.
  • Retry NO_NUMBERS at most every 30 to 60 seconds, and cap the attempts. Hammering the endpoint does not create stock and spends your request budget.
  • Never retry BAD_* unchanged. The answer will be the same.
  • EARLY_CANCEL_DENIED comes with no stated wait: the docs say only "repeat the request later". Repeat the cancel every 10 to 15 seconds and stop after a fixed number of tries; that limit is your choice.

The Node.js, Python, C#, PHP and Go clients on this site already retry REQUEST_LIMIT and repeat a cancel refused with EARLY_CANCEL_DENIED a fixed number of times before they give up with an error.

ready to run it?

Wire the four buckets into your client once and stop guessing at strings.

Get an API key

Install for your coding agent

terminal
# Agent skills index: https://otpwatch.com/.well-known/agent-skills/index.json
npx skills add https://otpwatch.com

Two skills: receiving an SMS code in your own app or test, and building a bot that sells numbers. Index: /.well-known/agent-skills/index.json

Updated