Skip to content

About

Blueping for Node.js: a typed client, webhook verification and the blueping CLI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Blueping for Node.js

Blueping gives your AI agent its own email inbox in one API call: username@blueping.dev, receiving at once. Every message arrives as clean JSON, with the sender's new words, verification codes (OTP) and links pulled out, attachments readable as text, and a verdict on who sent it and what it says.

This package gives you a typed client, webhook verification and the blueping CLI. It has no dependencies and runs on Node.js 18+, Bun, Deno and Cloudflare Workers.

Email inboxes for agents

An agent can have its own inbox, username@blueping.dev, in one call, with no key and no person to start: Blueping.signup() makes the agent, its key and its first inbox, which receives at once.

import { Blueping } from "blueping";

const { api_key, client, inbox } = await Blueping.signup({ name: "Acme Support", ownerEmail: "you@example.com" });
// Keep api_key: this is the only answer that shows it.

// Sign up to a service with inbox.address, then wait for its code or its sign-in link.
const { code, link } = await client.waitForCode(inbox.id, { from: "service.example" });

Until a person claims the agent, it writes only to people who wrote to it first, and to echo@blueping.dev, which answers within seconds with a test code. The owner gets a 6-digit code by email, and client.verifySignup(code) claims the agent.

With a key from your dashboard, new Blueping() reads BLUEPING_API_KEY, and each agent gets as many inboxes as its plan holds:

const blueping = new Blueping();
const support = await blueping.inboxes.create({ username: "acme-support", displayName: "Acme Support", clientId: "support" });
console.log(support.address); // acme-support@blueping.dev
const page = await client.inboxes.listMessages(inbox.id, { wait: 30 });
console.log(page.held); // what was kept back and why: includeHeld: true lists it
await client.messages.reply(page.data[0].id, { text: "Thanks, received." });
await client.inboxes.send(inbox.id, { to: "ana@example.com", subject: "Your invoice", text: "Attached.", attachments: [{ filename: "invoice.pdf", contentType: "application/pdf", content: pdfBytes }] });

The rest of the mailbox works the same way:

await client.messages.forward(page.data[0].id, { to: "accounting@example.com", text: "For the books." });
await client.messages.label(page.data[0].id, { add: ["invoices"] });
const { text } = await client.messages.attachmentText(page.data[0].id, page.data[0].attachments[0].id); // what the file says
const draft = await client.drafts.create(inbox.id, { to: "ana@example.com", subject: "Reminder", text: "Tomorrow at 9.", sendAt: new Date(Date.now() + 3_600_000) });
await client.rules.add(inbox.id, { direction: "receive", action: "block", value: "@spam.example" });

client.inboxes.listThreads() and client.threads read and label conversations, client.drafts writes, schedules and sends drafts, and client.rules keeps each inbox's allow and block lists.

Every email carries auth (SPF, DKIM and DMARC, with a verdict) and safety (text aimed at a model, hidden text). A message whose sender failed authentication, or that carries instructions for a model, is held: lists count it in held, and includeHeld: true shows it. Every send, forward and new draft carries an Idempotency-Key, so a retry sends or writes once. client.me.limits() says what the agent may send now, with warnings from 80% of a limit.

A send that meets a limit waits

A send past a limit that only takes time, such as the plan's day or month or the ramp of new recipients, is never refused for it: it comes back with status: "queued", sends_at and reason, and goes out by itself at sends_at, with every check run again. Every send's answer reads its Blueping-Usage header for you, in usage.

const sent = await client.inboxes.send(inbox.id, { to: "ana@example.com", subject: "Your invoice", text: "Attached." });
if (sent.status === "queued") console.log(`goes at ${sent.sends_at}, waiting for ${sent.reason}`);
console.log(sent.usage); // { day: { used: 42, allowed: 100 }, month: { used: 1200, allowed: 3000 } }

// Refused instead of queued, for code that decides itself: throws daily_limit_reached and the others.
await client.inboxes.send(inbox.id, { to: "ana@example.com", subject: "Now or never", text: "Hi", ifLimited: "refuse" });

Email plans

Plan Price Inboxes Emails sent a month A day
Free $0 3 3,000 100
Developer $19 a month, or $180 a year 50 15,000 1,500
Startup $79 a month, or $780 a year 500 75,000 7,500
Scale $249 a month, or $2,484 a year 5,000 300,000 30,000

