# Rent a number over the API: one test account for the whole sprint

> A one-off activation is built for one code. Regression runs need the same test account on Monday and again on Thursday, after a session reset, on a clean device. Pass duration=d1, d3 or d7 to getNumber and the number stays yours, with repeat codes from that service included until the rental ends.

Source: https://otpwatch.com/rent-number-api
Updated: 2026-11-24
API key: https://otpwatch.com/agent/key

## When a rental beats activations

A rental pays for itself when the same test account must receive codes more than once:

- logging in again after the test wipes the session or reinstalls the app;
- a "new device" check, password reset or SMS-based recovery in the test plan;
- the same regression scenario re-run after a hotfix, where a new account would change the conditions you are comparing.

With one-off activations each of those is a new purchase, and usually a new number, which means a new account with no history. The comparison takes a minute:

```text title="activation or rental"
# handler_api reference: https://otpwatch.com/rent-number-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
codes per cycle  = cases that need a code × runs in the cycle
activation cost  = codes per cycle × one-off price for the pair
rental cost      = price of d1, d3 or d7 for the same pair
```

Rentals and one-off activations are priced separately, and suppliers set both. Look at the rental price for your pair in the order window before you script it. For reference, the one-off "from" price for Telegram in the United Kingdom was $1.3798 on 24 Nov 2026.

## Ordering a rental

```text title="request → reply"
# handler_api reference: https://otpwatch.com/rent-number-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
?action=getNumber&api_key=KEY&service=tg&country=16&duration=d7
ACCESS_NUMBER:12345:447700900123
```

| duration | Term |
|---|---|
| `activation` (or omitted) | one-off activation, one code |
| `d1` | 1 day |
| `d3` | 3 days |
| `d7` | 7 days, the longest term |

Not every service sells every term. If the service has no such duration the reply is `BAD_SERVICE`; an unknown value gives `BAD_DURATION`. `maxPrice` works for rentals too, with one difference: a rental above the cap answers `NO_NUMBERS`, not `WRONG_MAX_PRICE:<price>`. Retry with a higher cap or check the price in the dashboard.

## Reading repeat codes

The rented number appears in `getCurrentActivationsList` until the rental ends, so a test process that restarts can find it again by number. Store three things with the test account: the activation id, the number and the end date.

```env title=".env.example"
# handler_api reference: https://otpwatch.com/rent-number-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
SMS_API_BASE_URL=https://sim-aggregator.org/stubs/handler_api.php
# Key from the SimAggregator dashboard: https://otpwatch.com/agent/key
SMS_API_KEY=
```

```js title="rental-code.mjs"
// handler_api reference: https://otpwatch.com/rent-number-api
// Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
// Wait for the next code on a rented number, then arm it for the one after.
import { SmsClient } from "./otp-client.mjs";   // from the Node.js page

const client = new SmsClient(process.env.SMS_API_KEY);
const id = process.env.RENTAL_ID;               // saved when the rental was ordered

export async function nextCode() {
  const code = await client.waitCode(id, { timeoutMs: 300_000, intervalMs: 4_000 });
  await client.anotherCode(id);                  // setStatus 3: wait for the next SMS
  return code;
}
```

After `setStatus` 3, `getStatus` answers `STATUS_WAIT_RETRY:<previous code>` until a new SMS arrives, then `STATUS_OK:<new code>`. Do not send `setStatus` 6 between logins: 6 finishes the order. Send it only when you are done with the number.

## Only the service you rented

A rental is tied to the number **and** the service. If you rented for Telegram, only Telegram SMS reach the order. Codes from any other sender do not show up, because the same SIM can serve other services for other buyers at the same time. If your test account needs two services on one number, the dashboard sells a multi-service order (up to three services) chosen at purchase.

## Cancel and refund rules

- A rental can be cancelled with a refund **within the first hour after purchase, and only before any SMS or call arrives.** After that it is paid in full even if no code ever comes.
- Like any order, a cancel can be refused as too early (`EARLY_CANCEL_DENIED`); repeat it later.
- Refunds go to the internal balance.

So check in the first hour that the service actually sends to the number. If it refuses the number outright, cancel and order another one.

## When the rental ends

The number goes back to the supplier. Any account still tied only to it is stuck with a phone you no longer control. Before the term ends, while repeat codes are still free:

1. add a second login method to the test account: an email you control, an authenticator app, recovery codes;
2. log out and back in with that method to prove it works;
3. record in your test-accounts vault which number the account used and when the rental ended.

Need more time? The expired order in the dashboard has a "Buy again" button that orders the same number again, which in practice extends the rental, as long as the supplier's SIM is online.

## Rentals and the rest of the suite

- Keep rentals on their own key. Your CI cleanup script cancels open orders of its key, and you do not want it cancelling a seven-day staging number.
- One rental per test account, not one per test. Tests that share the account must run serially, or two of them will read each other's codes.
- Full action reference: [getNumber](https://otpwatch.com/handler-api.md#getnumber) and [setStatus](https://otpwatch.com/handler-api.md#setstatus).
