Purchase SMS number
Purchase SMS number: purchaseSmsNumber in the TypeScript, Python, Rust and Go clients.
POST /v1/projects/{id}/platforms/sms/numbers
Buys one US local number from the provider and records it as a resource with SMS enabled. Requires countryCode (US) and accepts an optional three-digit geographic areaCode. The server selects an exact matching number. While inventory is empty the operation keeps searching, and the caller can cancel it until ordering begins; a search still empty one minute after the operation was created fails it with NUMBER_INVENTORY_UNAVAILABLE. Always answers 202 with an operation: the work runs behind the response, and the Location points at the operation to poll. New area-specific requests must appear in current provider coverage; discover it with GET /sms/numbers/area-codes?countryCode=US. Coverage and subscription checks run before operation creation. Billing follows delivery. Replays return the original operation without checking current coverage. The Idempotency-Key is required and permanent: repeating it returns the same operation forever, never a second number. A further number always needs a NEW key, including while others are still running. An optional promotionCode is redeemed with the number's charge, which follows delivery: a code billing refuses hands the number back, and its release operation carries the refusal (reason charge_refused, with detail.chargeRefusal { code: "promotion_code_rejected", detail: <why> }). Requires the platforms:write permission bound to the project resource in the path. If the operation fails, its error is the problem of one of these codes: ENTITLEMENT_REQUIRED, NUMBER_INVENTORY_UNAVAILABLE, NUMBER_ORDER_FAILED, NUMBER_ORDER_RECONCILIATION_REQUIRED, NUMBER_SEARCH_FAILED.
photon.projects.platforms.purchaseSmsNumber(input: PurchaseSmsNumberInput, options?: RequestOptions): Promise<PurchaseSmsNumberOutput>photon.projects.platforms.purchase_sms_number(input: PurchaseSmsNumberInput, *, options: RequestOptions | None = None) -> models.Operationclient.purchase_sms_number(idempotency_key: String, id: String, body: &types::PurchaseSmsNumberRequest).await -> Result<ResponseValue<types::Operation>, Error<PurchaseSmsNumberError>>client.Projects.Platforms.PurchaseSmsNumber(ctx context.Context, params *PurchaseSmsNumberParams, opts ...RequestOption) (*Operation, error)import { Photon } from "@photon-ai/api";
const photon = new Photon({
headers: { Authorization: `Bearer ${process.env.PHOTON_API_TOKEN}` },
});
const result = await photon.projects.platforms.purchaseSmsNumber({
path: {
id: "id",
},
headers: {
idempotencyKey: "idempotencyKey",
},
body: {
countryCode: "US",
},
});import os
from photon_api import Photon
from photon_api.rpc_generated import PurchaseSmsNumberInput
photon = Photon(headers={"Authorization": f"Bearer {os.environ['PHOTON_API_TOKEN']}"})
result = photon.projects.platforms.purchase_sms_number(
PurchaseSmsNumberInput.model_validate({
"path": {
"id": "id",
},
"headers": {
"Idempotency-Key": "idempotencyKey",
},
"body": {
"countryCode": "US",
},
})
)use photon_ai_api::{Credential, PhotonClientBuilder, SecretString};
let token = std::env::var("PHOTON_API_TOKEN")?;
let client = PhotonClientBuilder::new()
.credential("accountServiceKey", Credential::Bearer(SecretString::from(token)))
.build()?;
let result = client
.purchase_sms_number(
"idempotencyKey".to_owned(),
"id".to_owned(),
&serde_json::from_value(serde_json::json!({
"countryCode": "US",
}))?,
)
.await
.map_err(|error| format!("{error:?}"))?
.into_inner();import (
"context"
"encoding/json"
"os"
photonapi "github.com/photon-hq/api/packages/go"
)
ctx := context.Background()
client := photonapi.NewClient(photonapi.WithAPIKey(os.Getenv("PHOTON_API_TOKEN")))
var body photonapi.PurchaseSmsNumberRequest
if err := json.Unmarshal([]byte(`{
"countryCode": "US"
}`), &body); err != nil {
return err
}
result, err := client.Projects.Platforms.PurchaseSmsNumber(ctx, &photonapi.PurchaseSmsNumberParams{
IdempotencyKey: "idempotencyKey",
ID: "id",
Body: body,
})
if err != nil {
return err
}
_ = result{
"cancellable": true,
"createdAt": "2026-01-01T00:00:00.000Z",
"detail": {},
"endedAt": "2026-01-01T00:00:00.000Z",
"error": {
"code": "CHARGE_REFUSED",
"remediation": {
"action": "Check the payment method in Billing, then request the purchase again."
},
"status": 402,
"title": "Charge Refused",
"type": "https://photon.codes/docs/problems/charge-refused"
},
"operationId": "string",
"projectId": "string",
"reason": "charge_refused",
"resourceId": "string",
"resourceType": "string",
"startedAt": "2026-01-01T00:00:00.000Z",
"state": "pending",
"type": "resource.provision",
"updatedAt": "2026-01-01T00:00:00.000Z"
}Parameters
Selects the API contract date. Without it, the request is served as 2026-07-01.
Identifies one logical mutation across retries.
Body
A promotion code to redeem with this number's charge. Billing takes a fixed amount off the charge. The charge follows delivery, so a code Billing refuses hands the number back, and the release operation carries the refusal. Part of the request's identity: repeating the Idempotency-Key with a different code, or none, is refused.
Returns
202 The purchase was accepted and is running. GET the Location after the Retry-After interval until state is terminal; the response there carries the number once it exists. Operation
Headers: Location, Photon-Version. The raw response carries these headers; see Raw responses.
Why the operation failed: the problem of its code, the same object the endpoint returns when it rejects a request, with the status that rejection would have had (the poll itself answers 200). Every code an operation can end with is a branch below, and the endpoint that starts the operation lists its codes. Branch on code, never on status, and keep a default: a code added after your client was generated arrives as a generic problem with type: about:blank and status: 500. That 500 means this document does not describe the code yet, not that the request failed on our side or that retrying will help.