Mail the agent receives never counts as a send: the plan's storage is what holds it. On Free, mail the agent sends ends with a short "Sent with Blueping" line; paid plans add nothing. client.me.mailPlanCheckout({ plan: "developer", period: "year" }) answers a payment page for the agent's owner to open in their own browser. Every limit: blueping.dev/pricing.

Many inboxes, delivery and events

// One inbox per customer, up to 50 in one call: the same clientId twice makes nothing twice.
const batch = await blueping.inboxes.createMany([{ username: "acme-1", clientId: "cust_1" }, { username: "globex", clientId: "cust_2" }]);
for await (const inbox of blueping.inboxes.iterate()) console.log(inbox.address); // page after page

// Whether mail reached people, and the addresses nothing more goes to.
const health = await blueping.inboxes.deliverability(support.id, { days: 30 });
const { suppressed } = await blueping.suppressions.get("bob@example.net").catch(() => ({ suppressed: false }));

// Every event as it happens, kept 7 days: new mail, deliveries, bounces and complaints.
for await (const event of blueping.events.iterate({ types: ["email.received", "email.bounced"] })) console.log(event.type, event.data);

// Search every inbox: the text, and on a paid plan the files' text.
const found = await blueping.search({ q: "invoice november", hasAttachment: true });
const month = await blueping.usage.get({ month: "2026-11" });

A key can be limited to one inbox and to permissions: a call past them throws PermissionDenied (with required) or InboxOutOfScope (with keyInboxId), both a BluepingError. blueping.messages.release(id) lets a held message in, with a key that holds held:release. With an admin key, new BluepingOrg() reads BLUEPING_ADMIN_KEY and creates agents and their keys: org.agents.create(), org.keys.create(), org.audit.list() and org.usage(). Keys and permissions.

Get a key in 30 seconds

An agent signs itself up from a terminal, with no key and no person. The key is saved in ~/.config/blueping/config.json, readable only by you, and never printed:

npx blueping signup --username acme-signups --owner you@example.com

A person gets a key for an account of their own by approving the terminal in their browser:

npx blueping login

The CLI shows a short code and opens a page in your browser. Sign in with Google, GitHub or your email, check that the page shows the same code and approve, with no credit card. You can also sign up at blueping.dev/signup and copy the key from the dashboard, then save it with printf %s "$KEY" | npx blueping login --with-key.

An agent working for a person uses two steps instead, so it can show the link while it waits: npx blueping login --start, then npx blueping login --check until it prints approved. Without a terminal, or with --json, a plain login starts and returns the same way.

Try it in a minute

npm install blueping
import { Blueping } from "blueping";

const blueping = new Blueping(); // reads BLUEPING_API_KEY

const inbox = await blueping.inboxes.create({ clientId: "first-try" });
await blueping.inboxes.send(inbox.id, { to: "echo@blueping.dev", subject: "Hello", text: "Testing my inbox" });

// echo@blueping.dev answers within seconds, with a test code.
const { code } = await blueping.waitForCode(inbox.id, { from: "blueping.dev" });
const { data } = await blueping.inboxes.listMessages(inbox.id);
console.log(inbox.address, code, data.map((message) => message.subject));

clientId makes the create safe to run again: the same id returns the same inbox.

Options

const blueping = new Blueping({
  apiKey: "bp_live_...",
  baseUrl: "https://blueping.dev",
  maxRetries: 2,
  timeoutMs: 30_000,
});
Option Default What it does
apiKey BLUEPING_API_KEY, then the key saved by npx blueping login on Node.js 20.16 and 22.3 or later Your API key
baseUrl BLUEPING_BASE_URL, then the saved key's server, then https://blueping.dev The API address
maxRetries 2 Retries after a network error or a 500, with the same Idempotency-Key
timeoutMs 30000 How long each attempt may take
fetch the global fetch Your own fetch implementation

Retries and idempotency

Every send, reply, forward and new draft carries an Idempotency-Key. The client makes one up and reuses it for its own retries, so a retried send never goes out twice. Blueping keeps a key 24 hours, and without one, the same message to the same people from the same inbox within 5 minutes still goes once.

Pass your own key when your code may run twice for the same event, such as a job that gets retried:

