The four buckets
| Bucket | Codes | Do this |
|---|---|---|
| Try later | NO_NUMBERS, ERROR_API, EARLY_CANCEL_DENIED | wait and retry the same request, or pick another country |
| Slow down | REQUEST_LIMIT, CHANNEL_LIMIT | back off; close orders you no longer need |
| Fix the request | BAD_ACTION, BAD_COUNTRY, BAD_SERVICE, BAD_DURATION, BAD_MAX_PRICE, WRONG_MAX_PRICE:<price>, BAD_STATUS | do not retry unchanged; correct the parameters |
| Stop | BAD_KEY, NO_BALANCE | fail loudly; a human has to act |
Every code
| Code | Returned by | Meaning | What to do |
|---|---|---|---|
NO_NUMBERS | getNumber, getNumberV2 | no free number for this pair right now; also a rental priced above maxPrice | retry in a minute, or try the next country on your list |
NO_BALANCE | getNumber, getNumberV2 | the balance does not cover the order | stop ordering; top up |
WRONG_MAX_PRICE:<price> | getNumber, getNumberV2 | one-off price is above your maxPrice; the tail is the lowest current price | raise the cap if the price is acceptable, otherwise skip the pair |
BAD_MAX_PRICE | getNumber, getNumberV2 | maxPrice is not a number above zero | send a decimal with a dot, e.g. 1.50 |
BAD_COUNTRY | getPrices, getServicesList, getNumber | unknown country id | look the id up with getCountries (country ids) |
BAD_SERVICE | getPrices, getNumber | unknown service code, or the service has no such rental term | check getServicesList (service codes) or drop duration |
BAD_DURATION | getNumber | duration is not activation, d1, d3 or d7 | fix the value |
CHANNEL_LIMIT | getNumber, getNumberV2 | the account has reached its limit of simultaneous orders | close finished or useless orders, then retry |
STATUS_CANCEL | getStatus | the activation is closed: cancelled, finished or expired | stop polling this id |
NO_ACTIVATION | getStatus, setStatus | unknown or already closed id | stop polling; check you stored the right id |
EARLY_CANCEL_DENIED | setStatus | too early to cancel (the docs give no time) | repeat the cancel with a pause, and cap the attempts |
BAD_STATUS | setStatus | not allowed: already closed, a code was delivered so it cannot be cancelled, or an unsupported value | use 3, 6 or 8; after a code, finish with 6 |
REQUEST_LIMIT | any | more than 600 requests a minute on this key | exponential backoff with jitter; poll less often |
BAD_ACTION | any | unknown action name | check spelling and case: getNumber, not getnumber |
BAD_KEY | any | key unknown or revoked | stop; the key needs replacing |
ERROR_API | several | unexpected server-side error | retry with backoff, a few times at most |
Classifier
Put the mapping in one function and make every caller handle the bucket, not the string.
// 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" }# 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, NoneTreat 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_NUMBERSvsWRONG_MAX_PRICE. The first says "nothing free", the second says "free, but above your cap" and tells you the price. Only one-off activations getWRONG_MAX_PRICE; a rental over the cap answersNO_NUMBERS.STATUS_CANCELvsNO_ACTIVATION. Both mean "stop polling". If you seeNO_ACTIVATIONfor an id you just ordered, you are probably sending a different key than the one that placed the order.NO_BALANCEvsCHANNEL_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 getNO_BALANCE, add up what the open orders hold.BAD_STATUSafter 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_LIMITandERROR_APIwith growing pauses (1, 2, 4, 8 s, capped at 30 s) plus random jitter, so parallel workers do not wake up together. - Retry
NO_NUMBERSat 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_DENIEDcomes 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.