Vercel AI SDK Provider
Use WebInfer with the Vercel AI SDK for streaming, tool calling, and more
Installation
npm install ../webinfer/packages/vercel-ai-provider ai@^7 # repository previewBasic Usage
Import the webinfer provider and use it with any Vercel AI SDK function:
import { webinfer } from 'webinfer-ai-provider'import { generateText } from 'ai'const result = await generateText({ model: webinfer(), // [!code highlight] prompt: 'Explain TypeScript in simple terms'})console.log(result.text)WebInfer automatically selects the best available model based on user configuration.
Task-Based Routing
Specify a task type and hints to guide model selection:
import { webinfer } from 'webinfer-ai-provider'import { generateText } from 'ai'const result = await generateText({ model: webinfer({ // [!code highlight] task: 'coding', // [!code highlight] hints: { // [!code highlight] quality: 'high', // [!code highlight] speed: 'fast' // [!code highlight] } // [!code highlight] }), // [!code highlight] prompt: 'Write a React hook for fetching data'})console.log(result.text)speed: fastest, fast, balanced, quality
quality: draft, standard, high, best
costPriority: free, budget, balanced, premium
capabilities: multilingual, codeGeneration, reasoning, longContext, math
Streaming
Stream responses in real-time using streamText:
import { webinfer } from 'webinfer-ai-provider'import { streamText } from 'ai'const { textStream } = streamText({ // [!code highlight] model: webinfer(), prompt: 'Write a short story about a robot learning to paint'})let text = ''for await (const chunk of textStream) { // [!code highlight] text += chunk // [!code highlight]}Tool Calling
Define tools that the AI can use. Tools execute client-side in the browser:
import { webinfer } from 'webinfer-ai-provider'import { generateText, tool } from 'ai'import { z } from 'zod'const result = await generateText({ model: webinfer(), prompt: 'What is the weather in San Francisco?', tools: { // [!code highlight] getWeather: tool({ // [!code highlight] description: 'Get weather for a location', // [!code highlight] inputSchema: z.object({ // [!code highlight] location: z.string().describe('City name') // [!code highlight] }), // [!code highlight] execute: async ({ location }) => { // [!code highlight] // This runs in the browser! // [!code highlight] return { temp: 72, condition: 'sunny', location } // [!code highlight] } // [!code highlight] }) // [!code highlight] }})console.log(result.text)Client-side tool execution means no server round-trips - AI can directly update the UI, play sounds, or manipulate the DOM.
React Example
Call the browser-only provider directly from a client component:
'use client'import { useState } from 'react'import { streamText } from 'ai'import { webinfer } from 'webinfer-ai-provider'export function Chat() { const [answer, setAnswer] = useState('') async function submit() { setAnswer('') const result = streamText({ model: webinfer(), prompt: 'Explain browser AI' }) for await (const chunk of result.textStream) { setAnswer(current => current + chunk) } } return ( <button type="button" onClick={() => void submit()}> {answer || 'Ask WebInfer'} </button> )}How Model Selection Works
Unlike traditional AI SDK providers where you specify a model like openai('gpt-4'), WebInfer uses intelligent routing. When you call webinfer():
Request sent to WebInfer extension
The extension receives your task type and hints
Router evaluates options
Scores available models by 16 criteria (speed, quality, cost, capabilities)
Best model executes request
Could be Claude, GPT-4, browser-managed on-device AI, a local daemon, or another configured provider
This means users control which AI they use, not your application. Your code works with any model.
API Reference
Creates a WebInfer language model for use with Vercel AI SDK functions.
Parameters
task?: 'general' | 'coding' | 'creative' | 'summarization' | 'qa' | 'extraction' | 'translation'
hints?: { speed?, quality?, costPriority?, capabilities?, model?, provider? }
model?: string — Direct model specification (optional)
provider?: string — Direct provider specification (optional)
Returns
A LanguageModel compatible with all Vercel AI SDK functions.
Next Steps
Use the WebInfer SDK directly
View Guide →Learn how WebInfer selects models
View Routing Docs →Configure AI providers
View Provider Docs →Understand how WebInfer works
View Architecture →