Run AI Models

Run machine learning models, such as LLMs, in Nuxt.

NuxtHub AI makes integrating AI models such as text generation, image generation, embeddings, and more into your Nuxt application simple and intuitive via AI SDK.

Getting Started

  1. Enable AI in NuxtHub by setting the ai property to your provider in hub within your nuxt.config.ts file.
nuxt.config.ts
export default defineNuxtConfig({
  hub: {
    ai: 'vercel' // or 'cloudflare'
  }
})
  1. Install the ai package
pnpm add ai
  1. Authenticate with the AI provider.

Generate an API key from the Vercel AI Gateway dashboard.

Set the AI_GATEWAY_API_KEY environment variable to configure AI Gateway.

.env
AI_GATEWAY_API_KEY=your-api-key

Alternatively, if you manage local environment variables on Vercel, you can run npx vercel env pull .env to authenticate using OIDC for 12 hours.

Automatic Configuration

When building the Nuxt app, NuxtHub automatically configures the specified AI provider on many providers.

  1. Install the @ai-sdk/gateway package
pnpm add @ai-sdk/gateway
  1. Vercel AI Gateway is automatically configured when deploying to Vercel.

Usage

hubAI() provides pre-configured AI SDK provider either of Vercel AI Gateway or Cloudflare Workers AI.

Use hubAI() when passing a model to to AI SDK.

const result = streamText({
  // When using Vercel AI Gateway
  model: hubAI('mistral/mistral-large'),
  // When using Cloudflare Workers AI
  model: hubAI('@cf/meta/llama-3.3-70b-instruct-fp8-fast'),

  prompt: 'Who created Nuxt?',
});
Learn more about AI SDK on their documentation.

Models

See all supported models on the Vercel AI Gateway documentation.

Examples