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 18+ installed
- WebInfer extension installed (or daemon running)
- At least one provider configured (API key or local model)
Step 1: Install WebInfer
terminal
npm install webinferStep 2: Import and Use
Create a new file called app.js:
app.js
import { generateText } from 'webinfer'// Simple text generationconst result = await generateText({ prompt: 'Write a haiku about programming'})console.log(result.text)Run it:
terminal
node app.jsThat'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 model: string // Which model was used provider: string // Which provider executed it usage: { inputTokens: number outputTokens: number totalTokens: number } metadata: { latency: number // Response time in ms 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'const stream = await streamText({ prompt: 'Write a long story about space exploration'})for await (const chunk of stream) { process.stdout.write(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