# Primitive (/docs/v/0.6.4/adapters/primitive)



The Primitive adapter calls Primitive's `POST /v1/send-mail` endpoint over `fetch` — no extra dependency. [Primitive](https://www.primitive.dev) is email infrastructure for AI agents: a REST API for sending and receiving mail, with idempotency, typed errors, and an async delivery model. The adapter maps the normalized `EmailMessage` straight onto its send payload.

<ProviderBadge adapter="primitive" />

## Configure [#configure]

Create a Primitive API key (prefixed `prim_`) and verify the outbound domain you send `from`.

```ts title="lib/email.ts"
import { createEmailClient } from "@opencoredev/email-sdk";
import { primitive } from "@opencoredev/email-sdk/primitive";

export const email = createEmailClient({
  adapters: [primitive({ apiKey: process.env.PRIMITIVE_API_KEY! })],
});
```

<TypeTable
  type="{
  apiKey: {
    description: &#x22;Primitive API key (prefixed prim_) or OAuth access token (prefixed prim_oat_).&#x22;,
    type: &#x22;string&#x22;,
    required: true,
  },
  baseUrl: {
    description: &#x22;Override the API origin, e.g. for a proxy.&#x22;,
    type: &#x22;string&#x22;,
    default: '&#x22;https://api.primitive.dev/v1&#x22;',
  },
  fetch: {
    description: &#x22;Custom fetch implementation for tests or special runtimes.&#x22;,
    type: &#x22;typeof fetch&#x22;,
  },
  headers: {
    description: &#x22;Extra headers merged into every request.&#x22;,
    type: &#x22;Record<string, string>&#x22;,
  },
}"
/>

## Send [#send]

Primitive's send API targets a single recipient and accepts `html`, `text`, and attachments. Attachments are base64-encoded automatically.

```ts
const result = await email.send({
  from: "Acme <hello@acme.com>",
  to: "user@example.com",
  subject: "Welcome to Acme",
  html: "<p>Thanks for joining Acme.</p>",
  text: "Thanks for joining Acme.",
});

console.log(result.id); // Primitive sent-email id
```

<Callout type="warn" title="One recipient, no CC or BCC">
  Primitive's `send-mail` accepts exactly one recipient and has no CC or BCC field. The adapter
  fails fast with an `EmailValidationError` when a message carries more than one recipient, `cc`, or
  `bcc`, so route fan-out to multiple people as separate sends.
</Callout>

<Callout type="warn" title="No custom headers, tags, or metadata">
  Primitive's send API has no custom-header, tags, or metadata field, so the adapter rejects
  `headers`, `tags`, and `metadata` with an `EmailValidationError` before the request. Check [field
  support](/docs/v/0.6.4/adapters/field-support) before using Primitive in a fallback route.
</Callout>

<Callout title="From a verified outbound domain">
  The sender domain in `from` must be a verified outbound domain for your Primitive organization,
  and recipient eligibility depends on your account's outbound entitlements.
</Callout>

## Idempotent sends [#idempotent-sends]

Pass an `idempotencyKey` and the adapter forwards it as Primitive's `Idempotency-Key` header, so a retried send with the same key and body replays the original result instead of sending twice.

```ts
await email.send(message, { idempotencyKey: "receipt:order_123" });
```

## Verify from the CLI [#verify-from-the-cli]

```bash
PRIMITIVE_API_KEY="prim_..." npx email-sdk doctor --adapter primitive
```

```bash
PRIMITIVE_API_KEY="prim_..." npx email-sdk send \
  --adapter primitive \
  --from "Acme <hello@acme.com>" \
  --to user@example.com \
  --subject "Primitive smoke test" \
  --text "It works" \
  --dry-run
```

Drop `--dry-run` for one real smoke send — the only check that proves the API key and sender domain are ready.
