Skip to content

Repository files navigation

SynthAPI

A production-ready AI API gateway built with FastAPI. Provides a unified interface for AI chat, streaming, summarization, and model management through Groq (free) or any OpenAI-compatible provider.

Features

  • AI Chat -- Chat with LLMs with multi-turn session history
  • Streaming -- Real-time token-by-token responses (SSE) like ChatGPT
  • Summarization -- Brief and detailed text summarization modes
  • Model Registry -- Browse, search, and filter 12+ AI models
  • User Tiers -- Free vs premium model access control
  • Model Configuration -- Configure model parameters per request
  • API Authentication -- Header-based API key validation
  • Rate Limiting -- Tier-based request throttling (free/premium)
  • Session History -- Multi-turn conversation memory
  • Docker Ready -- One-command deployment

Tech Stack

  • Framework: FastAPI
  • Validation: Pydantic
  • LLM Provider: Groq (free tier) -- uses OpenAI SDK format
  • Containerization: Docker + Docker Compose

Quick Start

git clone https://github.com/mryusefi/AI-API-Bootcamp.git
cd AI-API-Bootcamp

python -m venv .venv
.venv\Scripts\activate      # Windows
source .venv/bin/activate   # Mac/Linux

pip install -r requirements.txt

echo GROQ_API_KEY=your_key_here > .env

uvicorn main:app --reload

Visit http://127.0.0.1:8000/docs for interactive API documentation.

Docker

docker build -t synthapi .
docker run -p 8000:8000 --env-file .env synthapi

API Endpoints

Public (no auth required)

Method Endpoint Description
GET / Health check
GET /model-info Current model info
GET /models/{model_name} Get model details
GET /search/models Search/filter models with pagination

Protected (API key required: X-API-Key header)

Method Endpoint Description
POST /chat Chat with AI (sync, with optional session history)
POST /chat/stream Chat with AI (real-time streaming SSE)
POST /summarize Summarize text (brief/detailed modes)
POST /models/{model_name}/configure Configure model settings
GET /chat/history/{session_id} Get conversation history
POST /chat/delete/{session_id} Clear conversation history

Usage Example

# Chat (streaming)
curl -X POST http://localhost:8000/chat/stream \
  -H "Content-Type: application/json" \
  -H "X-API-Key: api_key_1" \
  -d '{"message": "What is FastAPI?"}'

# Summarize
curl -X POST http://localhost:8000/summarize \
  -H "Content-Type: application/json" \
  -H "X-API-Key: api_key_1" \
  -d '{"text": "Your long document here...", "style": "brief"}'

# Search models
curl "http://localhost:8000/search/models?providers=openai&limit=3"

Project Structure

synthapi/
├── main.py                   # App entry point
├── models.py                 # Pydantic request/response schemas
├── config.py                 # Constants and settings
├── data/
│   ├── models_db.py          # AI model registry (12 models)
│   └── chat_history.py       # In-memory session storage
├── middleware/
│   ├── auth.py               # API key authentication
│   └── rate_limiter.py       # Tier-based rate limiting
├── routers/
│   ├── health.py             # Health check
│   ├── models_registry.py    # Model browsing, search, config
│   └── chat.py               # Chat, streaming, summarization
├── services/
│   └── llm.py                # LLM integration (Groq/OpenAI)
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── .env                      # API keys (gitignored)

Environment Variables

Variable Description
GROQ_API_KEY Your Groq API key (get one free at console.groq.com)

Switching LLM Providers

This project uses Groq by default (free tier: 14,400 requests/day). To switch to OpenAI or any compatible provider, change one line in config.py:

GROQ_BASE_URL = "https://api.groq.com/openai/v1"   # Groq (default, free)
# GROQ_BASE_URL = "https://api.openai.com/v1"        # OpenAI (paid)

License

MIT

About

A production-ready AI API gateway built with FastAPI. Provides a unified interface for AI chat, streaming, summarization, and model management through Groq (free) or any OpenAI-compatible provider.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages