Quick Start
Make your first AI request with WebInfer in 5 minutes
Your First AI Request
This guide will walk you through making your first AI request with WebInfer.
Prerequisites
- Node.js 22+ installed
- WebInfer extension loaded from
apps/extension/dist(or daemon running) - At least one available provider: an API key, Chrome's browser-managed built-in AI, or a local daemon
Step 1: Build the early preview
WebInfer is not yet published under its intended npm name. Use the repository build during the preview; this avoids installing the unrelated package that currently owns the unscoped name.
terminal
# Early preview: the public npm package has not shipped yet.# The unscoped "webinfer" package on npm belongs to another project.git clone https://github.com/iplanwebsites/webinfer.gitcd webinfernpm installnpm run build:clientnpm run build:extensionStep 2: Import and Use
Add this to a browser application in the cloned workspace:
app.js
import { generateText } from '@webinfer/client'// Simple text generationconst result = await generateText({ prompt: 'Write a haiku about programming'})console.log(result.text)Run the repository demo to exercise the same API through the extension:
terminal
npm run dev:site# Open http://localhost:5500/demoThat's it! You've made your first AI request with WebInfer.
Understanding the Response
The generateText function returns a response object with:
response.ts
{ text: string // The generated text finishReason: string model?: string // Which model was used provider?: string // Which provider executed it requestId?: string usage: { promptTokens: number completionTokens: number totalTokens: number cost?: number // Estimated cost in USD }}Step 3: Different Use Cases
Use generateText for various AI tasks:
tasks.js
// Summarizationconst summary = await generateText({ prompt: 'Summarize the following article: [your long text here]'})console.log(summary.text)// Coding taskconst code = await generateText({ prompt: 'Write a React component for a todo list in TypeScript'})console.log(code.text)// Creative writingconst story = await generateText({ prompt: 'Write a short story about a robot'})console.log(story.text)Step 4: Streaming Responses
For real-time text generation:
streaming.js
import { streamText } from '@webinfer/client'const stream = await streamText({ prompt: 'Write a long story about space exploration'})for await (const chunk of stream.textStream) { document.querySelector('#output')?.append(chunk)}Next Steps
Now that you've made your first request, explore more features:
- Browser Usage - Learn about the WebInfer SDK
- Provider Setup - Configure multiple providers
- Intelligent Routing - Understand how WebInfer selects models
- Examples - See more code examples