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

# SDKs

> Send email from your TypeScript or Python backend with the official Segmentflow SDKs.

Segmentflow has official SDKs for TypeScript and Python. They cover sending email (`emails.send`, `emails.batchSend`, `emails.get`) and reading Templates. Call every other endpoint over HTTP.

| Language | Install | Source |
| - | - | - |
| TypeScript / Node.js 20+ | `npm install @segmentflow/node` | [segmentflow/segmentflow-node](https://github.com/segmentflow/segmentflow-node) |
| Python 3.10+ | `pip install segmentflow` | [segmentflow/segmentflow-python](https://github.com/segmentflow/segmentflow-python) |

> [!WARNING]
>
> Use the SDKs on your server only. An API Key can send email as your
> Organization, so it must never reach a browser or a mobile app. The TypeScript
> client refuses to run in a browser.

## Set up

1. In the dashboard, verify a Sending Domain and add a sender (Integrations → Email). See [Sending domain](https://segmentflow.ai/docs/sending-domain.md).
2. Create an API Key (Settings → API Keys → Create API Key) with purpose **Unified API** and scopes **Send emails**. See [Authentication](https://segmentflow.ai/docs/authentication.md).
3. Store the key as the `SEGMENTFLOW_API_KEY` environment variable on your server. Both SDKs read it by default.

## Send your first email

```ts TypeScript theme={null}
import { SegmentflowClient } from "@segmentflow/node";

const segmentflow = new SegmentflowClient(); // reads SEGMENTFLOW_API_KEY

const sent = await segmentflow.emails.send({
  templateId: "018f7a35-2c2f-7e13-9b10-35f6d96d7a70",
  to: { email: "ada@example.com" },
  data: { orderNumber: "1042" },
});

const email = await segmentflow.emails.get({ id: sent.id });
console.log(email.status); // Queued, Processing, Sent, Failed, Skipped or DeliveryUnknown
```

```python Python theme={null}
from segmentflow import SegmentflowClient

segmentflow = SegmentflowClient()  # reads SEGMENTFLOW_API_KEY

sent = segmentflow.emails.send(
    template_id="018f7a35-2c2f-7e13-9b10-35f6d96d7a70",
    to={"email": "ada@example.com"},
    data={"orderNumber": "1042"},
)

email = segmentflow.emails.get(sent.id)
print(email.status)  # Queued, Processing, Sent, Failed, Skipped or DeliveryUnknown
```

A Template's id is the last part of its editor address in the dashboard (`/templates/email/<id>`). To send by a stable name instead, give the Template a key (in the editor, **More actions** → **Template key**) and pass `templateKey` (`template_key` in Python); see [Templates](https://segmentflow.ai/docs/templates.md#give-a-template-a-key). To send HTML you render yourself, use `emails.sendJsxEmail` in TypeScript or `emails.send_html` in Python. See [Emails](https://segmentflow.ai/docs/emails.md) for every option.

## What the SDKs do for you

* **Idempotency.** Every send carries an idempotency key. When you pass none, the SDK creates one, so its own retries never send the same email twice. Pass your own key, such as `order-1042-receipt`, to stay safe when your job restarts too.
* **Retries.** `408`, `429` and `5xx` responses are retried twice by default, honouring `Retry-After`. Set `maxRetries` (TypeScript) or `max_retries` (Python) on the client to change that.
* **Typed errors.** Failed requests raise errors such as `UnauthorizedError`, `ConflictError` and `TooManyRequestsError`, each with the status code and response body.
* **Types.** Requests and responses are fully typed in TypeScript and Python.

## Other languages and endpoints

Events, Journeys, Segments, Subscription Groups, Broadcasts and the other endpoints aren't in the SDKs. Call them with any HTTP client and the `x-api-key` header; each guide shows the request. The [API Reference](https://segmentflow.ai/docs/api-reference/overview) is generated from the OpenAPI spec, which you can also use to generate a client for another language.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.