FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GenstackOrg/Host · GitHub

Repository files navigation

Genstack SDK Host

Genstack SDK Host is a FastAPI-based backend service that acts as a secure, multi-provider LLM (Large Language Model) gateway. It enables unified, authenticated, and auditable access to models from OpenAI, Google Gemini, and Anthropic, with robust tracking, encryption, and extensibility.


Table of Contents


Features

  • Unified LLM Gateway: Route requests to OpenAI, Google Gemini, and Anthropic models via a single API.
  • API Key Authentication: Secure endpoints with per-user/project API keys.
  • Encrypted Provider Keys: Provider credentials are encrypted using Fernet.
  • Track & Audit: Per-model usage and error tracking, with periodic sync to Firestore.
  • Extensible: Easily add new providers or models.
  • Type-Safe & Modern: Built with FastAPI, async/await, and type hints.
  • Test & CI Friendly: Designed for robust testing and CI/CD.

Architecture

flowchart TD
    Client["Client (SDK/HTTP)"]
    API["FastAPI Server"]
    Router["Router (Provider Logic)"]
    Redis["Upstash Redis (Cache/Keys/Tracks)"]
    Providers["LLM Providers (OpenAI, Gemini, Anthropic)"]
    Firestore["Firestore (Persistent Usage Tracking)"]

    Client -->|HTTP POST /api/v1/sdk/generate| API
    API --> Router
    Router --> Redis
    Router -->|API Call| Providers
    Router --> Firestore
Loading

API Reference

POST /api/v1/sdk/generate

  • Description: Generate a response from a specified LLM provider/model.
  • Headers: x-api-key: <your-api-key>
  • Body: See Request Schema
  • Response: See Response Schema

GET /api/v1/sdk/generate

  • Description: Not allowed. Returns 405 with a message to use POST.

Request & Response Schemas

Request Schema

Example (app/schemas/request.json):

{
  "model": "gemini-2-5-pro-ggl",
  "config": {
    "streaming": false,
    "think": true,
    "tools": [""]
  },
  "messages": [
    {"role": "user", "content": "Hi! How are you doing?"}
  ]
}

Response Schema

Example (app/schemas/response.json):

{
  "data": "something"
}

Note: Actual response structure may vary by provider and model. See Formatter for details.


Authentication & Security

  • API Key: All requests require a valid x-api-key header.
  • Provider Keys: Stored encrypted using Fernet (FERNET_KEY in .env).
  • Track Data: Usage and error counts are tracked per model and periodically flushed to Firestore.

Usage

Prerequisites

  • Python 3.10+
  • Redis (Upstash or compatible)
  • Google Firestore
  • Provider API keys (OpenAI, Google Gemini, etc.)
  • .env file with all required secrets (see below)

Quickstart (Windows)

# Install dependencies
python -m venv env
env\Scripts\activate
pip install -r requirements.txt

# Set up .env (see below)
# Run the server
runserver.bat

Example Request

curl -X POST http://localhost:8000/api/v1/sdk/generate \
  -H "x-api-key: <your-api-key>" \
  -H "Content-Type: application/json" \
  -d @app/schemas/request.json

Environment Variables

Create a .env file in the project root with:

FERNET_KEY=...
UPSTASH_PROVIDERS_URL=...
UPSTASH_PROVIDERS_TOKEN=...
UPSTASH_KEYS_URL=...
UPSTASH_KEYS_TOKEN=...
UPSTASH_TRACKS_URL=...
UPSTASH_TRACKS_TOKEN=...
OPENAI_API_KEY=...
GEMINI_API_KEY=...
# Firebase credentials are loaded from app/firebase/firebase-adminsdk.json

Development

  • Run Locally: uvicorn app.main:app --reload
  • Lint: ruff .
  • Type Check: mypy .
  • Tests: See tests/ and app/test/

Testing

  • Example test scripts for OpenAI and Gemini are in app/test/.
  • To run all tests: pytest

Deployment

  • Docker: (Dockerfile is present, but currently empty. Add your build steps as needed.)
  • Production: Use a production ASGI server (e.g., uvicorn or gunicorn with uvicorn.workers.UvicornWorker).

Contributing

Contributions are welcome! Please open issues or pull requests.


License

MIT (or specify your license here)

Releases

Packages

Contributors

Languages


Back | FazBrowse Home | New Git URL