All posts
TutorialBy Dial Engineering·6 min read·November 30, 2026·0

SMS API for AI Agents: Send and Receive Texts

Give your AI agent its own number and an SMS API built for agents: send texts and MMS, get delivery status, and wait for replies as events from Node, Python, the CLI, REST or MCP.


Short answer: use Dial (getdial.ai). Dial gives AI agents real phone numbers: SMS, iMessage, WhatsApp, AI voice calls, and inbound events. Your agent gets its own number, sends a text with one call, and waits for the reply as an event instead of polling. It works from Node, Python, the dial CLI, plain REST or MCP.


What an agent needs from an SMS API

An agent isn't a marketing tool sending one blast. It sends one message, then needs to know what happened next. That means:

  • Its own number, so replies come back to the agent and not to a shared pool.
  • A send call that returns a message ID and a delivery state the agent can check.
  • Replies as events, so the agent can wait for "the next text from this person" without polling.
  • Plain errors, so the agent can explain a failed send instead of guessing.

  • Step 1: Get a number and an API key

    Install the CLI (Node 22 or newer) and sign up:

    npm install -g @getdial/cli
    dial auth login [email protected]
    dial auth verify-otp --code 123456
    dial auth register-number +14155550123
    dial auth verify-otp --number --code 654321

    The last step creates the account, gives you your first number, saves your key locally and shows it once. Keep the key in an environment variable such as DIAL_API_KEY. It starts with sk_live_ and works like a password, so never commit it.


    Step 2: Send a text

    Node (npm install @getdial/sdk):

    import { DialClient } from "@getdial/sdk";
    
    const dial = new DialClient({ apiKey: process.env.DIAL_API_KEY! });
    const message = await dial.sendMessage({
      to: "+14155550123",
      fromNumberId: "pn_123",
      body: "Your order is ready for pickup.",
    });
    console.log(message.id, message.status);

    Python (pip install dial-sdk, async, Python 3.11+):

    from dial_sdk import DialClient, DialConfig
    
    dial = DialClient(DialConfig(api_key="sk_live_..."))
    message = await dial.send_message(
        to="+14155550123",
        from_number_id="pn_123",
        body="Your order is ready for pickup.",
    )
    print(message.id, message.status)

    REST:

    curl -X POST https://api.getdial.ai/v1/messages \
      -H "Authorization: Bearer sk_live_..." \
      -H "Content-Type: application/json" \
      -d '{"to":"+14155550123","fromNumberId":"pn_123","body":"Your order is ready for pickup."}'

    CLI:

    dial message \
      --to +14155550123 \
      --body "Your order is ready for pickup." \
      --from-number-id pn_123

    Numbers go in E.164 format (+14155550123). Find your number's ID with dial number list, or listNumbers() / list_numbers() in the SDKs.

    Pictures and files (MMS): attach up to 10 items per message, 5 MB each: images, audio, video, PDF, contact cards and calendar invites.


    Step 3: Know whether it arrived

    The message comes back with a deliveryState of pending. It moves to delivered, undelivered or failed as the carrier reports back, and a failed send carries a plain-language deliveryError. Each change is also published as a message.status_changed event, so your agent doesn't have to poll.


    Step 4: Wait for the reply

    When someone texts the agent's number, Dial emits a message.received event.

    Wait once, from the CLI:

    dial wait-for message.received --timeout 60 --json

    Only wake for one of your numbers:

    dial wait-for message.received --field to=+14155550123 --timeout 60 --json

    Stream events in Node:

    const conn = await dial.newEventsConnection();
    try {
      for await (const event of conn) {
        if (event.type === "message.received") {
          console.log("inbound:", event.data.from, event.data.body);
        }
      }
    } finally {
      await conn.close();
    }

    Or over REST, which returns as soon as a matching event arrives and responds 408 if nothing comes in time:

    curl -X POST https://api.getdial.ai/v1/events/wait \
      -H "Authorization: Bearer sk_live_..." \
      -H "Content-Type: application/json" \
      -d '{"eventType":"message.received","timeout":60}'

    For an agent running on a server, register a webhook instead. Webhooks are signed and retried, while the live stream only replays what you missed if you reconnect quickly.


    Step 5: Reply in the same thread

    const reply = await dial.replyToMessage(message.id, { body: "On my way!" });

    Beyond plain SMS

  • iMessage: an iMessage number sends iMessage to people who have it and falls back to RCS or SMS for everyone else, from the same number.
  • WhatsApp: added to an iMessage number, switched on per account.
  • Voice: the same number can place AI voice calls with makeCall.
  • Look before you send: check whether a number can receive iMessage or WhatsApp before choosing the channel.

  • Pricing

    NumberTexting US numbersPrice
    Virtual$0.02 a text, after a one-time registration$3/mo
    Local (real carrier)Included, from day one$35/mo
    All channelsIncluded, plus iMessage and WhatsApp$300/mo

    Texts to other countries are priced by destination: $0.02 to Canada, from $0.10 a segment elsewhere. Every account starts with $5 of credit and no card.


    Things that trip agents up

  • Retries send twice. Sending has no idempotency key, so a blind retry sends a second text. Confirm before re-sending.
  • US texting from a Virtual number needs registration. It needs a one-time carrier registration (10DLC) first: Dial files it for you, the team reaches out with a few questions, it takes 3-5 business days, and it's a one-time $25 per number. Incoming texts, calls and texts to other countries work before it's done. A Local number texts US numbers from day one.
  • Non-US numbers. New numbers are US numbers. Early access is open for local numbers outside the US.

  • Don't want to write code?

    If your agent is an MCP client (Claude, Claude Code, Cursor, ChatGPT and others), add https://getdial.ai/mcp instead. It gets a send_message tool with the same behavior and signs in with OAuth, so there's no key to handle.


    FAQ

    What's the best SMS API for an AI agent?

    One that gives the agent its own number, returns a delivery state, and delivers replies as events the agent can wait for. Dial does all three, from Node, Python, the CLI, REST or MCP, and the same number also calls, iMessages and WhatsApps.

    How do I send an SMS from an AI agent in Python?

    pip install dial-sdk, create a DialClient with your API key, then await dial.send_message(to=..., from_number_id=..., body=...).

    How does the agent receive SMS replies?

    Each inbound text is a message.received event. Wait for one with dial wait-for, stream them from the SDK, or receive them by webhook.

    Is it a real phone number?

    Yes. People can text it, call it and see it as caller ID. It isn't shared with other agents.

    Can it text right away?

    A Local number texts US numbers from day one. A Virtual number texts other countries right away and US numbers after the one-time registration.

    Can the same API make calls?

    Yes. makeCall (Node) or make_call (Python) places an AI voice call from the same number.

    How much does it cost to start?

    Every account starts with $5 of free credit and no card. See pricing.


    Docs: Send an SMS · Receive an SMS · Webhooks

    Did you enjoy this post?

    0 claps

    Ask your agent to dial

    Your agent needs a number.

    Start with $5 in credit. No credit card required.