30% extra credits on top-ups within 24 hours of signup.

Integrations / Vercel AI SDK

Vercel AI SDK tools to send SMS and email

Hail has no Node SDK. The examples call the REST API with fetch and a bearer key. The tools let a Vercel AI SDK agent send SMS and email.

1. Set the key

Create an API key in the Hail console and expose it to your server runtime only.

# .env.local
HAIL_API_KEY="hl_live_9fa2..."

2. Define the tools

The AI SDK's tool() takes a Zod schema and an execute function. recipient_consent is a required field. The API refuses a send without it.

import { generateText, tool } from "ai";
import { z } from "zod";

const hail = (path: string, body: unknown) =>
  fetch(`https://api.hail.so${path}`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.HAIL_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(body),
  }).then((r) => r.json());

const sendSms = tool({
  description: "Text an opted-in recipient.",
  inputSchema: z.object({ to: z.string(), body: z.string() }),
  execute: ({ to, body }) =>
    hail("/sms", { to, body, recipient_consent: true }),
});

3. Use them in generateText

The model selects the tool. Hail sends delivery events to your webhook.

const { text } = await generateText({
  model: "anthropic/claude-sonnet-5",
  tools: { sendSms },
  prompt: "Text +14155550142 that order 4471 shipped.",
});

Questions

Is there a Hail Node SDK?

No. The examples call the REST API with fetch and a bearer key. An OpenAPI spec is available for typed clients.

Where do delivery receipts go?

Register a webhook URL. Hail signs each delivery and retries on a fixed schedule. Your route handler can verify the signature and remove duplicate events.

Run the examples

The examples above run as written with a Hail account and an API key. You pay for usage.

Create account

Guides for other frameworks