WebInfer

Vercel AI SDK Provider

Use WebInfer with the Vercel AI SDK for streaming, tool calling, and more

Installation

terminal
npm install webinfer-ai-provider ai

Basic Usage

Import the webinfer provider and use it with any Vercel AI SDK function:

app.ts
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:

task-routing.ts
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)
Available Tasks
general
General purpose
coding
Code generation
creative
Creative writing
summarization
Text summarization
qa
Question answering
extraction
Data extraction
translation
Language translation
Hints

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:

streaming.ts
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:

tools.ts
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:

Chat.tsx
'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():

1

Request sent to WebInfer extension

The extension receives your task type and hints

2

Router evaluates options

Scores available models by 16 criteria (speed, quality, cost, capabilities)

3

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

webinfer(settings?)

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

Browser Usage

Use the WebInfer SDK directly

View Guide →
Model Routing

Learn how WebInfer selects models

View Routing Docs →
Providers

Configure AI providers

View Provider Docs →
Architecture

Understand how WebInfer works

View Architecture →