await blueping.messages.reply(messageId, {
  text: "Invoice 1042 is scheduled for payment on December 1.",
  idempotencyKey: `invoice-1042-ack`,
});

Handle errors

Every failed call throws a BluepingError with status, code, message, docs_url and details, which holds every extra field the API sent, next_action and retry_after included.

import { Blueping, BluepingError } from "blueping";

const blueping = new Blueping();

try {
  await blueping.inboxes.send(inboxId, { to: "ana@example.com", subject: "Your invoice", text: "Attached." });
} catch (error) {
  if (!(error instanceof BluepingError)) throw error;
  console.log(error.code, error.details.next_action); // what to do now, written for an agent
}
Code Status Meaning
recipient_not_allowed 403 Before a person claims the agent, it writes only to people who wrote to it first, to echo@blueping.dev and to its owner.
message_held 403 A held message isn't answered or forwarded: it waits for a person.
recipient_blocked 403 One of the inbox's own send rules refuses a recipient.
inbox_limit_reached 429 The plan's inboxes are all in use.
queue_full 429 The send met a limit and the queue is full. retry_after says when it has room.
no_code_yet 404 waitForCode found no code in time. Call it again.
too_many_recipients 400 10 addresses at most per message, to, cc and bcc together.
attachments_too_large 413 10 MB of attachments per send.
rate_limited 429 Too many requests in a short time. Wait retry_after seconds.
unauthorized 401 The API key is wrong, or was revoked.
internal_error 500 Something failed on Blueping's side. The client already retried with the same key.
network_error 0 No answer from the API, even after the retries.
missing_api_key 0 No key was passed, BLUEPING_API_KEY is not set and no key is saved.

A limit the agent's owner can lift, such as inbox_limit_reached or daily_limit_reached on Free, also carries upgrade_url and owner_message: one line, with the page where the owner decides, for the agent to pass on as it is.

Every code, with what it means and what to do: blueping.dev/docs/errors.

Receive email with a webhook

Blueping posts each event to your webhook URL as JSON: email.received when mail reaches an inbox, email.held when it is kept back, email.sent when a send goes out, email.delivered, email.deferred, email.bounced and email.complained for each recipient, email.suppressed when an address joins the suppression list, email.failed when a send fails, and email.draft_failed when a scheduled draft fails. isDeliveryEvent(event) picks the delivery events. isEmailEvent(event) tells the message events apart, and each carries data.inbox and data.message.

const hook = await blueping.webhooks.create({ url: "https://example.com/blueping", events: ["email.received", "email.bounced"] });
console.log(hook.secret); // whsec_..., store it as BLUEPING_WEBHOOK_SECRET

email.held needs a key that holds held:read.

verifyWebhook checks the Blueping-Signature header with Web Crypto, compares signatures in constant time, rejects events older than 5 minutes and returns the event, typed by its type. It throws a WebhookVerificationError otherwise. It needs the raw body exactly as it arrived, so read it before any JSON parsing.

Answer with a 2xx within 10 seconds. Failed deliveries are retried for about 31 hours, so the same event can arrive twice: dedupe on event.id.

Express

import express from "express";
import { Blueping, isEmailEvent, verifyWebhook } from "blueping";

const app = express();
const blueping = new Blueping();

app.post("/blueping", express.raw({ type: "application/json" }), async (req, res) => {
  let event;
  try {
    event = await verifyWebhook({
      rawBody: req.body, // a Buffer, thanks to express.raw()
      signature: req.get("Blueping-Signature"),
      secret: process.env.BLUEPING_WEBHOOK_SECRET,
    });
  } catch {
    return res.sendStatus(400);
  }

  res.sendStatus(200);

  if (event.type === "email.received" && isEmailEvent(event)) {
    const { id, subject } = event.data.message;
    blueping.messages.reply(id, { text: `Received: ${subject}`, idempotencyKey: event.id }).catch(console.error);
  }
});

app.listen(3000);

Hono on Cloudflare Workers

import { Hono } from "hono";
import { Blueping, isEmailEvent, verifyWebhook, type WebhookEvent } from "blueping";

type Bindings = { BLUEPING_API_KEY: string; BLUEPING_WEBHOOK_SECRET: string };

const app = new Hono<{ Bindings: Bindings }>();

