# Create a broadcast (/docs/api-reference/broadcasts/create-broadcast)

Creates a draft, or with `send` or `scheduled_at` a broadcast that starts sending (so it needs `broadcast:send` too). A broadcast goes to every contact of its audience or segment who is subscribed, reached by its topic and not suppressed, as one email each, at the plan's marketing rate.

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

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 broadcast created first instead of creating another, for 24 hours. 1-256 characters.

## Request body

- `name` (string, required, 1-200 characters): Shown only to you.
- `audience_id` (string): Send to this audience…
- `segment_id` (string): …or to this segment (one of the two).
- `topic` (string): The topic the broadcast is about (its key): only contacts it reaches get it, and its unsubscribe link leaves just that topic. It is the emails' `category`.
- `from` (string, required)
- `reply_to` (string[], at most 10 items): Addresses replies go to.
- `subject` (string, required, 1-998 characters): May use `{{{contact.<key>|fallback}}}` (e.g. `{{{contact.first_name|there}}}`).
- `preview_text` (string, at most 500 characters): The inbox preview line (a hidden preheader at the start of the HTML).
- `html` (string, at most 1000000 characters): `{{{contact.<key>|fallback}}}` for contact fields and properties (escaped), and `{{{unsubscribe_url}}}`, `{{{preferences_url}}}`, `{{{mailing_address}}}`; a footer with the postal address and an unsubscribe link is added unless they are there.
- `text` (string, at most 1000000 characters): The plain text part. Takes the same placeholders as `html`.
- `tracking` (object): Which opens and clicks are tracked.
  - `opens` (boolean): Track opens with a pixel.
  - `clicks` (boolean): Track clicks by rewriting links.
- `rate_per_second` (integer, 1-1000): Recipients per second, at most the plan's marketing rate (the default).
- `send` (boolean): Start sending right away.
- `scheduled_at` (string, date-time): Start sending at this time (ISO 8601 with an offset, at most 30 days ahead).

## 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.email.broadcasts.create({
  name: "October newsletter",
  segment_id: "seg_01k7c8m4q2f3e9v6t5r1n0p8yz",
  topic: "newsletter",
  from: "Acme <news@acme.com>",
  subject: "What's new, {{{contact.first_name|there}}}",
  html: "<p>Hi {{{contact.first_name|there}}},</p><p>…</p><p><a href=\"{{{unsubscribe_url}}}\">Unsubscribe</a></p>",
  scheduled_at: "2026-10-20T09:00:00Z",
}, {
  idempotencyKey: "welcome-user-123",
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/broadcasts" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Idempotency-Key: welcome-user-123" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "October newsletter",
  "segment_id": "seg_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "topic": "newsletter",
  "from": "Acme <news@acme.com>",
  "subject": "What'\''s new, {{{contact.first_name|there}}}",
  "html": "<p>Hi {{{contact.first_name|there}}},</p><p>…</p><p><a href=\"{{{unsubscribe_url}}}\">Unsubscribe</a></p>",
  "scheduled_at": "2026-10-20T09:00:00Z"
}'
```

Python:

```python
from coss import Coss
import datetime

client = Coss()  # api_key= or COSS_API_KEY

