AI SDK Integration

Vercel AI SDK Integration

Learn about the Vercel AI SDK integration in Nuxt AI.

Nuxt AI seamlessly integrates the Vercel AI SDK (ai & @ai-sdk/vue) into your Nuxt application, providing auto-imports for all the SDK's composables and utilities.

What is the Vercel AI SDK?

The Vercel AI SDK is a library that makes it easy to build AI-powered user interfaces with:

  • Streaming - First-class support for streaming responses from AI providers
  • Vue Hooks - Composables for common AI interaction patterns
  • Edge Runtime - Support for Edge Runtime and streaming responses
  • Multiple Providers - Support for various AI providers like OpenAI, Anthropic, and more

Features Provided by Nuxt AI

The Nuxt AI module enhances the Vercel AI SDK experience in Nuxt by providing:

Auto-imports

All composables and utilities from the Vercel AI SDK are automatically imported, so you can use them directly in your components:

components/AiChat.vue
<script setup>
const { messages, input, handleSubmit } = useChat({
  api: '/api/chat'
})
</script>

TypeScript Support

Full TypeScript support for all Vercel AI SDK components and utilities.

Available Functions from ai

The following functions are auto-imported from the Vercel AI SDK:

FunctionDescriptionExample
streamTextFor streaming textts const stream = streamText('Hello, world!')
streamObjectFor streaming structured objectsts const stream = streamObject({ name: 'John', age: 30 })
generateTextFor generating textts const text = generateText('Hello, world!')
generateObjectFor generating structured objectsts const object = generateObject({ name: 'John', age: 30 })
toolFor creating toolsts const tool = tool({ name: 'John', age: 30 })
zodToJsonSchemaFor converting Zod schemas to JSON schemasts const schema = zodToJsonSchema(z.object({ name: z.string(), age: z.number() }))

Available Components from @ai-sdk/vue

The following components are auto-imported from the Vercel AI SDK:

ComponentDescriptionExample
MessageFor displaying AI messagesvue <Message :message="message" />
ChatMessagesFor displaying a list of messagesvue <ChatMessages :messages="messages" />
TextareaFor inputting textvue <Textarea v-model="input" />

Available Composables`

The following composables are auto-imported from the Vercel AI SDK:

ComposableDescriptionExample
useChatFor building chat interfaces with AI modelsvue const { messages, input, handleSubmit } = useChat({ api: '/api/chat' })
useCompletionFor simple text completionvue const { completion, complete } = useCompletion({ api: '/api/completion' })
useObjectGenerationFor generating structured objectsvue const { object, generateObject } = useObjectGeneration({ api: '/api/object-generation' })
useAssistantFor managing assistants and threadsvue const { assistant, setAssistant } = useAssistant({ api: '/api/assistant' })

Getting Started

To start using the Vercel AI SDK in your Nuxt AI application:

  1. Configure the AI providers you want to use in your nuxt.config.ts
  2. Create API endpoints in the server/api directory
  3. Use the auto-imported composables in your Vue components

For more detailed examples and a step-by-step guide on running your application with the Vercel AI SDK, visit the official Vercel AI SDK documentation.