Vercel AI SDK Provider
Use WebInfer with the Vercel AI SDK for streaming, tool calling, and more
Installation
npm install webinfer-ai-provider aiBasic 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 } = await streamText({ // [!code highlight] model: webinfer(), prompt: 'Write a short story about a robot learning to paint'})for await (const chunk of textStream) { // [!code highlight] process.stdout.write(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] parameters: 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
Use WebInfer in a React component with the useChat hook:
'use client'import { useChat } from 'ai/react'import { webinfer } from 'webinfer-ai-provider'export function Chat() { const { messages, input, handleInputChange, handleSubmit } = useChat({ // Note: useChat typically connects to an API route, // but you can use webinfer directly in client components }) return ( <div> {messages.map(m => ( <div key={m.id}> <strong>{m.role}:</strong> {m.content} </div> ))} <form onSubmit={handleSubmit}> <input value={input} onChange={handleInputChange} /> <button type="submit">Send</button> </form> </div> )}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, a local model, or any 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 →