A3M Router Python SDK
Intelligent LLM routing — auto-selects the cheapest capable model from 47+ providers.
Routes queries to the best model for your needs — whether it's Groq for simple Q&A ($0.001/1K) or GPT-4o for complex reasoning ($0.15/1K).
Installation
pip install a3m-router
Quick Start
from a3m import A3MRouter
router = A3MRouter(base_url="http://localhost:8787")
# Auto-routes to optimal provider
response = await router.chat("What is 2+2?")
# → Routes to Groq, costs ~$0.000001
# See routing decision before executing
decision = await router.route("Explain quantum computing")
print(f"Model: {decision.model}")
print(f"Tier: {decision.tier}")
print(f"Cost: ${decision.cost:.6f}")
# Stream responses
async for token in router.stream_chat("Tell me a story"):
print(token, end="", flush=True)
Key Features
- Auto-routing: Picks the right model based on query complexity, budget, and requirements
- Cost savings: 70-95% cheaper than always using premium models
- 47+ providers: Groq, DeepSeek, GPT-4o, Claude, Mistral, and more
- Framework adapters: Drop-in for LangChain, LlamaIndex, Qdrant, Weaviate
- Health monitoring: Check provider status and availability
- Cost analytics: Track spending and savings
Framework Adapters
| Adapter | Use Case | Install |
|---|---|---|
| LangChain | Chain-based AI workflows | pip install a3m-router[langchain] |
| LlamaIndex | RAG and document QA | pip install a3m-router[llamaindex] |
| Qdrant | Vector search + RAG | pip install a3m-router[qdrant] |
| Weaviate | Vector search + RAG | pip install a3m-router[weaviate] |
All adapters:
pip install a3m-router[all]
Routing Tiers
| Tier | Providers | Cost | When Used |
|---|---|---|---|
| free | Ollama, vLLM | $0 | Local inference |
| cheap | Groq, DeepSeek | ~$0.001/1K | Simple Q&A, short code |
| mid | GPT-4o-mini, Claude-haiku | ~$0.01/1K | Standard tasks |
| premium | GPT-4o, Claude-sonnet | ~$0.15/1K | Complex reasoning |
API Reference
A3MRouter
router = A3MRouter(
base_url="http://localhost:8787", # A3M Router server URL
timeout=30.0, # Request timeout
)
| Method | Description |
|---|---|
chat(message) |
Send chat message with auto-routing |
route(query) |
Get routing decision (no execution) |
route_batch(queries) |
Route multiple queries |
stream_chat(message) |
Stream response tokens |
models() |
List all available models |
health() |
Provider health status |
cost_report() |
Cost analytics |
LangChain Example
from a3m import LangChainAdapter
from langchain.schema import HumanMessage
llm = LangChainAdapter(base_url="http://localhost:8787")
response = llm([HumanMessage(content="What is RAG?")])
LlamaIndex Example
from a3m import LlamaIndexAdapter
llm = LlamaIndexAdapter()
response = llm.complete("Explain transformers")
Server Setup
Start the A3M Router server:
# Via npm
npx a3m-router serve
# Via Docker
docker-compose up -d
Server runs on http://localhost:8787 by default.
Links
- GitHub: https://github.com/Das-rebel/a3m-router
- npm Package: https://www.npmjs.com/package/adaptive-memory-multi-model-router
- Documentation: https://das-rebel.github.io/a3m-router
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
a3m_router-2.2.1.tar.gz
(13.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file a3m_router-2.2.1.tar.gz.
File metadata
- Download URL: a3m_router-2.2.1.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7d6eaff1fb34e64bc214dbafb9a5f2edeec4f47f42673be5ee7322b71b8fa4c
|
|
| MD5 |
e85f021d015c983b8134e74f24a60b64
|
|
| BLAKE2b-256 |
f4c04fa0ba86bb71ccebf266bda1a313d01e34dc6eb67247aa0ca5b506d4977b
|
File details
Details for the file a3m_router-2.2.1-py3-none-any.whl.
File metadata
- Download URL: a3m_router-2.2.1-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
438ef4b4f321993fb9e988335fba33f62d72d9c7b72f87041f105238ab63edd7
|
|
| MD5 |
065d4775b63b65476077856d78c90815
|
|
| BLAKE2b-256 |
1d86de0fc2f1f023ff9e3800a448ffde0fcdbc23a218356104f53e1b08644916
|