FlaresendDocs

@flaresend/client

The official TypeScript client. Sends over HTTP from any runtime with fetch, or over RPC from Cloudflare Workers.

@flaresend/client is the client for your Flaresend mailer. It is written in TypeScript, ships ESM and CommonJS builds with type definitions, and has one runtime dependency, @flaresend/types.

npm install @flaresend/client

Three entry points

ImportWhat it isRuns in
@flaresend/clientFlaresend, the HTTP client for the whole REST API, plus errors, webhook helpers and typesAnything with fetch: Node.js 18+, Bun, Deno, browsers, Workers
@flaresend/client/rpcrpcClient, for Workers that call the mailer over a service bindingCloudflare Workers in the same account as the mailer
@flaresend/client/webhooksverifyWebhookSignature and friends, on their ownAnything with Web Crypto

Each entry point is separate, so a Worker that only verifies webhooks doesn't bundle the HTTP client.

Quick look

import { Flaresend } from '@flaresend/client';

const flaresend = new Flaresend({
  apiKey: process.env.FLARESEND_API_KEY!,
  baseUrl: 'https://mailer.example.com',
});

const { id } = await flaresend.emails.send({
  from: 'Acme <hello@acme.com>',
  to: 'ada@example.com',
  subject: 'Welcome to Acme',
  html: '<p>Thanks for signing up.</p>',
});
const email = await flaresend.emails.get(id);

Which one should I use?

  • Your code runs in a Cloudflare Worker in the same account as the mailer: use RPC. There is no key to store or leak, and the call doesn't go over the public internet.
  • Anything else (a Node.js server, a serverless function on another platform, a script, a Worker in another account): use HTTP with a project API key.
  • Never use the HTTP client with an API key in a browser. The key would be visible to anyone.

Other languages

There is no official client for other languages yet. The REST API is plain JSON over HTTPS, so any HTTP library works. See the quickstarts for Python, Go, PHP and Ruby, and the API reference.

Versioning

@flaresend/client and @flaresend/types are always released together at the same version, following semantic versioning. While the version is 0.x, a breaking change bumps the minor version. Release notes are on the GitHub releases page.

On this page