To give an LLM a send-SMS tool, expose a narrow function that takes a contact ID and a message, resolve the phone number on your server, check consent and limits before sending, and use the tool call's ID to build the idempotency key. The model proposes a text, and your code decides whether it goes out.

We make Ready, so the send uses the Ready REST API. If you'd rather connect an agent directly, Ready also runs an MCP server, covered in our MCP post. This guide is for the function-calling route, where you own the tool.

Keep the schema narrow

{
  "name": "send_text",
  "description": "Send one text message to a contact the user is already talking to.",
  "input_schema": {
    "type": "object",
    "properties": {
      "contact_id": { "type": "string" },
      "message": { "type": "string", "maxLength": 300 }
    },
    "required": ["contact_id", "message"]
  }
}

The tool takes a contact_id, not a phone number. The model never types a number, so it can't be talked into texting a stranger, and a prompt injection in a customer's reply can't redirect the text. Cap the message length in the schema, and again in code.

The handler

def handle_send_text(call, session):
    contact = db.contacts.get(call.input["contact_id"], tenant=session.tenant)
    if contact is None:
        return {"error": "unknown contact"}
    if not contact.sms_consent or contact.opted_out:
        return {"error": "contact has not agreed to texts"}
    if session.texts_sent >= 3:
        return {"error": "limit reached for this conversation"}
    if not session.auto_approved:
        return queue_for_human(contact, call.input["message"], call.id)

    key = str(uuid.uuid5(uuid.NAMESPACE_URL, f"{session.id}:{call.id}"))
    res = requests.post(
        "https://api.tryready.com/v1/messages",
        json={"to": contact.phone_e164, "body": call.input["message"], "consent_attested": True},
        headers={"X-API-Key": os.environ["READY_API_KEY"], "Idempotency-Key": key},
        timeout=15,
    )
    body = res.json()
    if not res.ok:
        return {
            "sent": False,
            "code": body.get("error_code") or body.get("code"),
            "message": body.get("error"),
            "next_allowed_at": body.get("next_allowed_at"),
        }
    session.texts_sent += 1
    return {"sent": True, "message_id": body.get("data", {}).get("message_id")}

Each model response with a tool call has an ID, and models sometimes repeat a call. Deriving the idempotency key from the session and call ID means a repeated key means the request isn't sent twice, even if the agent loop re-runs the same step. Return plain errors the model can read ("limit reached", or the code and message Ready sends back) so it can explain to the user instead of retrying in circles, and count a text only when the API accepted it. Approval is the default here: the handler sends on its own only for a session your code has marked auto_approved.

Guardrails that matter

RiskControl
Texting the wrong personResolve contact IDs server-side, scoped to the tenant
Prompt injection from a replyNever put reply text where the model can pick recipients
Runaway sendsPer-conversation and per-day caps in code
Unwanted wordingLength cap, a human approval step for first contact
No consentCheck your own consent record, and set consent_attested only when true

The model's text is also an AI-written message to a real person, so keep a person in the loop wherever a mistake is costly. A reply to someone who just texted you can go out at any hour, and a first message to someone who hasn't texted you lately can come back as a 409 QUIET_HOURS_BLOCK, which means it isn't sent and you send it again once the window opens. Our guardrails post goes deeper on all of this.

Log the whole chain

Store the tool call ID, the model's proposed text, any human edit, the key and the API status. When a customer asks why they got a message, that record is the answer. See observability for SMS for what to keep.

FAQ

Can the agent read replies too?

Yes, through your webhook receiver. Pass replies in as plain data, label them as untrusted customer text in the prompt, and never let them change tool permissions.

Should the model set consent_attested?

No. That's your statement about your records, so your code sets it, only after checking them.

How do I test without texting anyone?

Use a test key, which simulates send requests and refuses anything that would change or bill an account.

The short version

A narrow tool, server-side contact lookup, consent and cap checks, and a key built from the tool call ID. The messages API docs cover the request.

Cost and registration

A segment on the Standard rate is $0.0075 plus a $0.0045 carrier fee, excluding optional screening. An account can send up to 500 texts a month before it registers for 10DLC, and most approvals take 2 to 7 days. See pricing for the full list.