Skip to main content

Free multi-provider AI SDK with OpenAI-compatible server and 27+ provider routing

Project description

AI Synapse

PyPI Python License: MIT Tests

Free multi-provider AI SDK with drop-in OpenAI compatibility, intelligent routing across 27+ providers, automatic key rotation, and an optional local OpenAI-compatible server. Use it as a Python library, run your own API gateway, or add the terminal chat UI.

pip install ai-synapse              # SDK — routing, failover, OpenAI client
pip install ai-synapse[server]      # SDK + local OpenAI-compatible server
pip install ai-synapse[all]         # SDK + server + terminal chat (TUI)

Latest: v1.0.3 — test harness, rotation mutmut gate, httpx 0.28, docs refresh. See CHANGELOG.


Python SDK

Drop-in OpenAI client that routes across free-tier and self-hosted providers with failover, per-provider API key rotation, health-aware routing, and model caching.

from ai_engine import OpenAI

client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

CLI (entry point ai-engine or python -m ai_engine):

ai-engine chat "Explain quantum tunneling"
ai-engine serve --port 8000          # local OpenAI-compatible server
ai-engine providers                # list configured providers
ai-engine status                   # quick provider counts
ai-engine version
python -m ai_engine tui            # optional terminal UI

More examples: examples/sdk/


Local server

OpenAI-compatible HTTP API on your machine — same routing engine as the SDK, plus dashboard, provider management, metrics, and chat persistence.

mkdir -p ~/.ai-engine && cp .env.example ~/.ai-engine/.env
# edit ~/.ai-engine/.env — add provider API keys

pip install ai-synapse[server]
python -m ai_engine serve
Endpoint URL
OpenAI API http://localhost:8000/v1/
Universal router http://localhost:8000/v1/uni
Swagger UI http://localhost:8000/docs
Health http://localhost:8000/health

Point any OpenAI SDK at base_url="http://localhost:8000/v1":

from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Routed through AI Synapse"}],
)

Server docs: API reference · Server guide · Deployment


Configuration

Provider API keys load in layers. When the same variable appears in multiple places, the higher layer wins.

Priority Source Typical use
1 (highest) Shell / container env (export GROQ_API_KEY=…) CI, Docker, secrets
2 AI_SYNAPSE_ENV=/path/to/profile.env Named profiles
3 ./.env in current working directory Per-project overrides
4 (lowest) ~/.ai-engine/.env Global config after pip install

Global setup (pip install)

mkdir -p ~/.ai-engine
cp .env.example ~/.ai-engine/.env
# edit ~/.ai-engine/.env — GROQ_API_KEY, OPENROUTER_API_KEY, etc.

Project overrides (git clone / editable install)

pip install -e ".[server]"
cp .env.example .env
python -m ai_engine serve

Runtime modes (developers)

Variable Values Purpose
AI_ENGINE_MODE testing, live, all Filter providers (testing = mock harness only)

See .env.example and provider keys guide.


Terminal chat (optional)

Textual-based terminal UI — same SDK routing. Install only if you want a local chat app in the terminal.

pip install ai-synapse[tui]    # or ai-synapse[all]
python -m ai_engine tui

Main chat

Sidebar history, model/provider routing, slash commands, @ file attach, vision. docs/TUI.md


Documentation

Doc Contents
API reference HTTP endpoints (server)
Server guide Dashboard, providers, metrics
User guide Web dashboard & chat UI
Architecture Routing, failover, caching
Provider keys Free-tier signup
Deployment Docker, production
TUI guide Terminal chat (optional)
Contributing Dev setup, tests, mutmut gate

Development

git clone https://github.com/mihir0209/AI_engine.git
cd AI_engine
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev,server]"

# Non-live tests (mock provider on 127.0.0.1:18765 — no live API calls)
AI_ENGINE_MODE=testing pytest tests/ -m "not live" --timeout=30 -q

ruff check core tests ai_engine

Key rotation and server paths are covered by integration + unit tests; optional local mutation gate: ./scripts/mutmut_rotation_gate.sh 90 after mutmut run. Details in CONTRIBUTING.md.


License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_synapse-1.0.3.tar.gz (300.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_synapse-1.0.3-py3-none-any.whl (286.2 kB view details)

Uploaded Python 3

File details

Details for the file ai_synapse-1.0.3.tar.gz.

File metadata

  • Download URL: ai_synapse-1.0.3.tar.gz
  • Upload date:
  • Size: 300.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ai_synapse-1.0.3.tar.gz
Algorithm Hash digest
SHA256 078b9f0d444727a6f237b8ec2d39179cc933b29261bc512c34e546a80a37efd6
MD5 6a57fe9c37c25821e95280a5268dd324
BLAKE2b-256 2a19b31d6a59317407697e2b4fcc39783f66f0ce7687449bbfb81d83c3cc2056

See more details on using hashes here.

File details

Details for the file ai_synapse-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: ai_synapse-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 286.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ai_synapse-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b2aafd57b62578dbf5c3b66b4f529172b6bf1f6aea3d6b56f724ff1586856a6b
MD5 4278a4e29be519fe77536842f7de550e
BLAKE2b-256 c1e0a82c5987ddc2891b0b657101deef0e16e8512b2368c987265203a2324edb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page