# Install and configure AI-Model-Wrapper-for-OpenAI

Follow the source instructions for **AI-Model-Wrapper-for-OpenAI**. Read the prerequisites and configuration steps before running an example.

## Installation

### Prerequisites

```bash
# Required dependencies
npm install openai
npm install -D typescript @types/node

# Or if using Bun
bun add openai
bun add -D typescript @types/node
```

### Basic Setup

```typescript
// Create the library file
// Save as ai-model-lib.ts in your project
```

## Quick Start

### 1. Basic Setup

```typescript
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

```bash
# .env file
OPENROUTER_API_KEY=your_openrouter_key_here
OPENAI_API_KEY=your_openai_key_here
ANTHROPIC_API_KEY=your_anthropic_key_here
```

```typescript
// 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

```typescript
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](/docs/up-to-code-ai-model-wrapper-for-openai/quick-start-guide). If a command fails, compare the runtime version, working directory, and required configuration with the original README before changing dependencies.

## Source and help

- [GitHub repository](https://github.com/Up-to-code/AI-Model-Wrapper-for-OpenAI)
- [Original README](https://github.com/Up-to-code/AI-Model-Wrapper-for-OpenAI/blob/main/README.md)
- [Issues and existing reports](https://github.com/Up-to-code/AI-Model-Wrapper-for-OpenAI/issues)
