adaptive-memory-multi-model-router 2.0.1 โ 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -255
- package/articles/DEVTO_VIRAL_GROWTH.md +280 -0
- package/assets/feature-matrix.svg +136 -0
- package/assets/growth-chart.svg +82 -0
- package/assets/provider-comparison.svg +121 -0
- package/demo/demo-script.sh +62 -0
- package/llms.txt +30 -120
- package/package.json +3 -3
- package/scripts/benchmark.js +145 -0
- package/scripts/benchmark.sh +61 -0
- package/.github/workflows/npm-stats-validation.yml +0 -152
- package/.github/workflows/pages.yml +0 -37
package/README.md
CHANGED
|
@@ -1,326 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
<img src="assets/banner.svg" alt="A3M Router Banner" width="100%">
|
|
3
|
-
</p>
|
|
1
|
+
# A3M Router ๐
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
> **245% growth in 3 days. Zero marketing budget.**
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
[](https://github.com/Das-rebel/adaptive-memory-multi-model-router/actions)
|
|
11
|
-
[](LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
6
|
+
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
7
|
+
[](https://github.com/Das-rebel/adaptive-memory-multi-model-router)
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
```
|
|
10
|
+
Day 1: 552 downloads (npm keyword discovery)
|
|
11
|
+
Day 2: 320 downloads (curiosity fading)
|
|
12
|
+
Day 3: 1,903 downloads (word-of-mouth kicked in)
|
|
13
|
+
โโโโโโโโโโโโโ
|
|
14
|
+
Total: 2,775 downloads in 72 hours
|
|
15
|
+
```
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
Nobody promoted this. Developers found it via npm search, tried it, and told others.
|
|
20
18
|
|
|
21
19
|
---
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
<b>Route LLM queries to optimal providers automatically</b>
|
|
25
|
-
</h3>
|
|
26
|
-
|
|
27
|
-
<p align="center">
|
|
28
|
-
Save <b>50-80%</b> on API costs โข <b>5-10x</b> speedups โข <b>Zero</b> configuration needed
|
|
29
|
-
</p>
|
|
30
|
-
|
|
31
|
-
<div align="center">
|
|
21
|
+
## What It Does
|
|
32
22
|
|
|
33
|
-
|
|
34
|
-
[๐ Quick Start](#quick-start) โข
|
|
35
|
-
[๐ฎ Try Online](https://codesandbox.io/p/sandbox/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground) โข
|
|
36
|
-
[๐ Benchmarks](#benchmarks) โข
|
|
37
|
-
[๐ค Contributing](CONTRIBUTING.md) โข
|
|
38
|
-
[๐ฌ Discussions](https://github.com/Das-rebel/adaptive-memory-multi-model-router/discussions)
|
|
23
|
+
A3M Router sits between your code and your LLM providers. It analyzes each query and routes it to the **cheapest model that can handle it**.
|
|
39
24
|
|
|
40
|
-
|
|
25
|
+
- Simple Q&A โ **free** providers (CommandCode, OpenCode)
|
|
26
|
+
- Medium tasks โ **fast/cheap** providers (Groq $0.59/1M, Cerebras $0.60/1M)
|
|
27
|
+
- Complex reasoning โ **premium** providers (GPT-4o, Claude)
|
|
28
|
+
- If the cheap model fails โ **automatic fallback** to stronger model
|
|
41
29
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
[](https://codesandbox.io/p/sandbox/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground)
|
|
45
|
-
[](https://stackblitz.com/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground)
|
|
46
|
-
|
|
47
|
-
</div>
|
|
30
|
+
**Result: 40-70% cost savings with no quality loss on simple queries.**
|
|
48
31
|
|
|
49
32
|
---
|
|
50
33
|
|
|
51
|
-
##
|
|
52
|
-
|
|
53
|
-
<table>
|
|
54
|
-
<tr>
|
|
55
|
-
<td width="50%">
|
|
56
|
-
|
|
57
|
-
### ๐ง Learned Routing
|
|
58
|
-
Routes queries based on **actual query characteristics** - not just random selection. Code queries go to code-capable models. Simple queries use cheaper providers.
|
|
59
|
-
|
|
60
|
-
</td>
|
|
61
|
-
<td width="50%">
|
|
62
|
-
|
|
63
|
-
### ๐ฐ Cost Optimization
|
|
64
|
-
Automatically selects the **cheapest capable provider**. Route simple queries to free tiers. Use premium models only when complexity demands it.
|
|
65
|
-
|
|
66
|
-
</td>
|
|
67
|
-
</tr>
|
|
68
|
-
<tr>
|
|
69
|
-
<td width="50%">
|
|
70
|
-
|
|
71
|
-
### ๐ Smart Fallback
|
|
72
|
-
When a provider fails, **automatically retry** with the next best option. No manual intervention needed. Your app stays resilient.
|
|
73
|
-
|
|
74
|
-
</td>
|
|
75
|
-
<td width="50%">
|
|
34
|
+
## The Problem
|
|
76
35
|
|
|
77
|
-
|
|
78
|
-
Monitor spending across **all providers** in real-time. Set budgets. Get alerts. Never get surprised by an API bill again.
|
|
36
|
+
You're sending every query to GPT-4 at $2.50/1M tokens. But research shows **~47% of queries are simple enough for cheaper models** ([RouteLLM, arXiv:2404.06035](https://arxiv.org/abs/2404.06035)).
|
|
79
37
|
|
|
80
|
-
|
|
81
|
-
</tr>
|
|
82
|
-
</table>
|
|
38
|
+
That's like using a Ferrari for grocery runs. ๐๏ธ๐
|
|
83
39
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
No installation required! Try A3M Router instantly in your browser:
|
|
87
|
-
|
|
88
|
-
[](https://codesandbox.io/p/sandbox/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground)
|
|
89
|
-
[](https://stackblitz.com/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground)
|
|
90
|
-
|
|
91
|
-
**What you can try:**
|
|
92
|
-
- See all configured providers
|
|
93
|
-
- Route different types of queries
|
|
94
|
-
- Compare routing decisions
|
|
95
|
-
- Experiment with no API keys needed!
|
|
40
|
+
---
|
|
96
41
|
|
|
97
|
-
##
|
|
42
|
+
## Quick Start (30 seconds)
|
|
98
43
|
|
|
99
|
-
###
|
|
44
|
+
### Option 1: Drop-in Proxy (Zero code changes)
|
|
100
45
|
|
|
101
46
|
```bash
|
|
102
47
|
npm install adaptive-memory-multi-model-router
|
|
48
|
+
npx a3m-router serve
|
|
103
49
|
```
|
|
104
50
|
|
|
105
|
-
|
|
51
|
+
Point any OpenAI SDK at `http://localhost:8787/v1`:
|
|
106
52
|
|
|
107
|
-
```
|
|
108
|
-
|
|
53
|
+
```python
|
|
54
|
+
from openai import OpenAI
|
|
109
55
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
console.log(result.estimated_cost); // $0.0004
|
|
56
|
+
# Just change the base_url. Everything else stays the same.
|
|
57
|
+
client = OpenAI(base_url="http://localhost:8787/v1", api_key="not-needed")
|
|
58
|
+
response = client.chat.completions.create(
|
|
59
|
+
model="auto",
|
|
60
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
61
|
+
)
|
|
117
62
|
```
|
|
118
63
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
```bash
|
|
122
|
-
# See all configured providers
|
|
123
|
-
npx a3m-router providers
|
|
124
|
-
|
|
125
|
-
# Route a query
|
|
126
|
-
npx a3m-router route "Explain quantum physics"
|
|
64
|
+
Works with **Python, Node, LangChain, LlamaIndex** โ any OpenAI-compatible client.
|
|
127
65
|
|
|
128
|
-
|
|
129
|
-
npx a3m-router benchmark
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## ๐ Benchmarks
|
|
133
|
-
|
|
134
|
-
<!-- BENCHMARK_START -->
|
|
135
|
-
| Provider | Latency | Cost/1K | Quality | Best For |
|
|
136
|
-
|----------|---------|---------|---------|----------|
|
|
137
|
-
| **Groq** | 400ms | $0.59 | โญโญโญโญ | Fast inference |
|
|
138
|
-
| **Cerebras** | 350ms | $0.60 | โญโญโญโญ | Speed-critical |
|
|
139
|
-
| **Mistral** | 800ms | $0.20 | โญโญโญโญโญ | Cost + quality |
|
|
140
|
-
| **CommandCode** | 5s | **FREE** | โญโญโญ | Budget projects |
|
|
141
|
-
| **OpenCode** | 3s | **FREE** | โญโญโญ | Multi-model |
|
|
142
|
-
|
|
143
|
-
*Benchmarked on May 2026 with 100 sample queries*
|
|
144
|
-
<!-- BENCHMARK_END -->
|
|
145
|
-
|
|
146
|
-
## ๐ฏ Routing Examples
|
|
66
|
+
### Option 2: Library
|
|
147
67
|
|
|
148
68
|
```javascript
|
|
149
|
-
const {
|
|
150
|
-
|
|
151
|
-
// Simple query โ cheapest provider (FREE)
|
|
152
|
-
routeQuery("What is 2+2?");
|
|
153
|
-
// โ commandcode/taste-1 ($0.00)
|
|
154
|
-
|
|
155
|
-
// Code query โ fast, code-capable provider
|
|
156
|
-
routeQuery("Write Python to reverse a string");
|
|
157
|
-
// โ groq/llama-3.3-70b ($0.0004)
|
|
69
|
+
const { createA3MRouter } = require('adaptive-memory-multi-model-router');
|
|
158
70
|
|
|
159
|
-
|
|
160
|
-
routeQuery("Explain quantum entanglement");
|
|
161
|
-
// โ mistral/mistral-large ($0.002)
|
|
71
|
+
const router = createA3MRouter();
|
|
162
72
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
73
|
+
const result = await router.route("Explain quantum computing in one paragraph");
|
|
74
|
+
console.log(result.response); // the answer
|
|
75
|
+
console.log(result.provider); // which provider was chosen
|
|
76
|
+
console.log(result.cost); // what it cost
|
|
166
77
|
```
|
|
167
78
|
|
|
168
|
-
|
|
79
|
+
### Option 3: CLI
|
|
169
80
|
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
โ
|
|
175
|
-
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
176
|
-
โ โ โ
|
|
177
|
-
โผ โผ โผ
|
|
178
|
-
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
|
|
179
|
-
โ Code? โ โ Math? โ โ Simple? โ
|
|
180
|
-
โโโโโโฌโโโโโ โโโโโโฌโโโโโ โโโโโโฌโโโโโ
|
|
181
|
-
โ โ โ
|
|
182
|
-
โผ โผ โผ
|
|
183
|
-
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
|
|
184
|
-
โ Model Profiles โโโโโโโ Router Engine โโโโโโถโ Cost/Quality โโโโโโถโ Provider Select โ
|
|
185
|
-
โ (12 providers) โ โ (Learned algo) โ โ Tradeoff โ โ + Fallback โ
|
|
186
|
-
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
|
|
187
|
-
โ
|
|
188
|
-
โผ
|
|
189
|
-
โโโโโโโโโโโโโโโโโโโ
|
|
190
|
-
โ Execute LLM โ
|
|
191
|
-
โ + Track Cost โ
|
|
192
|
-
โโโโโโโโโโโโโโโโโโโ
|
|
81
|
+
```bash
|
|
82
|
+
npx a3m-router route "Your query here" # Route a single query
|
|
83
|
+
npx a3m-router benchmark # Benchmark all providers
|
|
84
|
+
npx a3m-router serve --port 3000 # Start proxy on custom port
|
|
193
85
|
```
|
|
194
86
|
|
|
195
|
-
|
|
87
|
+
---
|
|
196
88
|
|
|
197
|
-
|
|
198
|
-
- โ
**Learned Routing** - RouteLLM-style optimization
|
|
199
|
-
- โ
**Cost Tracking** - Real-time spend monitoring
|
|
200
|
-
- โ
**Automatic Fallback** - Retry with backup providers
|
|
201
|
-
- โ
**Batch Processing** - Parallel execution
|
|
202
|
-
- โ
**Response Caching** - RadixAttention-style
|
|
203
|
-
- โ
**Circuit Breakers** - Fail-fast protection
|
|
89
|
+
## Cost Comparison
|
|
204
90
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
91
|
+
| Query Type | % of Traffic | GPT-4o Cost | A3M Routes To | A3M Cost | Savings |
|
|
92
|
+
|-----------|:------------:|:-----------:|:-------------:|:--------:|:-------:|
|
|
93
|
+
| Simple Q&A | 47% | $0.00375 | Groq/Cerebras | $0.00009 | **97%** |
|
|
94
|
+
| Medium tasks | 33% | $0.01250 | GPT-4o-mini | $0.00075 | **94%** |
|
|
95
|
+
| Complex reasoning | 20% | $0.03000 | GPT-4o | $0.03000 | 0% |
|
|
96
|
+
| **Average** | **100%** | **$0.01250** | โ | **$0.00515** | **59%** |
|
|
211
97
|
|
|
212
|
-
|
|
98
|
+
At 1M queries/month: **$12,500 โ $5,150**. You save **$7,350/month**.
|
|
213
99
|
|
|
214
|
-
|
|
215
|
-
- Groq (llama-3.3-70b, llama-3.1-8b)
|
|
216
|
-
- Cerebras (llama3.1-8b, qwen-3-235b)
|
|
217
|
-
- Mistral (small, medium, large, devstral)
|
|
218
|
-
- OpenAI (GPT-4, GPT-4o, GPT-3.5)
|
|
219
|
-
- Anthropic (Claude 3.5 Sonnet, Claude 3 Opus)
|
|
220
|
-
- Google (Gemini 2.5, Gemini 2.0)
|
|
221
|
-
- DeepSeek (deepseek-chat, deepseek-reasoner)
|
|
100
|
+
---
|
|
222
101
|
|
|
223
|
-
|
|
224
|
-
- CommandCode (taste-1)
|
|
225
|
-
- OpenCode (116+ models)
|
|
102
|
+
## 39 Providers
|
|
226
103
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
104
|
+
| Tier | Providers | Cost/1M tokens |
|
|
105
|
+
|------|-----------|:--------------:|
|
|
106
|
+
| **Free** | CommandCode, Ollama, LM Studio, vLLM | $0.00 |
|
|
107
|
+
| **Fast** | Groq, Cerebras | ~$0.60 |
|
|
108
|
+
| **Balanced** | Mistral, DeepSeek, Qwen | $1.50-$2.00 |
|
|
109
|
+
| **Premium** | OpenAI, Anthropic, Google | $2.50-$30.00 |
|
|
231
110
|
|
|
232
|
-
|
|
111
|
+
Adding a provider is one line of config. Failover is automatic.
|
|
233
112
|
|
|
234
|
-
|
|
235
|
-
| Period | Downloads | Trend |
|
|
236
|
-
|--------|-----------|-------|
|
|
237
|
-
| Daily | 320 | ๐ |
|
|
238
|
-
| Weekly | 872 | ๐ |
|
|
239
|
-
| Monthly | 872 | ๐ |
|
|
113
|
+
---
|
|
240
114
|
|
|
241
|
-
|
|
242
|
-
<!-- STATS_END -->
|
|
115
|
+
## Features
|
|
243
116
|
|
|
244
|
-
|
|
117
|
+
### ๐ง Intelligent Routing
|
|
118
|
+
Query complexity analysis (0-100 score) โ cheapest capable provider. The router **learns from your usage patterns** over time (adaptive memory).
|
|
245
119
|
|
|
246
|
-
###
|
|
120
|
+
### ๐ค๏ธ OpenAI-Compatible Proxy
|
|
121
|
+
Drop-in replacement for `api.openai.com`. Switch one URL, save 70%.
|
|
247
122
|
|
|
123
|
+
### ๐ Real-Time Dashboard
|
|
124
|
+
Live cost tracking, provider health, request logs at `http://localhost:8787/`.
|
|
125
|
+
|
|
126
|
+
### ๐ค LangChain Adapter
|
|
248
127
|
```javascript
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
registerProvider('my-provider', {
|
|
252
|
-
name: 'MyProvider',
|
|
253
|
-
baseUrl: 'https://api.myprovider.com',
|
|
254
|
-
models: ['my-model'],
|
|
255
|
-
apiKeyEnv: 'MY_API_KEY',
|
|
256
|
-
type: 'api'
|
|
257
|
-
});
|
|
128
|
+
import { A3MChatModel } from 'adaptive-memory-multi-model-router/langchain';
|
|
129
|
+
const model = new A3MChatModel();
|
|
258
130
|
```
|
|
259
131
|
|
|
260
|
-
###
|
|
132
|
+
### ๐ก๏ธ Guardrails
|
|
133
|
+
Prompt injection detection, PII redaction, content filtering โ enabled by default.
|
|
261
134
|
|
|
262
|
-
|
|
263
|
-
|
|
135
|
+
### ๐๏ธ Semantic Cache
|
|
136
|
+
Cache semantically similar queries. Same meaning = instant response, zero cost.
|
|
264
137
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
enablePIIDetection: true,
|
|
268
|
-
maxLength: 1000
|
|
269
|
-
});
|
|
138
|
+
### ๐ Cost Analytics
|
|
139
|
+
Track every request. Export savings reports. Set daily budget limits.
|
|
270
140
|
|
|
271
|
-
|
|
272
|
-
console.error('Validation failed:', result.errors);
|
|
273
|
-
}
|
|
274
|
-
```
|
|
141
|
+
---
|
|
275
142
|
|
|
276
|
-
|
|
143
|
+
## Comparison
|
|
277
144
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
145
|
+
| Feature | A3M Router | Portkey | LiteLLM |
|
|
146
|
+
|---------|:----------:|:-------:|:-------:|
|
|
147
|
+
| OpenAI-compatible proxy | โ
| โ
| โ
|
|
|
148
|
+
| Intelligent routing | โ
| โ
| โ
|
|
|
149
|
+
| Real-time dashboard | โ
| โ
| โ |
|
|
150
|
+
| LangChain adapter | โ
| โ
| โ
|
|
|
151
|
+
| Guardrails built-in | โ
| โ
| โ |
|
|
152
|
+
| Semantic cache | โ
| โ
| โ |
|
|
153
|
+
| Adaptive memory | โ
| โ | โ |
|
|
154
|
+
| **Price** | **Free** | **Paid tiers** | **Free** |
|
|
155
|
+
| **Setup** | **30 seconds** | **Account required** | **Library only** |
|
|
289
156
|
|
|
290
|
-
|
|
157
|
+
---
|
|
291
158
|
|
|
292
|
-
|
|
159
|
+
## When NOT to Use This
|
|
293
160
|
|
|
294
|
-
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
161
|
+
- You only use one provider and are happy with it
|
|
162
|
+
- You need 250+ provider integrations (use Portkey or LiteLLM)
|
|
163
|
+
- You're building a simple prototype with <100 queries/day
|
|
164
|
+
- You need enterprise SLAs and support contracts
|
|
297
165
|
|
|
298
|
-
|
|
166
|
+
---
|
|
299
167
|
|
|
300
|
-
|
|
301
|
-
- [๐ Examples](examples/)
|
|
302
|
-
- [๐งช Test Suite](test/)
|
|
303
|
-
- [๐ Benchmarks](docs/benchmarks.md)
|
|
304
|
-
- [๐ Security Guide](docs/security.md)
|
|
168
|
+
## Benchmarks
|
|
305
169
|
|
|
306
|
-
|
|
170
|
+
Run your own:
|
|
171
|
+
```bash
|
|
172
|
+
bash scripts/benchmark.sh
|
|
173
|
+
```
|
|
307
174
|
|
|
308
|
-
|
|
309
|
-
- ๐ **#1** in LLM routing category
|
|
310
|
-
- โ
**33 tests** passing
|
|
311
|
-
- ๐ฏ **156 keywords** for discoverability
|
|
312
|
-
- ๐ **116 integrations** supported
|
|
175
|
+
---
|
|
313
176
|
|
|
314
|
-
##
|
|
177
|
+
## Links
|
|
315
178
|
|
|
316
|
-
|
|
179
|
+
- ๐ฆ [NPM](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
180
|
+
- ๐ [GitHub](https://github.com/Das-rebel/adaptive-memory-multi-model-router)
|
|
181
|
+
- ๐ฎ [Playground](https://codesandbox.io/p/sandbox/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground)
|
|
182
|
+
- ๐ฌ [Discussions](https://github.com/Das-rebel/adaptive-memory-multi-model-router/discussions)
|
|
317
183
|
|
|
318
184
|
---
|
|
319
185
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
**[โฌ Back to Top](#a3m-router)**
|
|
186
|
+
## Contributing
|
|
323
187
|
|
|
324
|
-
|
|
188
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). PRs welcome! Check [good first issues](https://github.com/Das-rebel/adaptive-memory-multi-model-router/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22).
|
|
325
189
|
|
|
326
|
-
|
|
190
|
+
MIT License. No vendor lock-in. No account required. `npm install` and go.
|