Set OTPMOCK_URL=https://api.otpmock.com in your test environment, point the Bird (MessageBird) client at it, and use your otpmock API key as the Bird (MessageBird) credential. Your application code doesn't change, and production keeps sending real SMS through Bird (MessageBird).
Setup
The official SDK has a baseUrl option that overrides the region host derived from the key.
import { BirdClient } from "@messagebird/sdk";
export const bird = new BirdClient({
apiKey: process.env.BIRD_API_KEY, // otpmock API key in tests
...(process.env.OTPMOCK_URL && { baseUrl: process.env.OTPMOCK_URL }),
});import os
import requests
BIRD_URL = os.environ.get("OTPMOCK_URL", "https://us-west-1.platform.bird.com")
requests.post(
f"{BIRD_URL}/v1/sms/messages",
headers={"Authorization": f"Bearer {os.environ['BIRD_API_KEY']}"}, # otpmock API key in tests
json={"from": "+15557654321", "to": "+15550142", "text": f"Your code is {code}", "category": "authentication"},
).raise_for_status()// Bird has no Java SDK; call the REST API and swap the host.
String base = System.getenv().getOrDefault("OTPMOCK_URL", "https://eu.platform.bird.com");
HttpRequest req = HttpRequest.newBuilder(URI.create(base + "/v1/sms/messages"))
.header("Authorization", "Bearer " + System.getenv("BIRD_API_KEY")) // otpmock API key in tests
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json)) // {"from":"+1...","to":"+1...","text":"...","category":"authentication"}
.build();// Bird has no official .NET SDK; call the REST API with HttpClient.
var birdUrl = Environment.GetEnvironmentVariable("OTPMOCK_URL") ?? "https://eu-west-1.platform.bird.com";
var http = new HttpClient { BaseAddress = new Uri(birdUrl) };
http.DefaultRequestHeaders.Add("Authorization",
"Bearer " + Environment.GetEnvironmentVariable("BIRD_API_KEY")); // otpmock API key in tests
await http.PostAsJsonAsync("/v1/sms/messages",
new { from = "+15557654321", to = phone, text = $"Your code is {code}", category = "authentication" });use GuzzleHttp\Client;
$birdUrl = getenv('OTPMOCK_URL') ?: 'https://us-west-1.platform.bird.com';
(new Client())->post("$birdUrl/v1/sms/messages", [
'headers' => ['Authorization' => 'Bearer ' . getenv('BIRD_API_KEY')], // otpmock API key in tests
'json' => ['from' => '+15557654321', 'to' => '+15550142', 'text' => "Your code is $code", 'category' => 'authentication'],
]);require "net/http"
require "json"
# Bird has no official Ruby SDK; apps call the REST API, so only the host changes.
BIRD_URL = ENV.fetch("OTPMOCK_URL", "https://api.bird.com")
res = Net::HTTP.post(
URI("#{BIRD_URL}/v1/sms/messages"),
{ from: "+15557654321", to: "+15550142", text: "Your code is #{code}", category: "authentication" }.to_json,
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV["BIRD_API_KEY"]}" # otpmock API key in tests
)// Bird has no official Go SDK; call its HTTP API with net/http, only the host changes.
base := os.Getenv("OTPMOCK_URL")
if base == "" {
base = "https://eu.platform.bird.com"
}
body, _ := json.Marshal(map[string]any{"from": os.Getenv("BIRD_NUMBER"), "to": "+15550142", "text": msg, "category": "authentication"})
req, _ := http.NewRequest("POST", base+"/v1/sms/messages", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+os.Getenv("BIRD_API_KEY")) // otpmock API key in tests
res, err := http.DefaultClient.Do(req) // 202, status "accepted"Each language is tested in CI against otpmock with the provider's official SDK, or its plain HTTP API where no SDK can be pointed at another host.
Credentials. In the test environment, set your Bird API key variable to your otpmock API key. With baseUrl set, the SDK no longer needs the bk_{region}_ key prefix.
What otpmock emulates
| Endpoint | What it does |
|---|---|
POST /v1/sms/messages | Send one SMS (to, from, text, category), 202 with status: "accepted" |
POST /v1/verify/verifications | Verify: start (otpmock generates the code; options.code_length honoured; an open verification for the same number is reused) |
POST /v1/verify/verifications/check | Verify: check by recipient; 200 with success, reason (incorrect_code, attempts_exhausted) and attempts_remaining |
POST /v1/verify/verifications/next-channel | Verify: resend the same code by SMS |
Responses and errors follow Bird (MessageBird)'s own format, so the SDK parses them as usual. Authentication failures and an exhausted monthly allowance also come back in Bird (MessageBird)'s error shape.
Phone numbers
Send in E.164 (+15550142), as Bird expects.
How to tell your app uses Bird (MessageBird)
Look for any of these in your codebase to confirm where the SMS is sent, and therefore where the otpmock option has to be set:
@messagebird/sdkin package.jsonnew BirdClient(bird.sms.send(bird.verify.verifications.- requests to
*.platform.bird.com/v1/sms/messagesor/v1/verify/
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 Bird (MessageBird)
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
- This is Bird's current SMS API. The legacy MessageBird API (
rest.messagebird.com/messages) and its oldmessagebirdnpm package aren't emulated: that SDK can't be pointed at another host. - When the monthly allowance is used up, otpmock returns Bird's
billing_error(402) rather than a rate-limit error, so the SDK doesn't retry in a loop.
FAQ
Does otpmock send real SMS through Bird (MessageBird)?
No. In the test environment your app's Bird (MessageBird) requests go to otpmock, which stores the message for 10 minutes and never contacts Bird (MessageBird) or any carrier. Production keeps using Bird (MessageBird) because otpmock is only enabled when OTPMOCK_URL is set.
Is the official @messagebird/sdk SDK supported?
Yes. otpmock's Bird (MessageBird) endpoints are tested end to end with the official @messagebird/sdk package for Node.js. Other languages work too if their Bird (MessageBird) client lets you change the API host.
Which Bird (MessageBird) APIs does otpmock support?
POST /v1/sms/messages (Send one SMS (to, from, text, category), 202 with status: "accepted"); POST /v1/verify/verifications (Verify: start (otpmock generates the code; options.code_length honoured; an open verification for the same number is reused)); POST /v1/verify/verifications/check (Verify: check by recipient; 200 with success, reason (incorrect_code, attempts_exhausted) and attempts_remaining); POST /v1/verify/verifications/next-channel (Verify: resend the same code by SMS).
The free plan includes 300 messages a month. Using an AI coding assistant? Point it at otpmock.com/llms-full.txt.
Get a free API key