> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tofrom.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Send message

> Send an SMS or MMS message through the messaging platform

## Authentication

This endpoint requires API key authentication. Include your API key in the `Authorization` header.

```
Authorization: Bearer YOUR_API_KEY
```

## Request Body

<ParamField body="to" type="string" required>
  The destination phone number in E.164 format (e.g., +15551234567)
</ParamField>

<ParamField body="body" type="string" required>
  The text content of the message to send
</ParamField>

<ParamField body="from" type="string">
  The sender phone number. If not provided, the default messaging service number will be used
</ParamField>

## Response

<ResponseField name="sid" type="string">
  The unique identifier for the sent message from the provider
</ResponseField>

<ResponseField name="status" type="string">
  The current status of the message (e.g., "queued", "sent", "delivered")
</ResponseField>

<ResponseExample>
  ```json theme={null}
  {
    "sid": "SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "status": "queued"
  }
  ```
</ResponseExample>

## Error Responses

<ResponseField name="error" type="string">
  The error code indicating what went wrong
</ResponseField>

<ResponseField name="detail" type="string">
  Additional details about the error
</ResponseField>

### Error Codes

* `missing_params` (400) - Required parameters are missing from the request
* `provider_not_configured` (400) - The workspace doesn't have a messaging provider configured
* `send_failed` (500) - Message sending failed due to an internal error

<RequestExample>
  ```bash theme={null}
  curl -X POST https://api.example.com/api/messages \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "to": "+15551234567",
      "body": "Hello from the messaging API!",
      "from": "+15559876543"
    }'
  ```

  ```javascript theme={null}
  const response = await fetch('https://api.example.com/api/messages', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      to: '+15551234567',
      body: 'Hello from the messaging API!',
      from: '+15559876543'
    })
  });

  const data = await response.json();
  ```

  ```python theme={null}
  import requests

  response = requests.post(
      'https://api.example.com/api/messages',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
      },
      json={
          'to': '+15551234567',
          'body': 'Hello from the messaging API!',
          'from': '+15559876543'
      }
  )

  data = response.json()
  ```
</RequestExample>
