npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tooly/resend

v0.0.7

Published

Resend API tools for OpenAI, Anthropic, and AI SDK

Readme

@tooly/resend

Resend API tools for OpenAI, Anthropic, and AI SDK. Convert Resend's email API into AI-compatible tools for sending, retrieving, updating, and canceling emails.

Installation

npm install @tooly/resend
# or
pnpm add @tooly/resend
# or
yarn add @tooly/resend

Features

  • sendEmail: Send a single email
  • sendBatchEmails: Send up to 100 batch emails at once
  • retrieveEmail: Retrieve email details by ID
  • updateEmail: Update a scheduled email
  • cancelEmail: Cancel a scheduled email

Quick Start

Basic Usage

import { ResendTools } from '@tooly/resend'

const resendTools = new ResendTools('your-resend-api-key')

// Get all available tools
const tools = resendTools.getTools()

// Execute a function directly
const result = await resendTools.executeFunction('sendEmail', {
  from: '[email protected]',
  to: ['[email protected]'],
  subject: 'Hello from Resend!',
  html: '<p>This is a test email.</p>',
})

Usage with OpenAI

import OpenAI from 'openai'
import { createOpenAIFunctions } from '@tooly/resend'

const openai = new OpenAI({
  apiKey: 'your-openai-api-key',
})

const { tools, executeFunction } = createOpenAIFunctions('your-resend-api-key')

const completion = await openai.chat.completions.create({
  model: 'gpt-4.1-nano',
  messages: [
    {
      role: 'user',
      content: 'Send a welcome email to [email protected] with the subject "Welcome to our platform!"',
    },
  ],
  tools: tools.map((tool) => ({
    type: 'function',
    function: tool,
  })),
})

// Handle function calls
const message = completion.choices[0].message
if (message.tool_calls) {
  for (const toolCall of message.tool_calls) {
    if (toolCall.type === 'function') {
      const result = await executeFunction(toolCall.function.name, JSON.parse(toolCall.function.arguments))
      console.log('Email sent:', result)
    }
  }
}

Usage with Anthropic

import Anthropic from '@anthropic-ai/sdk'
import { createAnthropicTools } from '@tooly/resend'

const anthropic = new Anthropic({
  apiKey: 'your-anthropic-api-key',
})

const { tools, executeFunction } = createAnthropicTools('your-resend-api-key')

const message = await anthropic.messages.create({
  model: 'claude-sonnet-4-20250514',
  max_tokens: 1024,
  messages: [
    {
      role: 'user',
      content: 'Send a welcome email to [email protected]',
    },
  ],
  tools: tools,
})

// Handle function calls
if (message.content.some((content) => content.type === 'tool_use')) {
  for (const content of message.content) {
    if (content.type === 'tool_use') {
      const result = await executeFunction(content.name, content.input)
      console.log('Email sent:', result)
    }
  }
}

Usage with AI SDK

import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { createAITools } from '@tooly/resend'

const tools = createAITools('your-resend-api-key')

const { text } = await generateText({
  model: openai('gpt-4.1-nano'),
  prompt: 'Send a welcome email to [email protected] with subject "Welcome!"',
  tools: tools,
})

console.log(text)

API Reference

ResendTools

Main class for managing Resend tools.

const resendTools = new ResendTools(apiKey: string);

Methods

  • getTools(): Returns all available tool definitions
  • executeFunction(name: string, parameters: any): Execute a tool function by name
  • getHandlers(): Get direct access to handler methods

Available Tools

sendEmail

Send a single email using Resend.

Parameters:

  • from (string, required): Sender email address
  • to (string[], required): Recipient email addresses (max 50)
  • subject (string, required): Email subject
  • html (string, optional): HTML version of the message
  • text (string, optional): Plain text version of the message
  • bcc (string[], optional): BCC recipients
  • cc (string[], optional): CC recipients
  • reply_to (string[], optional): Reply-to addresses
  • scheduled_at (string, optional): Schedule email for later
  • headers (object, optional): Custom headers
  • attachments (array, optional): File attachments
  • tags (array, optional): Custom tags for tracking

Example:

await executeFunction('sendEmail', {
  from: '[email protected]',
  to: ['[email protected]'],
  subject: 'Hello!',
  html: '<p>Hello world!</p>',
  text: 'Hello world!',
})

sendBatchEmails

Send up to 100 batch emails at once.

Parameters:

  • emails (array, required): Array of email objects (max 100)

Example:

await executeFunction('sendBatchEmails', {
  emails: [
    {
      from: '[email protected]',
      to: ['[email protected]'],
      subject: 'Hello User 1!',
      html: '<p>Hello User 1!</p>',
    },
    {
      from: '[email protected]',
      to: ['[email protected]'],
      subject: 'Hello User 2!',
      html: '<p>Hello User 2!</p>',
    },
  ],
})

retrieveEmail

Retrieve details of a single email by ID.

Parameters:

  • id (string, required): The email ID to retrieve

Example:

await executeFunction('retrieveEmail', {
  id: '49a3999c-0ce1-4ea6-ab68-afcd6dc2e794',
})

updateEmail

Update a scheduled email.

Parameters:

  • id (string, required): The email ID to update
  • scheduled_at (string, optional): New scheduled time

Example:

await executeFunction('updateEmail', {
  id: '49a3999c-0ce1-4ea6-ab68-afcd6dc2e794',
  scheduled_at: 'in 2 hours',
})

cancelEmail

Cancel a scheduled email.

Parameters:

  • id (string, required): The email ID to cancel

Example:

await executeFunction('cancelEmail', {
  id: '49a3999c-0ce1-4ea6-ab68-afcd6dc2e794',
})

Environment Variables

You can set your Resend API key as an environment variable:

RESEND_API_KEY=your-resend-api-key

Then use it in your code:

const resendTools = new ResendTools(process.env.RESEND_API_KEY!)

Error Handling

All functions include proper error handling and will throw descriptive errors:

try {
  const result = await executeFunction('sendEmail', {
    from: 'invalid-email',
    to: ['[email protected]'],
    subject: 'Test',
  })
} catch (error) {
  console.error('Failed to send email:', error.message)
}

TypeScript Support

This package includes full TypeScript support with proper type definitions:

import type { SendEmailParams, EmailResponse, EmailDetails } from '@tooly/resend'

Requirements

  • Node.js 18+
  • A Resend API key (get one at resend.com)
  • A verified domain in Resend (for sending from your own domain)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.