Docs
Email verification tool with the Vercel AI SDK
Define the tool with tool() and pass it to generateText. The example matches the AI SDK documentation for tools as of October 2026; confirm the current signatures in the AI SDK docs, because they have changed between major versions (earlier versions used a parameters field instead of inputSchema).
Tool definition
import { generateText, tool } from 'ai';
import { z } from 'zod';
const verifyEmail = tool({
description:
'Check whether one email address can receive mail. status unknown means no conclusion, not invalid.',
inputSchema: z.object({ email: z.string() }),
execute: async ({ email }) => {
const res = await fetch('https://validreach.dev/api/v1/verify/single', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VALIDREACH_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});
const body = await res.json();
if (!body.success) return { error: body.message ?? 'request failed' };
const { status, is_deliverable, reason, retryable } = body.data;
return { email, status, is_deliverable, reason, retryable };
},
});
const result = await generateText({
model, // a model from your chosen provider
tools: { verifyEmail },
prompt: 'Is user@example.com deliverable?',
});Notes
Pick the model and provider in your own configuration. Tool calls may need a step limit so the model can use the result; see the AI SDK documentation on multi-step calls.
Keep VALIDREACH_API_KEY on the server and cap how many tool calls a run may make, because each definite result spends a credit. For decisions that matter, branch on data.status in your own code rather than on the model’s summary.
Related