Skip to content

Vercel AI SDK

Terminal window
npm install ai truval
import { tool } from 'ai'
import { z } from 'zod'
export const verifyEmailTool = tool({
description: 'Verify if an email address is real and deliverable. Returns valid status, confidence score, and whether the address is disposable or a role address.',
parameters: z.object({
email: z.string().email().describe('The email address to verify'),
}),
execute: async ({ email }) => {
const res = await fetch('https://api.truval.dev/v1/email/verify', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.TRUVAL_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
})
return res.json()
},
})
import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
const result = await generateText({
model: openai('gpt-4o'),
tools: { verifyEmail: verifyEmailTool },
maxSteps: 3,
prompt: 'Is user@example.com a valid email address?',
})
console.log(result.text)
import { streamText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { verifyEmailTool } from '@/lib/tools'
export async function POST(req: Request) {
const { messages } = await req.json()
const result = streamText({
model: openai('gpt-4o'),
tools: { verifyEmail: verifyEmailTool },
maxSteps: 5,
messages,
})
return result.toDataStreamResponse()
}
Terminal window
TRUVAL_API_KEY=sk_live_...

Get your API key at dash.truval.dev.