Skip to content

Repository files navigation

Universal AI Gateway - README

πŸš€ What is AI Gateway?

One API to rule them all!

A universal gateway that connects to every major AI service in one place:

  • βœ… Gemini (Google) - Free
  • βœ… OpenAI (ChatGPT) - Paid
  • βœ… Claude (Anthropic) - Paid
  • βœ… Groq (Fast inference) - Free
  • βœ… Ollama (Local models) - Free
  • βœ… HuggingFace - Free
  • βœ… And more...

πŸ“‹ Quick Start

1. Clone & Setup

git clone https://github.com/NeXifiyAI/ai-gateway.git
cd ai-gateway

# Install dependencies
npm install

# Copy environment template
cp .env.example .env

2. Add Your API Keys to .env

GEMINI_API_KEY=your_key_here
OPENAI_API_KEY=sk_test_xxxxx
ANTHROPIC_API_KEY=sk-ant-xxxxx
GROQ_API_KEY=gsk_xxxxx
OLLAMA_URL=http://localhost:11434
HF_API_KEY=hf_xxxxx

3. Run Locally

Option A: Docker (Recommended)

docker-compose -f docker/docker-compose.yml up -d
# Gateway: http://localhost:3000
# Open WebUI: http://localhost:3001

Option B: Manual

npm run dev
# Gateway: http://localhost:3000

4. Deploy to Vercel

npm run deploy
# Your gateway is now live! πŸš€

πŸ’» API Usage

Python Client

from clients.ai_gateway_client import AIGatewayClient

# Local
client = AIGatewayClient('http://localhost:3000')

# Or Vercel
client = AIGatewayClient('https://your-gateway.vercel.app')

# Chat
response = client.chat('gemini', 'What is AI?')
print(response['message'])

# List models
models = client.list_models('gemini')
print(models['models'])

# Health check
health = client.health_check()
print(health['status'])

JavaScript Client

const AIGatewayClient = require('./clients/AIGatewayClient');

const client = new AIGatewayClient('http://localhost:3000');

// Chat
const response = await client.chat('gemini', 'What is AI?');
console.log(response.message);

// Models
const models = await client.listModels('gemini');
console.log(models.models);

// Health
const health = await client.healthCheck();
console.log(health.status);

cURL

# Chat
curl -X POST http://localhost:3000/api/chat \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "gemini",
    "message": "What is AI?"
  }'

# Models
curl http://localhost:3000/api/models?provider=gemini

# Health
curl http://localhost:3000/api/health

🌐 Endpoints

POST /api/chat

Send a message to any provider.

Request:

{
  "provider": "gemini",
  "message": "What is the meaning of life?",
  "model": "gemini-1.5-pro",
  "temperature": 0.7,
  "maxTokens": 1024
}

Response:

{
  "provider": "gemini",
  "model": "gemini-1.5-pro",
  "message": "The meaning of life is subjective...",
  "usage": {
    "inputTokens": 5,
    "outputTokens": 50
  }
}

GET /api/models?provider=gemini

Get available models for a provider.

Response:

{
  "provider": "gemini",
  "models": [
    "gemini-1.5-pro",
    "gemini-1.5-flash",
    "gemini-1.0-pro"
  ]
}

GET /api/health

Check gateway health and provider status.

Response:

{
  "status": "ok",
  "timestamp": "2025-01-17T10:30:00Z",
  "providers": [
    {
      "name": "Gemini",
      "status": "configured"
    },
    {
      "name": "OpenAI",
      "status": "not-configured"
    }
  ]
}

πŸ“¦ Supported Providers

Provider Model Speed Cost Setup
Gemini gemini-1.5-pro ⚑⚑⚑ Free Add API Key
OpenAI gpt-4-turbo ⚑⚑ Paid Add API Key
Claude claude-3-opus ⚑⚑⚑ Paid Add API Key
Groq mixtral-8x7b ⚑⚑⚑ Free Add API Key
Ollama mistral ⚑ Free Local
HuggingFace Llama-2 ⚑⚑ Free Add API Key

🐳 Docker

Start Services

# Start all (Gateway + Ollama + Open WebUI)
docker-compose -f docker/docker-compose.yml up -d

# View logs
docker-compose -f docker/docker-compose.yml logs -f

# Stop all
docker-compose -f docker/docker-compose.yml down

Services

πŸš€ Vercel Deployment

1. Push to GitHub

git add .
git commit -m "Initial commit: AI Gateway"
git push origin main

2. Deploy to Vercel

npm run deploy

Or manually on vercel.com:

  1. Connect your GitHub repository
  2. Add environment variables
  3. Deploy!

3. Your Gateway is Live!

https://your-project.vercel.app/api/chat

πŸ” Security

  • βœ… API keys stored in environment variables
  • βœ… CORS enabled (configurable)
  • βœ… No keys exposed in logs
  • βœ… Rate limiting recommended for production

πŸ“š Examples

React Component

import { useState } from 'react';
import AIGatewayClient from './clients/AIGatewayClient';

const client = new AIGatewayClient(process.env.REACT_APP_GATEWAY_URL);

export function ChatComponent() {
  const [message, setMessage] = useState('');
  const [response, setResponse] = useState('');

  const handleSend = async () => {
    const result = await client.chat('gemini', message);
    setResponse(result.message);
  };

  return (
    <div>
      <input value={message} onChange={e => setMessage(e.target.value)} />
      <button onClick={handleSend}>Send</button>
      <p>{response}</p>
    </div>
  );
}

FastAPI Integration

from fastapi import FastAPI
from clients.ai_gateway_client import AIGatewayClient

app = FastAPI()
client = AIGatewayClient('https://your-gateway.vercel.app')

@app.post('/ask')
async def ask(question: str, provider: str = 'gemini'):
    response = client.chat(provider, question)
    return response

πŸ› οΈ Development

# Install dependencies
npm install

# Run locally with hot reload
npm run dev

# Build
npm run build

# Deploy to production
npm run deploy

πŸ“ Files

ai-gateway/
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ gateway.js        # Core routing logic
β”‚   β”œβ”€β”€ chat.js           # Chat endpoint
β”‚   β”œβ”€β”€ models.js         # Models endpoint
β”‚   └── health.js         # Health check
β”œβ”€β”€ clients/
β”‚   β”œβ”€β”€ ai_gateway_client.py    # Python client
β”‚   └── AIGatewayClient.js      # JavaScript client
β”œβ”€β”€ docker/
β”‚   └── docker-compose.yml      # Local development
β”œβ”€β”€ vercel.json           # Vercel config
β”œβ”€β”€ package.json          # Dependencies
β”œβ”€β”€ .env.example          # Environment template
└── README.md             # This file

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file

πŸ™‹ Support

  • πŸ“š Documentation: See /docs
  • πŸ› Issues: GitHub Issues
  • πŸ’¬ Discord: [Community Server]
  • πŸ“§ Email: support@nexifiyai.com

Made with ❀️ by NeXifiyAI

GitHub | Website

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages