API Documentation

Unified interface for multiple AI providers

API Usage

AIRouter provides unified API endpoints compatible with multiple AI providers. Use these endpoints to integrate AI capabilities into your applications seamlessly.

🔐 Authentication: Include your API key in the Authorization header: Authorization: Bearer YOUR_API_KEY

OpenAI Compatible Endpoint

POST /v1/chat/completions

Compatible with OpenAI's chat completions API format

curl -X POST "YOUR_AIROUTER_URL/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {
        "role": "user",
        "content": "Hello, how are you?"
      }
    ],
    "max_tokens": 150,
    "temperature": 0.7
  }'

Anthropic Compatible Endpoint

POST /v1/messages

Compatible with Anthropic's messages API format

curl -X POST "YOUR_AIROUTER_URL/v1/messages" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-3-sonnet-20240229",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Hello, Claude!"
      }
    ]
  }'

Google Gemini Compatible Endpoint

POST /v1beta/models/{model}:generateContent

Compatible with Google Gemini API format

curl -X POST "YOUR_AIROUTER_URL/v1beta/models/gemini-pro:generateContent" \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer YOUR_API_KEY" \
 -d '{
   "contents": [
     {
       "parts": [
         {
           "text": "Hello, how are you?"
         }
       ]
     }
   ],
   "generationConfig": {
     "temperature": 0.7,
     "maxOutputTokens": 150
   }
 }'
Streaming Endpoint
POST /v1beta/models/{model}:streamGenerateContent

For streaming responses from Gemini API

curl -X POST "YOUR_AIROUTER_URL/v1beta/models/gemini-pro:streamGenerateContent" \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer YOUR_API_KEY" \
 -d '{
   "contents": [
     {
       "parts": [
         {
           "text": "Write a short story about AI"
         }
       ]
     }
   ]
 }'

Models Endpoint

GET /v1/models

List all available models

curl -X GET "YOUR_AIROUTER_URL/v1/models" \
  -H "Authorization: Bearer YOUR_API_KEY"
✅ Pro Tip: You can use any OpenAI-compatible client library by simply changing the base URL to your AIRouter instance.

Claude Code Integration

Use AIRouter with Claude Code for seamless AI-powered development workflows. Choose between quick installation or manual setup based on your preferences.

Quick Installation

One-command setup with automatic configuration

🔧
Manual Installation

Step-by-step setup with full control

⚡ Quick Installation

1
One-Click Install

Run this command to automatically install and configure Claude Code with AIRouter:

curl -fsSL YOUR_AIROUTER_URL/install.sh | bash
ℹ️ What this does: Downloads Claude Code, installs it globally, and configures it to use your AIRouter instance automatically.

🔧 Manual Installation

1
Install Claude Code

First, install Claude Code using npm (requires Node.js 16+ and npm):

npm install -g @anthropic-ai/claude-code
📋 Prerequisites: Make sure you have Node.js 16+ and npm installed on your system.
2
Configuration Options

Choose one of the following configuration methods:

Option A: Environment Variables

Set up your environment to use AIRouter as the API endpoint:

export ANTHROPIC_API_KEY="YOUR_API_KEY"
export ANTHROPIC_BASE_URL="YOUR_AIROUTER_URL"

# Add to your shell profile for persistence
echo 'export ANTHROPIC_API_KEY="YOUR_API_KEY"' >> ~/.bashrc
echo 'export ANTHROPIC_BASE_URL="YOUR_AIROUTER_URL"' >> ~/.bashrc
set ANTHROPIC_API_KEY=YOUR_API_KEY
set ANTHROPIC_BASE_URL=YOUR_AIROUTER_URL

REM For persistence, add to system environment variables
setx ANTHROPIC_API_KEY "YOUR_API_KEY"
setx ANTHROPIC_BASE_URL "YOUR_AIROUTER_URL"
$env:ANTHROPIC_API_KEY="YOUR_API_KEY"
$env:ANTHROPIC_BASE_URL="YOUR_AIROUTER_URL"

# For persistence, add to PowerShell profile
Add-Content $PROFILE '$env:ANTHROPIC_API_KEY="YOUR_API_KEY"'
Add-Content $PROFILE '$env:ANTHROPIC_BASE_URL="YOUR_AIROUTER_URL"'
3
Option B: Settings File Configuration

Alternatively, you can configure Claude Code using a settings file (recommended for advanced users):

📁 Create settings file at: $HOME/.claude/settings.json

This file provides more granular control over Claude Code's behavior and takes precedence over environment variables.

{
  "apiKeyHelper": "\"YOUR_API_KEY\"",
  "env": {
    "ANTHROPIC_API_KEY": "YOUR_API_KEY",
    "ANTHROPIC_BASE_URL": "YOUR_AIROUTER_URL"
  },
  "permissions": {
    "allow": [],
    "deny": []
  },
  "model": "sonnet"
}
📝 Configuration Options Explained:
  • apiKeyHelper: Your API key (note the escaped quotes)
  • env: Environment variables for the API
  • permissions: Control file access permissions
  • model: Default model to use (sonnet, haiku, opus)
⚠️ Important: The settings file takes precedence over environment variables. Choose one configuration method to avoid conflicts. If you use the settings file, environment variables will be ignored.
4
Verify Installation

Test your configuration by running Claude Code to ensure everything is set up correctly:

# Check version
claude --version

# Test connection
claude "Hello, can you confirm the connection is working?"
✅ Success! If you see a response from Claude, your installation is complete and working properly.

🚀 Usage Examples

💬
Interactive Mode

Start an interactive session with Claude:

claude
Direct Command

Send a direct command to Claude:

claude "Help me debug this Python script"
📁
File Processing

Process specific files with Claude:

claude --file script.py "Optimize this code for performance"
🔧
Advanced Usage

Use Claude Code with specific models and options:

# Use specific model
claude --model claude-3-opus-20240229 "Complex reasoning task"

# Process multiple files
claude --file *.py "Review all Python files for security issues"

# Set custom temperature
claude --temperature 0.2 "Generate precise documentation"
💡 Pro Tips:
  • Use claude --help to see all available options
  • The settings file allows for more advanced configurations like custom prompts
  • You can switch between different AIRouter instances by changing the base URL
  • Environment variables are great for CI/CD pipelines