app.post("/blueping", async (c) => {
  let event: WebhookEvent;
  try {
    event = await verifyWebhook({
      rawBody: await c.req.text(),
      signature: c.req.header("Blueping-Signature"),
      secret: c.env.BLUEPING_WEBHOOK_SECRET,
    });
  } catch {
    return c.text("Invalid signature", 400);
  }

  if (event.type === "email.received" && isEmailEvent(event)) {
    const blueping = new Blueping({ apiKey: c.env.BLUEPING_API_KEY });
    const { id, subject } = event.data.message;
    c.executionCtx.waitUntil(blueping.messages.reply(id, { text: `Received: ${subject}`, idempotencyKey: event.id }));
  }
  return c.body(null, 204);
});

export default app;

With Hono on Node.js there is no executionCtx: call blueping.messages.reply(...) directly.

Runtimes

  • Node.js 18 and later: works as is.
  • Bun and Deno: the same code. Deno reads BLUEPING_API_KEY when the script may read the environment (--allow-env).
  • Cloudflare Workers: there is no process.env, so pass the key from your bindings: new Blueping({ apiKey: env.BLUEPING_API_KEY }).
  • Browsers: don't. The API key would be visible to anyone. Call Blueping from your server.

CLI

The blueping command works an inbox from a terminal or an agent's shell. Every command takes --json, and none prints a key.

npx blueping signup                                   # an agent signs itself up and saves its key
npx blueping inbox create acme-support                # acme-support@blueping.dev, receiving at once
npx blueping code --from github.com                   # waits for a verification code and prints it alone
npx blueping mail --follow                            # the newest mail, then new mail as it arrives
npx blueping read em_9PzR4fYc1KwM6tDq3VxB             # one email whole, with its verdicts
npx blueping send ana@example.com --subject "Your invoice" --text "Attached."
echo "Thanks, received." | npx blueping reply em_9PzR4fYc1KwM6tDq3VxB
npx blueping limits                                   # the plan, the claim, what is left today
npx blueping upgrade --plan developer                 # a payment page for the agent's owner
npx blueping help                                     # every command and option
  • code exits with 2 when no code arrived in time, so a script can wait again.
  • claim <owner_email> emails the owner a 6-digit code, and verify <code> claims the agent with it.
  • webhooks, webhooks add <url>, webhooks test <id> and webhooks remove <id> manage webhooks. A new webhook's signing secret prints at a terminal, or goes to a private file with --secret-file.
  • upgrade prints a Stripe page for the owner to open in their own browser: nothing is bought until they pay.
  • mcp serves Blueping's hosted MCP server over stdio, for MCP clients that only start local servers: the command is npx -y blueping mcp, with BLUEPING_API_KEY set or a saved key.

The CLI uses BLUEPING_API_KEY when it is set, and the saved key otherwise. BLUEPING_BASE_URL points it at another server, such as http://localhost:8787 for local development.

In CI

A job can test your app's emails end to end: give the sign-up form a fresh inbox, wait for the email, and check its link. clientId keeps one inbox per branch, so a job that runs again reuses it:

const inbox = await blueping.inboxes.create({ clientId: `ci-${process.env.GITHUB_REF_NAME}` });
await signUp(inbox.address); // your app's own sign-up, pointed at this address
const { link } = await blueping.waitForCode(inbox.id, { from: "app.example" });
assert.ok(link, "the confirmation email arrived with its link");

Use Blueping from Claude Code and other agents

An agent can make and read its own inbox. Paste this into it:

Read https://blueping.dev/agent-onboarding.md and set yourself up with a Blueping inbox.

Or add the hosted MCP server. There is nothing to install, and it signs in through the browser:

claude mcp add --transport http blueping https://blueping.dev/mcp
claude mcp login blueping

For a client that only starts local servers, npx -y blueping mcp carries the same tools over stdio, with your key.

This package also ships two Agent Skills: skills/blueping/SKILL.md, the same skill as blueping.dev/.well-known/agent-skills/blueping/SKILL.md, and skills/blueping-cli/SKILL.md, for agents that work through this CLI. Copy either folder into your agent's skills folder.

Cursor, Codex, ChatGPT, a key instead of OAuth, the skill and the plugin: blueping.dev/agents. Every framework and client, set up in a few lines: blueping.dev/integrations.

License

MIT

About

Blueping for Node.js: a typed client, webhook verification and the blueping CLI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages