Skip to main content

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

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.2.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

a3m_router-2.2.2-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file a3m_router-2.2.2.tar.gz.

File metadata

  • Download URL: a3m_router-2.2.2.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for a3m_router-2.2.2.tar.gz
Algorithm Hash digest
SHA256 50ba5151423381f0a9798446553d6edb760b3a4930ae4c7817e02b13d2308085
MD5 899c33e3e4ad433f69bcd1bf66946ff0
BLAKE2b-256 05c35ae4476f39299c17878687c34815fe588079601fdeffce092342d6882d35

See more details on using hashes here.

File details

Details for the file a3m_router-2.2.2-py3-none-any.whl.

File metadata

  • Download URL: a3m_router-2.2.2-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

Hashes for a3m_router-2.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 29b1a2bddd50c4d80bb46b2c71d8ea416a7ae984fd257695cebd393455668ac5
MD5 a987cf488bdce6414a0fd0956da1f4e3
BLAKE2b-256 d1480a0bdf2ff49f01f58cbad9ad28aff483894467720b35c8f4d0f9b44fcaa4

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 Sentry Error logging StatusPage Status page