client.email.broadcasts.create(
    idempotency_key="welcome-user-123",
    name="October newsletter",
    segment_id="seg_01k7c8m4q2f3e9v6t5r1n0p8yz",
    topic="newsletter",
    from_="Acme <news@acme.com>",
    subject="What\'s new, {{{contact.first_name|there}}}",
    html="<p>Hi {{{contact.first_name|there}}},</p><p>…</p><p><a href=\"{{{unsubscribe_url}}}\">Unsubscribe</a></p>",
    scheduled_at=datetime.datetime.fromisoformat("2026-10-20T09:00:00+00:00"),
)
```

Go:

```go
import (
	"context"

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

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

request := &email.CreateBroadcastRequest{
    IdempotencyKey: coss.String(
        "welcome-user-123",
    ),
    Name: "October newsletter",
    SegmentID: coss.String(
        "seg_01k7c8m4q2f3e9v6t5r1n0p8yz",
    ),
    Topic: coss.String(
        "newsletter",
    ),
    From: "Acme <news@acme.com>",
    Subject: "What's new, {{{contact.first_name|there}}}",
    HTML: coss.String(
        `<p>Hi {{{contact.first_name|there}}},</p><p>…</p><p><a href="{{{unsubscribe_url}}}">Unsubscribe</a></p>`,
    ),
    ScheduledAt: coss.Time(
        coss.MustParseDateTime(
            "2026-10-20T09:00:00Z",
        ),
    ),
}
client.Email.Broadcasts.Create(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

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

client.email.broadcasts.create(
  idempotency_key: "welcome-user-123",
  name: "October newsletter",
  segment_id: "seg_01k7c8m4q2f3e9v6t5r1n0p8yz",
  topic: "newsletter",
  from: "Acme <news@acme.com>",
  subject: "What's new, {{{contact.first_name|there}}}",
  html: "<p>Hi {{{contact.first_name|there}}},</p><p>…</p><p><a href=\"{{{unsubscribe_url}}}\">Unsubscribe</a></p>",
  scheduled_at: "2026-10-20T09:00:00Z"
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Email\Broadcasts\Requests\CreateBroadcastRequest;

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

$client->email->broadcasts->create(
    new CreateBroadcastRequest([
        'idempotencyKey' => 'welcome-user-123',
        'name' => 'October newsletter',
        'segmentId' => 'seg_01k7c8m4q2f3e9v6t5r1n0p8yz',
        'topic' => 'newsletter',
        'from' => 'Acme <news@acme.com>',
        'subject' => "What's new, {{{contact.first_name|there}}}",
        'html' => '<p>Hi {{{contact.first_name|there}}},</p><p>…</p><p><a href="{{{unsubscribe_url}}}">Unsubscribe</a></p>',
        'scheduledAt' => new DateTime('2026-10-20T09:00:00Z'),
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.email.broadcasts.requests.CreateBroadcastRequest;
import java.time.OffsetDateTime;

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

client.email().broadcasts().create(
    CreateBroadcastRequest
        .builder()
        .name("October newsletter")
        .from("Acme <news@acme.com>")
        .subject("What's new, {{{contact.first_name|there}}}")
        .idempotencyKey("welcome-user-123")
        .segmentId("seg_01k7c8m4q2f3e9v6t5r1n0p8yz")
        .topic("newsletter")
        .html("<p>Hi {{{contact.first_name|there}}},</p><p>…</p><p><a href=\"{{{unsubscribe_url}}}\">Unsubscribe</a></p>")
        .scheduledAt(OffsetDateTime.parse("2026-10-20T09:00:00Z"))
        .build()
);
```

.NET:

```csharp
using Coss;
using Coss.Email;

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

await client.Email.Broadcasts.CreateAsync(
    new CreateBroadcastRequest
    {
        IdempotencyKey = "welcome-user-123",
        Name = "October newsletter",
        SegmentId = "seg_01k7c8m4q2f3e9v6t5r1n0p8yz",
        Topic = "newsletter",
        From = "Acme <news@acme.com>",
        Subject = "What's new, {{{contact.first_name|there}}}",
        Html =
            "<p>Hi {{{contact.first_name|there}}},</p><p>…</p><p><a href=\"{{{unsubscribe_url}}}\">Unsubscribe</a></p>",
        ScheduledAt = new DateTime(2026, 10, 20, 09, 00, 00, 000),
    }
);
```

## Response 201

The new broadcast.

- `object` ("broadcast", required)
- `id` (string, required)
- `name` (string, required): Shown only to you.
- `status` ("draft" | "scheduled" | "sending" | "paused" | "sent" | "canceled" | "failed", required): `draft` (editable), `scheduled`, `sending`, `paused` (see `pause_reason`), `sent`, `canceled`, or `failed` (see `error`).
- `audience_id` (string | null, required): The audience it goes to. `null`: a segment.
- `segment_id` (string | null, required): The segment it goes to. `null`: an audience.
- `topic` (string | null, required): The topic it's about (its key), and its emails' `category`. `null`: none.
- `from` (string, required): Who it's sent from.
- `reply_to` (string[], required): Addresses replies go to.
- `subject` (string, required): The subject, before contact fields are filled in.
- `preview_text` (string | null, required): The inbox preview line. `null`: none.
- `html` (string | null, required): The HTML part, before contact fields are filled in. `null`: text only.
- `text` (string | null, required): The plain text part. `null`: HTML only.
- `tracking` (object, required): Which opens and clicks are tracked.
  - `opens` (boolean, required): Whether opens are tracked.
  - `clicks` (boolean, required): Whether clicks are tracked.
- `rate_per_second` (integer | null, required): Recipients per second. `null`: the plan's marketing rate.
- `scheduled_at` (string | null, required, date-time): When it's set to start. `null`: not scheduled.
- `started_at` (string | null, required, date-time): When sending started. `null`: it hasn't.
- `completed_at` (string | null, required, date-time): When it finished. `null`: it hasn't.
- `canceled_at` (string | null, required, date-time): When it was canceled. `null`: it wasn't.
- `recipients_estimated` (integer | null, required): How many contacts it would reach, counted when it started.
- `pause_reason` (string | null, required): Why a paused broadcast waits: `paused` (by you), `billing_hold`, `budget_exceeded`, `usage_limit`, `marketing_paused`, `account_suspended`, `sending_paused`.
- `error` (object | null, required): Why it `failed`, such as `target_unavailable` when its audience, segment or topic was deleted while sending. `null`: it didn't.
  - `code` (string, required): Machine-readable reason.
  - `message` (string, required): Human-readable explanation.
- `stats` (object, required): How its emails fared so far.
  - `recipients` (integer, required): Emails made so far (one per reached contact).
  - `sent` (integer, required): Emails accepted by the provider.
  - `delivered` (integer, required): Emails delivered to recipients' servers.
  - `bounced` (integer, required): Permanent bounces.
  - `complained` (integer, required): Emails marked as spam by recipients.
  - `failed` (integer, required): Emails that couldn't be sent.
  - `opened` (integer, required): Emails opened at least once (with open tracking).
  - `clicked` (integer, required): Emails clicked at least once (with click tracking).
  - `unsubscribed` (integer, required): Unsubscribes through the broadcast's links.
- `created_at` (string, required, date-time)
- `updated_at` (string, required, date-time)

Example:

```json
{
  "object": "broadcast",
  "id": "bcast_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "name": "October newsletter",
  "status": "sent",
  "audience_id": null,
  "segment_id": "seg_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "topic": "newsletter",
  "from": "Acme <news@acme.com>",
  "reply_to": [],
  "subject": "What's new, {{{contact.first_name|there}}}",
  "preview_text": null,
  "html": "<p>Hi {{{contact.first_name|there}}},</p>",
  "text": null,
  "tracking": {
    "opens": true,
    "clicks": true
  },
  "rate_per_second": null,
  "scheduled_at": "2026-10-20T09:00:00.000Z",
  "started_at": "2026-10-20T09:00:01.000Z",
  "completed_at": "2026-10-20T09:12:40.000Z",
  "canceled_at": null,
  "recipients_estimated": 1200,
  "pause_reason": null,
  "error": null,
  "stats": {
    "recipients": 1200,
    "sent": 1200,
    "delivered": 1180,
    "bounced": 6,
    "complained": 1,
    "failed": 0,
    "opened": 540,
    "clicked": 120,
    "unsubscribed": 4
  },
  "created_at": "2026-10-15T12:00:00.000Z",
  "updated_at": "2026-10-20T09:12:40.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`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `409`: Requests with this `Idempotency-Key` are racing (`request_in_progress`); retry.
- `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, the audience, segment or topic doesn't exist (`invalid_target`, `topic_not_found`), its content could render too long (`content_too_large`), the `Idempotency-Key` was used with another body (`idempotency_key_reused`), or it can't start (see `POST …/send`).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).