SMS
SMS sending, OTP and verification, and delivery status.
Overview
Base path:
/v1/smsPython namespace:
infra.smstext
# Python
from infrai import infra
# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.smsMethods
sms.send
POST /v1/sms/send
Send an SMS message; supports templates and BYOK vendors.
Python
python
infra.sms.send(to=..., body=..., from_=None, template_id=None, vendor=None, idempotency_key=None)TypeScript
typescript
client.sms.send(opts: SmsSendOptions): Promise<SmsRecord>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
to | string | Required | Recipient phone number in E.164. |
body | string | Optional | Message text. |
from | string | Optional | Sender id or number. |
template_id | string | Optional | Template id to render instead of a body. |
vendor | string | Optional | Pin a specific vendor instead of auto-routing. |
idempotency_key | string | Optional | Optional dedup key; identical retries return the same result. |
Returns
SmsRecord { sms_id, to, state, vendor, segments, created_at }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
msg = infra.sms.send(to="+15555550123", body="Your order has shipped.")
print("sms_id:", msg.get("sms_id"), "| state:", msg.get("state"))sms.otp
POST /v1/sms/otp
Send a one-time passcode to a phone number.
Python
python
infra.sms.otp(to=...)TypeScript
typescript
// see ROUTES["sms.otp"]Parameters
| Name | Type | Required | Description |
|---|---|---|---|
to | string | Required | Recipient phone number in E.164. |
Returns
{ request_id, expires_at }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
# Send a one-time passcode, then verify the code the user typed.
otp = infra.sms.otp(to="+15555550123")
print("sent:", otp.get("status") or otp.get("state"))
verified = infra.sms.verify(to="+15555550123", code="000000")
print("valid:", verified.get("verified") or verified.get("valid"))sms.verify
POST /v1/sms/verify
Verify a one-time passcode.
Python
python
infra.sms.verify(to=..., code=...)TypeScript
typescript
// see ROUTES["sms.verify"]Parameters
| Name | Type | Required | Description |
|---|---|---|---|
to | string | Required | Recipient phone number in E.164. |
code | string | Required | The one-time passcode to verify. |
Returns
{ valid: boolean }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
res = infra.sms.verify(to="+15555550123", code="123456")
print("valid:", res.get("valid") or res.get("verified"))sms.status
GET /v1/sms/{id}
Fetch the delivery status of an SMS.
Python
python
infra.sms.status(id=sms_id)TypeScript
typescript
client.sms.status(smsId: string): Promise<SmsRecord>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
id | string | Required | The SMS record id. |
Returns
SmsRecordExample
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
rec = infra.sms.status(id="sms_...")
print("state:", rec.get("state"), "| segments:", rec.get("segments"))