DEV Community

BridgeXAPI
BridgeXAPI

Posted on

You send SMS. You get billed later. You don’t know why: estimate SMS cost in Python

You send SMS. You get billed later. You don’t know why.

That is a bad backend flow.

Before execution, you should know:

  • what the message will cost
  • whether your balance is sufficient
  • whether the route is worth using
  • whether the request should continue at all

That is what estimation is for.


Most SMS APIs expose pricing after execution.

You send first.

You get billed later.

That means your backend is making execution decisions without cost visibility.


The problem

Without pre-send estimation:

  • you cannot gate expensive requests
  • you cannot compare route cost before execution
  • you cannot prevent avoidable balance failures
  • you cannot build predictable messaging workflows

You are committing first and understanding later.


What estimate is actually for

Estimate is not just a pricing endpoint.

It is a pre-send decision step.

It lets your backend inspect execution cost before sending anything.

That means estimation can be used to:

  • approve or reject a send attempt
  • compare routes before execution
  • prevent balance-related failures
  • enforce budget rules
  • make routing decisions deliberately

Basic estimate request

import requests

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://hi.bridgexapi.io"

response = requests.post(
    f"{BASE_URL}/api/v1/estimate",
    headers={
        "X-API-KEY": API_KEY,
        "Content-Type": "application/json",
    },
    json={
        "route_id": 1,
        "caller_id": "BRIDGEXAPI",
        "numbers": ["34699108839"],
        "message": "Cost test message"
    },
    timeout=30,
)

estimate = response.json()
print(estimate)
Enter fullscreen mode Exit fullscreen mode

Real estimate result

{
  "status": "success",
  "message": "Estimate calculated successfully.",
  "route_id": 1,
  "count": 1,
  "estimated_cost": 0.051,
  "currency": "EUR",
  "balance": 201.7,
  "sufficient_balance": true,
  "sandbox": false
}
Enter fullscreen mode Exit fullscreen mode

This gives you execution context before send:

  • estimated cost
  • current balance
  • whether sending is possible

Flow 1: estimate before send

import requests

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://hi.bridgexapi.io"

payload = {
    "route_id": 1,
    "caller_id": "BRIDGEXAPI",
    "numbers": ["34699108839"],
    "message": "Verification code: 4839"
}

estimate_response = requests.post(
    f"{BASE_URL}/api/v1/estimate",
    headers={
        "X-API-KEY": API_KEY,
        "Content-Type": "application/json",
    },
    json=payload,
    timeout=30,
)

estimate = estimate_response.json()

if not estimate.get("sufficient_balance"):
    print("Do not send: insufficient balance")
else:
    send_response = requests.post(
        f"{BASE_URL}/api/v1/send_sms",
        headers={
            "X-API-KEY": API_KEY,
            "Content-Type": "application/json",
        },
        json=payload,
        timeout=30,
    )
    print(send_response.json())
Enter fullscreen mode Exit fullscreen mode

Real send result

{
  "status": "success",
  "message": "SMS batch accepted via route 1",
  "order_id": 22565,
  "route_id": 1,
  "count": 1,
  "messages": [
    {
      "bx_message_id": "BX-22565-...",
      "msisdn": "34699108839",
      "status": "QUEUED"
    }
  ],
  "cost": 0.051,
  "balance_after": 201.65
}
Enter fullscreen mode Exit fullscreen mode

Notice:

  • estimated_cost = 0.051
  • actual cost = 0.051

Estimation matches execution.


Flow 2: compare routes before sending

for route_id in [1, 2, 3]:
    result = estimate_for_route(route_id)
    print(f"Route {route_id} -> {result}")
Enter fullscreen mode Exit fullscreen mode

Real comparison result

Route 1 -> estimated_cost: 0.051
Route 2 -> estimated_cost: 0.051
Route 3 -> estimated_cost: 0.052
Enter fullscreen mode Exit fullscreen mode

Even small differences matter at scale.


What this enables

With estimation in the flow, you can build:

  • pre-send approval logic
  • balance-aware execution
  • route cost comparison
  • budget controls
  • safer OTP and transactional pipelines

Estimate is not just a number.

It is part of execution design.


Why this matters

In most systems:

pricing is discovered after execution

Here:

pricing is known before execution

That changes how you build backend messaging systems.


Closing

Most SMS APIs tell you what you spent.

BridgeXAPI lets you decide whether to spend at all.

This is not just pricing visibility.

This is pre-send execution control.


Next

→ debug failed SMS

→ build OTP flows

→ programmable routing vs black box APIs

Top comments (0)