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
Roadmap Maintainer backlog

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 scripts chat_module

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.4.tar.gz (323.4 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.4-py3-none-any.whl (318.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ai_synapse-1.0.4.tar.gz
  • Upload date:
  • Size: 323.4 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.4.tar.gz
Algorithm Hash digest
SHA256 b617b0dc4b08d75a1f49ffd09eb7f8a1db986f1d1dc2aa6197fcb26275315708
MD5 7ad221b2fe5673c186b22ee5e64a12f6
BLAKE2b-256 e2f4ac9a7bd0df472a41ceae4658200c141ac06dee41ba2d369a37327741bb39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ai_synapse-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 318.1 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 20200b86081ec259465b45170a7ab57c8e5b744c83e043ad5bd055d4abc25dc8
MD5 48cabbcef31bbfb218ae3ad017b9e534
BLAKE2b-256 20991425b7fbd0170a7cf2ef9247bce7bca5f88f640cb0657b0da74fe00c3a30

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