Vercel AI SDK

Operations

Wire myagentmail into the Vercel AI SDK as tool definitions for generateText and streamText.

The Vercel AI SDK uses Zod schemas to define tools. We have no SDK package — you wrap our REST endpoints inline in a tools object. Below is a minimal kit you can paste into any project.

import { generateText, tool } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { z } from "zod";

const API = "https://myagentmail.com/v1";
const KEY = process.env.MYAGENTMAIL_KEY!;

async function mam(method: string, path: string, body?: unknown) {
  const r = await fetch(`${API}${path}`, {
    method,
    headers: { "X-API-Key": KEY, "Content-Type": "application/json" },
    body: body ? JSON.stringify(body) : undefined,
  });
  if (!r.ok) throw new Error(`${method} ${path} → ${r.status}: ${await r.text()}`);
  return r.json();
}

const myagentmailTools = {
  create_inbox: tool({
    description: "Create a new email inbox.",
    parameters: z.object({
      username: z.string().optional(),
      displayName: z.string().optional(),
    }),
    execute: async (args) => mam("POST", "/inboxes", args),
  }),

  send_message: tool({
    description:
      "Send an email from an inbox. Pass verified=true when you've validated the recipient.",
    parameters: z.object({
      inboxId: z.string(),
      to: z.union([z.string().email(), z.array(z.string().email())]),
      subject: z.string(),
      plainBody: z.string().optional(),
      htmlBody: z.string().optional(),
      verified: z.boolean().default(true),
    }),
    execute: async ({ inboxId, ...body }) =>
      mam("POST", `/inboxes/${inboxId}/send`, body),
  }),

  list_messages: tool({
    description: "List messages in an inbox, filtered by direction.",
    parameters: z.object({
      inboxId: z.string(),
      direction: z.enum(["inbound", "outbound"]).optional(),
      limit: z.number().int().min(1).max(100).default(20),
    }),
    execute: async ({ inboxId, direction, limit }) => {
      const q = new URLSearchParams({ limit: String(limit) });
      if (direction) q.set("direction", direction);
      return mam("GET", `/inboxes/${inboxId}/messages?${q}`);
    },
  }),

  reply_to_message: tool({
    description: "Reply to a message in-thread.",
    parameters: z.object({
      inboxId: z.string(),
      messageId: z.string(),
      plainBody: z.string(),
    }),
    execute: async ({ inboxId, messageId, ...body }) =>
      mam("POST", `/inboxes/${inboxId}/reply/${messageId}`, body),
  }),
};

// Use it
const result = await generateText({
  model: anthropic("claude-sonnet-4-6"),
  prompt: "Create an inbox called 'sales-bot', then send a hello to [email protected].",
  tools: myagentmailTools,
});

Add as many tools as your agent needs — the pattern is identical for every endpoint. The full surface is in the API reference; copy the input schema from the corresponding OpenAPI requestBody.