# Send an SMS (/docs/api-reference/sms/send-sms)

Queues a text message from the API key's environment and returns it with `status: "queued"`; it is handed to the carrier moments later. Follow it with `GET /v1/sms/{id}` or the `sms.sent`, `sms.delivered`, `sms.undelivered` and `sms.failed` webhooks. Live (`coss_live_…`) keys send `from` one of the organization's numbers whose carrier registration is approved, to the countries the organization allows (US and Canada unless changed in the dashboard). Sandbox (`coss_test_…`) keys accept any `from`, deliver nothing and answer the SMS simulator's numbers (`+15005550006` delivered, `+15005550001` invalid, `+15005550004` filtered by the carrier, `+15005550009` opted out, `+15005550008` replies). A number on the environment's SMS suppression list (it replied STOP, or it can't receive SMS) is skipped: the message is `failed` with `suppressed`. Segments count against the organization's send quota, and each is billed by the destination country.

`POST https://api.coss.com/v1/sms`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Headers

- `Idempotency-Key` (string, 1-256 characters): Makes retries safe: a repeated request with the same key and body returns the original message (with its current status) instead of sending again, for 24 hours. 1-256 characters.

## Request body

- `from` (string, required): One of your organization's phone numbers, in E.164 form. Sandbox environments accept any number.
- `to` (string, required): The recipient's mobile number, in E.164 form.
- `body` (string, required, 1-1600 characters): The text. Messages are split into segments of 153 GSM-7 or 67 Unicode characters (152 or 66 from a toll-free number; 160 or 70 for a single one), each billed; at most 10 (1,520 GSM-7 or 660 Unicode characters).
- `tags` (object[], at most 10 items): Up to 10 tags.
  - `name` (string, required): The tag's name, unique on the message.
  - `value` (string, required): The tag's value.
- `scheduled_at` (string, date-time): Send at this time instead of now (ISO 8601 with an offset, at most 30 days ahead). A time that is not in the future sends immediately.

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.sms.send({
  from: "+14155550123",
  to: "+14155550199",
  body: "Your Acme code is 482913",
  tags: [
    {
      name: "flow",
      value: "sign_in",
    },
  ],
}, {
  idempotencyKey: "welcome-user-123",
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/sms" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Idempotency-Key: welcome-user-123" \
  -H "Content-Type: application/json" \
  -d '{
  "from": "+14155550123",
  "to": "+14155550199",
  "body": "Your Acme code is 482913",
  "tags": [
    {
      "name": "flow",
      "value": "sign_in"
    }
  ]
}'
```

Python:

```python
from coss import Coss
from coss.sms import SendSmsRequestTagsItem

client = Coss()  # api_key= or COSS_API_KEY

client.sms.send(
    idempotency_key="welcome-user-123",
    from_="+14155550123",
    to="+14155550199",
    body="Your Acme code is 482913",
    tags=[
        SendSmsRequestTagsItem(
            name="flow",
            value="sign_in",
        )
    ],
)
```

Go:

```go
import (
	"context"

	coss "github.com/cosscom/coss-go"
	cossclient "github.com/cosscom/coss-go/client"
)

client := cossclient.NewClient() // option.WithAPIKey(…) or COSS_API_KEY

request := &coss.SendSmsRequest{
    IdempotencyKey: coss.String(
        "welcome-user-123",
    ),
    From: "+14155550123",
    To: "+14155550199",
    Body: "Your Acme code is 482913",
    Tags: []*coss.SendSmsRequestTagsItem{
        &coss.SendSmsRequestTagsItem{
            Name: "flow",
            Value: "sign_in",
        },
    },
}
client.Sms.Send(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

client = Coss::Client.new # api_key: or COSS_API_KEY

client.sms.send_(
  idempotency_key: "welcome-user-123",
  from: "+14155550123",
  to: "+14155550199",
  body: "Your Acme code is 482913",
  tags: [{
    name: "flow",
    value: "sign_in"
  }]
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Sms\Requests\SendSmsRequest;
use Coss\Sms\Types\SendSmsRequestTagsItem;

$client = new Coss(); // apiKey: or COSS_API_KEY

$client->sms->send(
    new SendSmsRequest([
        'idempotencyKey' => 'welcome-user-123',
        'from' => '+14155550123',
        'to' => '+14155550199',
        'body' => 'Your Acme code is 482913',
        'tags' => [
            new SendSmsRequestTagsItem([
                'name' => 'flow',
                'value' => 'sign_in',
            ]),
        ],
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.sms.requests.SendSmsRequest;
import com.coss.resources.sms.types.SendSmsRequestTagsItem;
import java.util.Arrays;
import java.util.Optional;

Coss client = Coss.builder().build(); // .apiKey(…) or COSS_API_KEY

client.sms().send(
    SendSmsRequest
        .builder()
        .from("+14155550123")
        .to("+14155550199")
        .body("Your Acme code is 482913")
        .idempotencyKey("welcome-user-123")
        .tags(
            Optional.of(
                Arrays.asList(
                    SendSmsRequestTagsItem
                        .builder()
                        .name("flow")
                        .value("sign_in")
                        .build()
                )
            )
        )
        .build()
);
```

.NET:

```csharp
using Coss;

var client = new CossClient(); // apiKey: or COSS_API_KEY

await client.Sms.SendAsync(
    new SendSmsRequest
    {
        IdempotencyKey = "welcome-user-123",
        From = "+14155550123",
        To = "+14155550199",
        Body = "Your Acme code is 482913",
        Tags = new List<SendSmsRequestTagsItem>()
        {
            new SendSmsRequestTagsItem { Name = "flow", Value = "sign_in" },
        },
    }
);
```

## Response 202

The message, accepted (`queued` or `scheduled`; `failed` when its number is suppressed). A replay returns the original message with its current status.

- `object` ("sms", required)
- `id` (string, required)
- `from` (string, required): The number it's sent from, in E.164.
- `to` (string, required): The recipient's number, in E.164.
- `body` (string, required): The text. Empty once discarded.
- `status` ("queued" | "scheduled" | "sent" | "delivered" | "undelivered" | "failed" | "canceled", required): `queued` until handed to the carrier (`sent`), then `delivered` or `undelivered` once the carrier reports. `failed`: never sent. `scheduled` and `canceled`: scheduled sends.
- `segments` (integer, required): Segments the body takes (what is billed).
- `encoding` ("gsm7" | "ucs2", required): `gsm7` fits the basic alphabet; `ucs2` is used for anything else, with smaller segments.
- `country` (string, required): ISO 3166 country of `to`.
- `tags` (object[], required): Your tags on the message.
  - `name` (string, required): The tag's name.
  - `value` (string, required): The tag's value.
- `failure` (object | null, required): Why the message failed or wasn't delivered.
  - `code` (string, required): Machine-readable reason.
  - `message` (string, required): Human-readable explanation.
- `sandbox` (boolean, required): Sent from a sandbox environment: simulated.
- `scheduled_at` (string | null, required, date-time): When it's set to send. `null`: it was sent at once.
- `sent_at` (string | null, required, date-time): When it was handed to the carrier. `null`: not yet.
- `delivered_at` (string | null, required, date-time): When the carrier reported delivery. `null`: not delivered, or not reported.
- `created_at` (string, required, date-time)

Example:

```json
{
  "object": "sms",
  "id": "sms_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "from": "+14155550123",
  "to": "+14155550199",
  "body": "Your Acme code is 482913",
  "status": "delivered",
  "segments": 1,
  "encoding": "gsm7",
  "country": "US",
  "tags": [
    {
      "name": "flow",
      "value": "sign_in"
    }
  ],
  "failure": null,
  "sandbox": false,
  "scheduled_at": null,
  "sent_at": "2026-11-10T12:00:01.000Z",
  "delivered_at": "2026-11-10T12:00:04.000Z",
  "created_at": "2026-11-10T12:00:00.000Z"
}
```

## Errors

- `400`: The body is not valid JSON (`invalid_json`) or the `Idempotency-Key` header is invalid (`invalid_idempotency_key`). Also when the `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `402`: Live sending is paused for an overdue invoice or the spend limit (`billing_hold`) or a used-up budget (`budget_exceeded`), the plan doesn't include SMS or the destination country isn't priced (`plan_feature_unavailable`) (`billing_error`). Never retried: it needs a plan change or a payment.
- `403`: The API key lacks the permission this endpoint needs (`insufficient_permissions`), its organization is suspended (`organization_suspended`), or live sending is suspended (`account_suspended`).
- `409`: Requests with this `Idempotency-Key` are racing for an expired key (`request_in_progress`).
- `413`: The request body is larger than 5 MB (`payload_too_large`).
- `415`: The body is not sent as `application/json` (`unsupported_media_type`).
- `422`: The body failed validation (`validation_error`, see `issues`), `to` isn't a valid number (`invalid_phone_number`), `from` isn't one of the organization's numbers (`sender_not_found`) or can't send yet (`sender_not_ready`), the destination country isn't allowed (`country_not_allowed`), or the `Idempotency-Key` was already used with a different body (`idempotency_key_reused`).
- `429`: Too many requests with this API key (`rate_limited`), or the message's segments exceed the send quota or too many messages went to this number in the last hour (`quota_exceeded`). Retry after `Retry-After` seconds.
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).