Set OTPMOCK_URL=https://api.otpmock.com in your test environment, point the Sinch client at it, and use your otpmock API key as the Sinch credential. Your application code doesn't change, and production keeps sending real SMS through Sinch.
Setup
The SDK has a documented smsHostname option.
import { SinchClient } from "@sinch/sdk-core";
export const sinch = new SinchClient({
servicePlanId: process.env.SINCH_SERVICE_PLAN_ID,
apiToken: process.env.SINCH_API_TOKEN, // otpmock API key in tests
...(process.env.OTPMOCK_URL && { smsHostname: process.env.OTPMOCK_URL }),
});Credentials. In the test environment, set your Sinch API token (used with servicePlanId) to your otpmock API key.
What otpmock emulates
| Endpoint | What it does |
|---|---|
POST /xms/v1/{service_plan_id}/batches | Send an SMS batch (mt_text) |
Responses and errors follow Sinch's own format, so the SDK parses them as usual. Authentication failures and an exhausted monthly allowance also come back in Sinch's error shape.
Phone numbers
Send in E.164 or without +; both land in the same inbox.
Read the code in your tests
const phone = otp.randomPhone();
const since = Date.now() - 5_000;
await page.getByRole("button", { name: "Send code" }).click(); // your app calls Sinch
const { code } = await otp.waitForCode(phone, { since });The otp helper is a single file: get it from the docs. Full walkthroughs: Playwright, Cypress.
Good to know
- Only the service plan ID + API token authentication mode is emulated, not the OAuth (project ID / key) mode.
FAQ
Does otpmock send real SMS through Sinch?
No. In the test environment your app's Sinch requests go to otpmock, which stores the message for 10 minutes and never contacts Sinch or any carrier. Production keeps using Sinch because otpmock is only enabled when OTPMOCK_URL is set.
Is the official @sinch/sdk-core SDK supported?
Yes. otpmock's Sinch endpoints are tested end to end with the official @sinch/sdk-core package for Node.js. Other languages work too if their Sinch client lets you change the API host.
Which Sinch APIs does otpmock support?
POST /xms/v1/{service_plan_id}/batches (Send an SMS batch (mt_text)).
The free plan includes 100 messages a month. Using an AI coding assistant? Point it at otpmock.com/llms-full.txt.
Get a free API key