Get Started
Install and configure AI-Model-Wrapper-for-OpenAI
Install and configure AI-Model-Wrapper-for-OpenAI: A clean, TypeScript-based wrapper for the OpenAI API with built-in conversation management, streaming support, and optional debug logging.
Follow the source instructions for AI-Model-Wrapper-for-OpenAI. Read the prerequisites and configuration steps before running an example.
Installation
Prerequisites
# Required dependencies
npm install openai
npm install -D typescript @types/node
# Or if using Bun
bun add openai
bun add -D typescript @types/nodeBasic Setup
// Create the library file
// Save as ai-model-lib.ts in your projectQuick Start
1. Basic Setup
import { AIModel } from './ai-model-lib';
// Simplest usage with OpenRouter (free tier available)
const ai = new AIModel({
apiKey: 'your-api-key-here',
provider: 'openrouter',
debug: true
});
// Send a message and get response
const response = await ai.sendTextMessage('Hello, how are you?');
console.log(response.content);2. Environment Variables Setup
# .env file
OPENROUTER_API_KEY=your_openrouter_key_here
OPENAI_API_KEY=your_openai_key_here
ANTHROPIC_API_KEY=your_anthropic_key_here// Create from environment variables
const ai = AIModel.createFromEnv('openrouter', {
temperature: 0.7,
maxTokens: 1000
});Configuration
Model Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | Required | Provider API key |
provider | string | "openrouter" | Provider ID |
model | string | Provider default | Specific model name |
temperature | number | 0.7 | Creativity (0.0-1.0) |
maxTokens | number | 1000 | Response length limit |
systemPrompt | string | "" | AI context/behavior |
debug | boolean | false | Enable logging |
timeout | number | 30000 | Request timeout (ms) |
retryAttempts | number | 3 | Retry attempts on failure |
Provider Configuration
import { ProviderRegistry } from './ai-model-lib';
// Register custom provider
ProviderRegistry.registerProvider('my-provider', {
name: 'My AI Service',
baseURL: 'https://api.my-ai.com/v1',
defaultModel: 'my-model-v1',
headers: {
'X-Custom-Header': 'value'
}
});Check the installation
After setup, continue with the first example. If a command fails, compare the runtime version, working directory, and required configuration with the original README before changing dependencies.
Source and help
Source captured: 2026-10-11
