adaptive-memory-multi-model-router 2.13.18 → 2.13.20
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/.dockerignore +82 -0
- package/.env.example +303 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +83 -12
- package/.github/ISSUE_TEMPLATE/config.yml +12 -6
- package/.github/ISSUE_TEMPLATE/feature_request.md +61 -10
- package/.github/PULL_REQUEST_TEMPLATE.md +53 -26
- package/.github/dependabot.yml +9 -0
- package/.github/workflows/codeql.yml +38 -0
- package/.github/workflows/npm-publish.yml +20 -0
- package/.github/workflows/stale.yml +56 -0
- package/ARCHITECTURE.md +346 -0
- package/AUDIT_REPORT.md +28 -0
- package/CHANGELOG.md +386 -22
- package/CONTRIBUTORS.md +20 -0
- package/Dockerfile +53 -0
- package/Dockerfile.proxy +33 -0
- package/PR_STATUS_REPORT.md +148 -0
- package/README.md +22 -0
- package/RUNKIT.md +83 -0
- package/_schema.html +61 -15
- package/articles/AI_AGENT_LLM_ROUTING.md +150 -0
- package/articles/FROM_ZERO_TO_10K.md +107 -0
- package/articles/LLM_BENCHMARK_DEEP_DIVE.md +153 -0
- package/articles/TWEETS_10K_DOWNLOADS.md +47 -0
- package/articles/TWEETS_BENCHMARK_FIRST.md +46 -0
- package/articles/TWEETS_MCP_PLAY.md +51 -0
- package/articles/TWEETS_SEQUENTIAL_BROKEN.md +49 -0
- package/articles/TWEETS_WHY_BUILD.md +54 -0
- package/benchmark-results.json +26 -45
- package/cli/a3m +840 -0
- package/demo/package.json +13 -0
- package/demo/public/index.html +762 -0
- package/demo/server.js +405 -0
- package/dist/cli.js +4 -0
- package/docker-compose.yml +74 -0
- package/docs/.nojekyll +0 -0
- package/docs/BENCHMARK.md +96 -22
- package/docs/_config.yml +49 -0
- package/docs/api.html +513 -0
- package/docs/benchmark.html +387 -0
- package/docs/cli-cheatsheet.md +339 -0
- package/docs/comparison.md +108 -0
- package/docs/curl-examples.md +247 -0
- package/docs/index.html +390 -99
- package/docs/openapi.yaml +1318 -0
- package/docs/quick-start.html +366 -0
- package/docs/robots.txt +1 -1
- package/docs/sitemap.xml +23 -5
- package/docs/styles.css +682 -0
- package/examples/README.md +61 -0
- package/examples/a3m-sdk.js +124 -0
- package/examples/basic-route.js +54 -0
- package/examples/chat-loop.js +202 -0
- package/examples/classify-then-route.js +102 -0
- package/examples/cost-compare.js +120 -0
- package/examples/ensemble.js +160 -0
- package/integrations/langchain/README.md +216 -0
- package/integrations/langchain/a3m_langchain.ts +1360 -0
- package/integrations/langchain/example.ts +287 -0
- package/integrations/vercel-ai-sdk/README.md +49 -0
- package/integrations/vercel-ai-sdk/a3m_provider.ts +78 -0
- package/integrations/vercel-ai-sdk/example.ts +25 -0
- package/llms-full.txt +43 -0
- package/llms.txt +9 -0
- package/mcp-server/README.md +188 -0
- package/mcp-server/package.json +29 -0
- package/mcp-server/src/index.ts +744 -0
- package/mcp-server/tsconfig.json +19 -0
- package/package.json +3 -3
- package/proxy/README.md +227 -0
- package/proxy/package-lock.json +831 -0
- package/proxy/package.json +17 -0
- package/proxy/rate-limit.js +145 -0
- package/proxy/rate-limit.test.js +311 -0
- package/proxy/server.js +970 -0
- package/scripts/banner.js +29 -0
- package/scripts/compare-providers.sh +230 -0
- package/scripts/cross_post.py +443 -0
- package/scripts/publish_fcc.py +106 -0
- package/scripts/push-to-gitee.sh +52 -0
- package/src/tui/dashboard.ts +13 -0
- package/tests/__mocks__/tokenUtils.ts +22 -0
- package/tests/memory/episodicMemory.test.ts +227 -0
- package/tests/package-lock.json +1628 -0
- package/tests/package.json +18 -0
- package/tests/routing/ensembleVoting.test.ts +236 -0
- package/tests/routing/providerRetry.test.ts +360 -0
- package/tests/routing/queryTypePresets.test.ts +206 -0
- package/tests/tsconfig.json +21 -0
- package/tests/vitest.config.ts +18 -0
- package/.env +0 -2
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# A3M Router CLI Cheat Sheet
|
|
2
|
+
|
|
3
|
+
> The fastest-growing open-source LLM router on npm. Parallel multi-LLM execution with confidence-weighted voting.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# TypeScript / Node (primary)
|
|
11
|
+
npm install -g adaptive-memory-multi-model-router
|
|
12
|
+
# or
|
|
13
|
+
npx a3m-router <command>
|
|
14
|
+
|
|
15
|
+
# Python
|
|
16
|
+
pip install a3m-router
|
|
17
|
+
|
|
18
|
+
# Verify installation
|
|
19
|
+
a3m-router --version
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Quick Reference
|
|
25
|
+
|
|
26
|
+
| Command | Description |
|
|
27
|
+
|---------|-------------|
|
|
28
|
+
| `a3m-router serve` | Start OpenAI-compatible proxy server |
|
|
29
|
+
| `a3m-router route <query>` | Route a single query to best provider |
|
|
30
|
+
| `a3m-router compare <query>` | Compare providers side by side |
|
|
31
|
+
| `a3m-router providers` | List configured providers |
|
|
32
|
+
| `a3m-router test` | Test all providers for connectivity |
|
|
33
|
+
| `a3m-router setup` | Interactive setup wizard |
|
|
34
|
+
| `a3m-router recommend <task>` | Get model recommendation for a task |
|
|
35
|
+
| `a3m-router cost <text>` | Estimate token cost |
|
|
36
|
+
| `a3m-router token <text>` | Count tokens |
|
|
37
|
+
| `a3m-router models` | List all known models |
|
|
38
|
+
| `a3m-router status` | Show router status and health |
|
|
39
|
+
| `a3m-router benchmark` | Benchmark all providers |
|
|
40
|
+
| `a3m-router batch <q1> <q2>...` | Route multiple queries |
|
|
41
|
+
| `a3m-router memory add` | Add to memory |
|
|
42
|
+
| `a3m-router memory search <q>` | Search memory |
|
|
43
|
+
| `a3m-router memory stats` | Show memory stats |
|
|
44
|
+
| `a3m-router tui` | Launch terminal UI overlay |
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Basic Usage
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Route a query (auto-detects best provider based on complexity)
|
|
52
|
+
a3m-router route "What is quantum computing?"
|
|
53
|
+
|
|
54
|
+
# Force routing through a specific provider
|
|
55
|
+
# (via environment variable or config file)
|
|
56
|
+
|
|
57
|
+
# Compare responses from different providers
|
|
58
|
+
a3m-router compare "Write a poem about AI"
|
|
59
|
+
|
|
60
|
+
# Route multiple queries at once
|
|
61
|
+
a3m-router batch "Explain gravity" "Write hello world in Rust" "What is ML?"
|
|
62
|
+
|
|
63
|
+
# Get a model recommendation for a task
|
|
64
|
+
a3m-router recommend "code generation"
|
|
65
|
+
a3m-router recommend "creative writing"
|
|
66
|
+
a3m-router recommend "data extraction"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Proxy Server
|
|
72
|
+
|
|
73
|
+
Start an OpenAI-compatible proxy server:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Default port 8787
|
|
77
|
+
a3m-router serve
|
|
78
|
+
|
|
79
|
+
# Custom port
|
|
80
|
+
a3m-router serve --port 3000
|
|
81
|
+
|
|
82
|
+
# With host binding
|
|
83
|
+
a3m-router serve --host 0.0.0.0 --port 8787
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then use any OpenAI SDK pointing to `http://localhost:8787/v1`:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import openai
|
|
90
|
+
client = openai.OpenAI(
|
|
91
|
+
api_key="sk-unused",
|
|
92
|
+
base_url="http://localhost:8787/v1"
|
|
93
|
+
)
|
|
94
|
+
response = client.chat.completions.create(
|
|
95
|
+
model="auto", # A3M auto-routes to best provider
|
|
96
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import OpenAI from 'openai';
|
|
102
|
+
const client = new OpenAI({
|
|
103
|
+
apiKey: 'sk-unused',
|
|
104
|
+
baseURL: 'http://localhost:8787/v1',
|
|
105
|
+
});
|
|
106
|
+
const response = await client.chat.completions.create({
|
|
107
|
+
model: 'auto',
|
|
108
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Programmatic Usage
|
|
115
|
+
|
|
116
|
+
### TypeScript / JavaScript
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// Main router
|
|
120
|
+
import { route, ensemble, createA3MRouter } from 'adaptive-memory-multi-model-router';
|
|
121
|
+
|
|
122
|
+
// Route to best provider
|
|
123
|
+
const result = await route({
|
|
124
|
+
query: "Explain quantum computing in simple terms",
|
|
125
|
+
strategy: "auto" // auto | cheapest | fastest | best
|
|
126
|
+
});
|
|
127
|
+
console.log(result.primary_model, result.content);
|
|
128
|
+
|
|
129
|
+
// Ensemble across multiple providers (P0 — core differentiator)
|
|
130
|
+
const ensembleResult = await ensemble({
|
|
131
|
+
query: "Write a poem about artificial intelligence",
|
|
132
|
+
providers: ["groq", "openai", "anthropic"], // optional: defaults to auto-select
|
|
133
|
+
});
|
|
134
|
+
console.log(ensembleResult.winner, ensembleResult.scores);
|
|
135
|
+
|
|
136
|
+
// Cost estimation
|
|
137
|
+
import { estimateCost, countTokens } from 'adaptive-memory-multi-model-router/cost';
|
|
138
|
+
const tokens = countTokens("Hello world");
|
|
139
|
+
const cost = estimateCost("gpt-4o", tokens);
|
|
140
|
+
|
|
141
|
+
// Memory operations
|
|
142
|
+
import { MemoryTree } from 'adaptive-memory-multi-model-router/memory';
|
|
143
|
+
const memory = new MemoryTree();
|
|
144
|
+
await memory.remember("user_preference", "likes short responses");
|
|
145
|
+
|
|
146
|
+
// Query with SDK (clean high-level API)
|
|
147
|
+
import { A3M } from 'adaptive-memory-multi-model-router/sdk';
|
|
148
|
+
const a3m = new A3M();
|
|
149
|
+
const response = await a3m.query("What is the capital of France?");
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Python
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from a3m_router import A3M
|
|
156
|
+
|
|
157
|
+
router = A3M()
|
|
158
|
+
result = router.route("Explain quantum computing")
|
|
159
|
+
print(result.model, result.content)
|
|
160
|
+
|
|
161
|
+
# Ensemble mode
|
|
162
|
+
results = router.ensemble("Write a poem", providers=["groq", "openai"])
|
|
163
|
+
print(results.winner, results.scores)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Environment Variables
|
|
169
|
+
|
|
170
|
+
### Provider API Keys (at least one required)
|
|
171
|
+
|
|
172
|
+
| Variable | Required | Provider | Models |
|
|
173
|
+
|----------|:--------:|----------|--------|
|
|
174
|
+
| `OPENAI_API_KEY` | Recommended | OpenAI | GPT-4o, GPT-4o-mini, o1, o3 |
|
|
175
|
+
| `ANTHROPIC_API_KEY` | Recommended | Anthropic | Claude Sonnet 4, Opus, Haiku |
|
|
176
|
+
| `GOOGLE_API_KEY` | Recommended | Google / Gemini | Gemini 2.5 Flash/Pro, Gemma |
|
|
177
|
+
| `XAI_API_KEY` | Optional | xAI | Grok-3, Grok-2 |
|
|
178
|
+
| `GROQ_API_KEY` | Recommended | Groq | Llama, Mixtral (fast) |
|
|
179
|
+
| `CEREBRAS_API_KEY` | Optional | Cerebras | Wafer-scale inference |
|
|
180
|
+
| `DEEPINFRA_API_KEY` | Optional | DeepInfra | Serverless open models |
|
|
181
|
+
| `TOGETHER_API_KEY` | Optional | Together AI | Hosted open-source models |
|
|
182
|
+
| `FIREWORKS_API_KEY` | Optional | Fireworks AI | Fast open models |
|
|
183
|
+
| `DEEPSEEK_API_KEY` | Recommended | DeepSeek | DeepSeek-V3, DeepSeek-R1 |
|
|
184
|
+
| `MISTRAL_API_KEY` | Optional | Mistral AI | Mistral Large, Codestral |
|
|
185
|
+
| `PERPLEXITY_API_KEY` | Optional | Perplexity | Sonar (online search) |
|
|
186
|
+
| `COHERE_API_KEY` | Optional | Cohere | Command R+, embeddings |
|
|
187
|
+
| `REPLICATE_API_KEY` | Optional | Replicate | Open-source models |
|
|
188
|
+
| `HUGGINGFACE_API_KEY` | Optional | HuggingFace | Inference API |
|
|
189
|
+
| `NVIDIA_API_KEY` | Optional | NVIDIA | NVIDIA NIM |
|
|
190
|
+
| `OPENROUTER_API_KEY` | Optional | OpenRouter | 400+ models via one key |
|
|
191
|
+
| `AZURE_OPENAI_API_KEY` | Optional | Azure OpenAI | Enterprise OpenAI |
|
|
192
|
+
| `ZHIPU_API_KEY` | Optional | Zhipu AI | GLM series |
|
|
193
|
+
| `DASHSCOPE_API_KEY` | Optional | Alibaba (Qwen) | Qwen models |
|
|
194
|
+
| `MOONSHOT_API_KEY` | Optional | Moonshot AI | Kimi models |
|
|
195
|
+
| `MINIMAX_API_KEY` | Optional | MiniMax | MiniMax models |
|
|
196
|
+
| `STEPFUN_API_KEY` | Optional | StepFun | Step models |
|
|
197
|
+
| `NOVITA_API_KEY` | Optional | Novita AI | Low-cost inference |
|
|
198
|
+
| `SAMBANOVA_API_KEY` | Optional | SambaNova | Fast open models |
|
|
199
|
+
| `ANYSCALE_API_KEY` | Optional | Anyscale | Open model endpoints |
|
|
200
|
+
| `WRITER_API_KEY` | Optional | Writer | Palmyra models |
|
|
201
|
+
| `OCTOAI_API_KEY` | Optional | OctoAI | Fast custom models |
|
|
202
|
+
| `AI21_API_KEY` | Optional | AI21 Labs | Jamba 1.5 |
|
|
203
|
+
| `LAMINAR_API_KEY` | Optional | Laminar | Laminar models |
|
|
204
|
+
| `JINA_API_KEY` | Optional | Jina AI | Embeddings, rerank |
|
|
205
|
+
| `VOYAGE_API_KEY` | Optional | Voyage AI | Embeddings |
|
|
206
|
+
|
|
207
|
+
### Configuration
|
|
208
|
+
|
|
209
|
+
| Variable | Default | Description |
|
|
210
|
+
|----------|---------|-------------|
|
|
211
|
+
| `A3M_LOG_LEVEL` | `info` | Logging level (debug, info, warn, error) |
|
|
212
|
+
| `A3M_CONFIG_DIR` | `~/.config/a3m-router` | Config directory |
|
|
213
|
+
| `A3M_CACHE_SIZE` | `1000` | Semantic cache entry limit |
|
|
214
|
+
| `A3M_BUDGET_MONTHLY` | unset | Monthly budget cap (USD) |
|
|
215
|
+
| `A3M_DEFAULT_STRATEGY` | `auto` | Routing strategy (auto, cheapest, fastest, best) |
|
|
216
|
+
| `A3M_PROXY_PORT` | `8787` | Proxy server port |
|
|
217
|
+
| `A3M_PROXY_ENABLED` | `true` | Enable proxy server |
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Terminal UI (TUI)
|
|
222
|
+
|
|
223
|
+
Launch the interactive dashboard:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# Via npm binary
|
|
227
|
+
a3m-tui
|
|
228
|
+
|
|
229
|
+
# Or via main package
|
|
230
|
+
a3m-router tui
|
|
231
|
+
|
|
232
|
+
# Or directly
|
|
233
|
+
node dist/tui/dashboard.js
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
TUI commands (type at prompt):
|
|
237
|
+
|
|
238
|
+
| Command | Description |
|
|
239
|
+
|---------|-------------|
|
|
240
|
+
| `/route <query>` | Route a query |
|
|
241
|
+
| `/cost <text>` | Estimate cost |
|
|
242
|
+
| `/health` | Check all providers |
|
|
243
|
+
| `/models` | List all models |
|
|
244
|
+
| `/model <provider>` | Show models for a provider |
|
|
245
|
+
| `/providers` | List configured providers |
|
|
246
|
+
| `/exit` or `Ctrl+C` | Exit TUI |
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Example Workflows
|
|
251
|
+
|
|
252
|
+
### Quick Health Check
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
# Test all configured providers
|
|
256
|
+
a3m-router test
|
|
257
|
+
|
|
258
|
+
# Show status
|
|
259
|
+
a3m-router status
|
|
260
|
+
|
|
261
|
+
# List all available models
|
|
262
|
+
a3m-router models
|
|
263
|
+
|
|
264
|
+
# List configured providers
|
|
265
|
+
a3m-router providers
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Cost Optimization
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Estimate cost for a prompt
|
|
272
|
+
a3m-router cost "Write a 500-word blog post about AI"
|
|
273
|
+
|
|
274
|
+
# Count tokens
|
|
275
|
+
a3m-router token "Hello, world! This is a test."
|
|
276
|
+
|
|
277
|
+
# Benchmark provider speeds
|
|
278
|
+
a3m-router benchmark
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Batch Processing
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
# Route multiple queries in batch
|
|
285
|
+
a3m-router batch \
|
|
286
|
+
"What is the speed of light?" \
|
|
287
|
+
"Write a haiku about coding" \
|
|
288
|
+
"Explain DNS in 3 sentences"
|
|
289
|
+
|
|
290
|
+
# Compare providers on the same query
|
|
291
|
+
a3m-router compare "Explain the transformer architecture"
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Setup Wizard
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
# Interactive setup — auto-detects API keys from environment
|
|
298
|
+
a3m-router setup
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Docker
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
# Pull and run
|
|
307
|
+
docker run -p 8787:8787 \
|
|
308
|
+
-e OPENAI_API_KEY=sk-... \
|
|
309
|
+
-e GROQ_API_KEY=gsk_... \
|
|
310
|
+
ghcr.io/das-rebel/a3m-router:latest
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Useful Aliases
|
|
316
|
+
|
|
317
|
+
Add to `~/.zshrc` or `~/.bashrc`:
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
alias a3m='a3m-router'
|
|
321
|
+
alias a3m-route='a3m-router route'
|
|
322
|
+
alias a3m-compare='a3m-router compare'
|
|
323
|
+
alias a3m-serve='a3m-router serve'
|
|
324
|
+
alias a3m-health='a3m-router test'
|
|
325
|
+
alias a3m-cost='a3m-router cost'
|
|
326
|
+
alias a3m-providers='a3m-router providers'
|
|
327
|
+
alias a3m-status='a3m-router status'
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Further Reading
|
|
333
|
+
|
|
334
|
+
- [Quick Start Guide](./QUICK_START.md)
|
|
335
|
+
- [Configuration Guide](./CONFIGURATION.md)
|
|
336
|
+
- [API Reference](./API.md)
|
|
337
|
+
- [Benchmark Results](./BENCHMARK.md)
|
|
338
|
+
- [GitHub: Das-rebel/a3m-router](https://github.com/Das-rebel/a3m-router)
|
|
339
|
+
- [npm: adaptive-memory-multi-model-router](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# A3M Router — Competitor Comparison
|
|
2
|
+
|
|
3
|
+
> Last updated: 2026-05-28
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
A3M Router is the **only open-source LLM gateway** that does **parallel multi-LLM execution with confidence-weighted result merging**. All competitors do sequential fallback (try A -> fail -> try B -> fail -> try C). This is the core differentiator.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Feature Comparison Table
|
|
12
|
+
|
|
13
|
+
| Feature | A3M Router | LiteLLM | OpenRouter | one-api | Portkey | Helicone |
|
|
14
|
+
|---------|:----------:|:-------:|:----------:|:-------:|:-------:|:--------:|
|
|
15
|
+
| **GitHub Stars** | ~2.2K | 48.5K | N/A (closed) | 34.3K | 11.9K | 5.7K |
|
|
16
|
+
| **Pricing Model** | Free (MIT) | Free + Enterprise | Pay-per-token | Free (MIT) | Free + Enterprise | Free tier + Paid |
|
|
17
|
+
| **Parallel Execution** | **YES** (ensemble) | NO (sequential) | NO (fallback) | NO (load bal) | NO (sequential) | NO (fallback) |
|
|
18
|
+
| **Confidence Scoring** | **YES** (voting) | NO | NO | NO | NO | NO |
|
|
19
|
+
| **Result Merging** | **YES** (weighted) | NO | NO | NO | NO | NO |
|
|
20
|
+
| **Independent Benchmarks** | **YES** (99.5%) | YES (8ms P95) | NO | NO | NO | NO |
|
|
21
|
+
| **Open Source** | YES (MIT) | YES (MIT) | NO | YES (MIT) | YES (MIT) | YES (MIT) |
|
|
22
|
+
| **Providers Supported** | 47+ | 100+ | 60+ | 25+ | 250+ | 100+ |
|
|
23
|
+
| **Streaming Support** | YES | YES | YES | YES | YES | YES |
|
|
24
|
+
| **TypeScript SDK** | YES | YES | YES (OpenAI) | NO | YES | YES |
|
|
25
|
+
| **Python SDK** | YES | YES | YES (OpenAI) | NO | YES | YES |
|
|
26
|
+
| **Self-Hostable** | YES (npm) | YES (pip/Docker) | NO (SaaS) | YES (Docker) | YES (npx/Docker) | YES (Docker) |
|
|
27
|
+
| **Semantic Cache** | YES (30%+ hit) | NO | NO | NO | NO | NO |
|
|
28
|
+
| **Budget Enforcement** | YES | YES | YES | YES | YES | YES |
|
|
29
|
+
| **Cost Tracking** | YES | YES | YES | YES | YES | YES |
|
|
30
|
+
| **Guardrails** | YES (17 types) | YES | NO | NO | YES | NO |
|
|
31
|
+
| **Circuit Breaker** | YES (3-fail) | YES | YES | YES | YES | NO |
|
|
32
|
+
| **Load Balancing** | YES | YES | YES | YES | YES | YES |
|
|
33
|
+
| **Admin Dashboard** | YES (TUI) | YES (Web) | YES (Web) | YES (Web) | YES (Web) | YES (Web) |
|
|
34
|
+
| **Multi-Modal** | YES | YES | YES | NO | YES | YES |
|
|
35
|
+
| **Free Models** | YES (taste-1) | NO | YES (25+) | NO | NO | NO |
|
|
36
|
+
| **CLI Tool** | YES (a3m) | YES (litellm) | NO | NO | YES (npx) | NO |
|
|
37
|
+
| **Package Size** | 19.5 KB | ~5 MB | N/A | ~15 MB | 122 KB | ~50 MB |
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Detailed Competitor Profiles
|
|
42
|
+
|
|
43
|
+
### LiteLLM (BerriAI) — 48.5K stars
|
|
44
|
+
- **The incumbent.** Most mature open-source AI gateway. Python-first, used by Stripe, Netflix, Google ADK.
|
|
45
|
+
- **Strengths:** 100+ providers, enterprise-grade (virtual keys, spend tracking, guardrails), 8ms P95 latency, Python SDK is excellent.
|
|
46
|
+
- **Weaknesses:** Sequential fallback only, no parallel execution, no confidence scoring, no semantic cache. TypeScript SDK is secondary.
|
|
47
|
+
- **Model:** Open Source (MIT) + Hosted Enterprise. Self-hostable via pip/Docker.
|
|
48
|
+
|
|
49
|
+
### OpenRouter — Closed Source
|
|
50
|
+
- **The aggregator.** Largest collection of models (400+) with pay-per-token billing. No API subscriptions needed.
|
|
51
|
+
- **Strengths:** 60+ providers, 25+ free models, model fallbacks, rankings/leaderboards, simple OpenAI-compatible API.
|
|
52
|
+
- **Weaknesses:** Completely closed source (not self-hostable), no parallel execution, no confidence scoring, vendor lock-in.
|
|
53
|
+
- **Model:** SaaS-only. Pay-per-token.
|
|
54
|
+
|
|
55
|
+
### one-api (songquanpeng) — 34.3K stars
|
|
56
|
+
- **The Chinese standard.** Dominant in China for API key management and redistribution. Single binary, Docker-ready.
|
|
57
|
+
- **Strengths:** Excellent Chinese provider support (Baichuan, Zhipu, Minimax, Stepfun, DeepSeek, etc.), user management, token quotas, load balancing, English UI.
|
|
58
|
+
- **Weaknesses:** Limited non-Chinese provider support, Go backend (no npm/Python SDK beyond OpenAI API), no parallel execution.
|
|
59
|
+
- **Model:** Open Source (MIT). Self-hostable via Docker or single binary.
|
|
60
|
+
|
|
61
|
+
### Portkey AI Gateway — 11.9K stars
|
|
62
|
+
- **The enterprise gateway.** Focus on guardrails, observability, and reliability. 10B+ tokens processed daily.
|
|
63
|
+
- **Strengths:** 250+ providers, 50+ guardrails, automatic retries and fallbacks, conditional routing, multi-modal, MCP Gateway.
|
|
64
|
+
- **Weaknesses:** Sequential fallback only, no parallel execution, confidence scoring, or semantic cache. <1ms latency on gateway itself though.
|
|
65
|
+
- **Model:** Open Source (MIT) + Enterprise Cloud. Self-hostable via npx, Docker, Cloudflare Workers.
|
|
66
|
+
|
|
67
|
+
### Helicone — 5.7K stars
|
|
68
|
+
- **The observability play.** Primarily an LLM observability platform that also offers AI gateway features. YC W23.
|
|
69
|
+
- **Strengths:** Excellent observability (traces, sessions, analytics), SOC 2/GDPR, 100+ providers, prompt management, fine-tuning integrations.
|
|
70
|
+
- **Weaknesses:** Observability-first (not a pure router), no parallel execution, no confidence scoring, no semantic cache. Free tier limited to 10K requests.
|
|
71
|
+
- **Model:** Open Source + Cloud (Hobby free / Pro $79/mo / Enterprise custom). Self-hostable via Docker or Helm.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Why This Matters
|
|
76
|
+
|
|
77
|
+
### Sequential Fallback (everyone else)
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
Query -> Try GPT-4o (fails) -> Try Claude (fails) -> Try Gemini -> Response
|
|
81
|
+
^^^^^^^^ ^^^^^^^ ^^^^^^^^
|
|
82
|
+
Wasted time Wasted time Only one opinion
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Parallel Ensemble (A3M Router only)
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
Query -> Run GPT-4o + Claude + Gemini simultaneously -> Score -> Pick best
|
|
89
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
90
|
+
All contribute. One winner. No wasted time.
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Real impact:**
|
|
94
|
+
- **+26%** answer quality over single-best provider
|
|
95
|
+
- **-57%** hallucination rate (1.8% vs 4.2%)
|
|
96
|
+
- **+19pp** multi-step reasoning accuracy (91% vs 72%)
|
|
97
|
+
- **62%** cost savings vs all-premium routing
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## References
|
|
102
|
+
|
|
103
|
+
- LiteLLM: https://github.com/BerriAI/litellm
|
|
104
|
+
- OpenRouter: https://openrouter.ai
|
|
105
|
+
- one-api: https://github.com/songquanpeng/one-api
|
|
106
|
+
- Portkey: https://github.com/Portkey-AI/gateway
|
|
107
|
+
- Helicone: https://github.com/Helicone/helicone
|
|
108
|
+
- A3M Router: https://github.com/Das-rebel/a3m-router
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Try A3M Router With One Curl Command
|
|
2
|
+
|
|
3
|
+
> No install. No signup. Just curl.
|
|
4
|
+
|
|
5
|
+
Jump to: [Free Providers](#free-providers) | [A3M Proxy](#a3m-proxy-localhost8787) | [Comparison](#quick-provider-comparison) | [NVIDIA NIM Catalog](#nvidia-nim-catalog) | [Diagnostics](#diagnostics--debugging)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Free Providers
|
|
10
|
+
|
|
11
|
+
Try LLMs right now with a free API key. No credit card required.
|
|
12
|
+
|
|
13
|
+
### Groq (fastest inference, 30 req/min free)
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
curl -s https://api.groq.com/openai/v1/chat/completions \
|
|
17
|
+
-H "Authorization: Bearer $GROQ_API_KEY" \
|
|
18
|
+
-H "Content-Type: application/json" \
|
|
19
|
+
-d '{
|
|
20
|
+
"model": "llama-3.3-70b-versatile",
|
|
21
|
+
"messages": [{"role": "user", "content": "Say hello in exactly 3 words."}]
|
|
22
|
+
}' | jq -r '.choices[0].message.content'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Other Groq models:** `llama-3.1-8b-instant`, `mixtral-8x7b-32768`, `gemma2-9b-it`
|
|
26
|
+
|
|
27
|
+
### NVIDIA NIM (free inference API)
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
curl -s https://integrate.api.nvidia.com/v1/chat/completions \
|
|
31
|
+
-H "Authorization: Bearer $NV_API_KEY" \
|
|
32
|
+
-H "Content-Type: application/json" \
|
|
33
|
+
-d '{
|
|
34
|
+
"model": "meta/llama-3.3-70b-instruct",
|
|
35
|
+
"messages": [{"role": "user", "content": "Say hello in exactly 3 words."}]
|
|
36
|
+
}' | jq -r '.choices[0].message.content'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Other NIM models:** `mistralai/mistral-7b-instruct-v0.3`, `google/gemma-2-27b-it`, `nvidia/llama-3.1-nemotron-70b-instruct`
|
|
40
|
+
|
|
41
|
+
> **Get a free NVIDIA API key:** https://build.nvidia.com/
|
|
42
|
+
|
|
43
|
+
### Cerebras (free, ultra-low latency)
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
curl -s https://api.cerebras.ai/v1/chat/completions \
|
|
47
|
+
-H "Authorization: Bearer $CEREBRAS_API_KEY" \
|
|
48
|
+
-H "Content-Type: application/json" \
|
|
49
|
+
-d '{
|
|
50
|
+
"model": "llama-3.3-70b",
|
|
51
|
+
"messages": [{"role": "user", "content": "Say hello in exactly 3 words."}]
|
|
52
|
+
}' | jq -r '.choices[0].message.content'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### HuggingFace Inference API (free tier)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
curl -s https://api-inference.huggingface.co/models/meta-llama/Llama-3.2-3B-Instruct/v1/chat/completions \
|
|
59
|
+
-H "Authorization: Bearer $HF_API_KEY" \
|
|
60
|
+
-H "Content-Type: application/json" \
|
|
61
|
+
-d '{
|
|
62
|
+
"messages": [{"role": "user", "content": "Say hello in exactly 3 words."}]
|
|
63
|
+
}' | jq -r '.choices[0].message.content'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## A3M Proxy (localhost:8787)
|
|
69
|
+
|
|
70
|
+
After `docker compose up` or `npx a3m-router serve`:
|
|
71
|
+
|
|
72
|
+
### Auto-route (cheapest capable model)
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
curl http://localhost:8787/v1/chat/completions \
|
|
76
|
+
-H "Content-Type: application/json" \
|
|
77
|
+
-d '{
|
|
78
|
+
"model": "auto",
|
|
79
|
+
"messages": [{"role": "user", "content": "What is the capital of France?"}]
|
|
80
|
+
}'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Route without executing (preview the decision)
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
curl -X POST http://localhost:8787/v1/route \
|
|
87
|
+
-H "Content-Type: application/json" \
|
|
88
|
+
-d '{"query": "Write a Python function to sort a list"}'
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Returns model selection, confidence score, estimated cost, and reasoning — without spending a penny.
|
|
92
|
+
|
|
93
|
+
### List available models
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
curl http://localhost:8787/v1/models | jq '.data[].id'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Health check
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
curl http://localhost:8787/health | jq '.status'
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Force a specific provider
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
curl http://localhost:8787/v1/chat/completions \
|
|
109
|
+
-H "Content-Type: application/json" \
|
|
110
|
+
-d '{
|
|
111
|
+
"model": "groq/llama-3.3-70b-versatile",
|
|
112
|
+
"messages": [{"role": "user", "content": "Hello!"}]
|
|
113
|
+
}'
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Quick Provider Comparison
|
|
119
|
+
|
|
120
|
+
Spin up A3M Proxy, then compare responses from different providers to the _same_ prompt:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# Terminal 1: start the proxy
|
|
124
|
+
npx a3m-router serve
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Terminal 2: compare providers
|
|
129
|
+
for provider in auto groq/llama-3.3-70b-versatile cerebras/llama-3.3-70b; do
|
|
130
|
+
echo "=== $provider ==="
|
|
131
|
+
curl -s http://localhost:8787/v1/chat/completions \
|
|
132
|
+
-H "Content-Type: application/json" \
|
|
133
|
+
-d "{\"model\": \"$provider\", \"messages\": [{\"role\": \"user\", \"content\": \"Explain quantum entanglement in one sentence.\"}]}" \
|
|
134
|
+
| jq -r '.choices[0].message.content'
|
|
135
|
+
echo
|
|
136
|
+
done
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Or compare via the [compare-providers.sh](../scripts/compare-providers.sh) script.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## NVIDIA NIM Catalog
|
|
144
|
+
|
|
145
|
+
NVIDIA's build.nvidia.com hosts 100+ free models. Here's the pattern:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Any NIM model follows this URL pattern:
|
|
149
|
+
# POST https://integrate.api.nvidia.com/v1/chat/completions
|
|
150
|
+
# model: "{org}/{model-name}"
|
|
151
|
+
|
|
152
|
+
# Meta Llama variants
|
|
153
|
+
curl -s https://integrate.api.nvidia.com/v1/chat/completions \
|
|
154
|
+
-H "Authorization: Bearer $NV_API_KEY" \
|
|
155
|
+
-H "Content-Type: application/json" \
|
|
156
|
+
-d '{"model": "meta/llama-3.1-405b-instruct", "messages": [{"role":"user","content":"Hi"}]}'
|
|
157
|
+
|
|
158
|
+
# Mistral
|
|
159
|
+
curl -s https://integrate.api.nvidia.com/v1/chat/completions \
|
|
160
|
+
-H "Authorization: Bearer $NV_API_KEY" \
|
|
161
|
+
-H "Content-Type: application/json" \
|
|
162
|
+
-d '{"model": "mistralai/mistral-7b-instruct-v0.3", "messages": [{"role":"user","content":"Hi"}]}'
|
|
163
|
+
|
|
164
|
+
# Google Gemma
|
|
165
|
+
curl -s https://integrate.api.nvidia.com/v1/chat/completions \
|
|
166
|
+
-H "Authorization: Bearer $NV_API_KEY" \
|
|
167
|
+
-H "Content-Type: application/json" \
|
|
168
|
+
-d '{"model": "google/gemma-2-27b-it", "messages": [{"role":"user","content":"Hi"}]}'
|
|
169
|
+
|
|
170
|
+
# Nemotron (NVIDIA's own)
|
|
171
|
+
curl -s https://integrate.api.nvidia.com/v1/chat/completions \
|
|
172
|
+
-H "Authorization: Bearer $NV_API_KEY" \
|
|
173
|
+
-H "Content-Type: application/json" \
|
|
174
|
+
-d '{"model": "nvidia/llama-3.1-nemotron-70b-instruct", "messages": [{"role":"user","content":"Hi"}]}'
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Diagnostics & Debugging
|
|
180
|
+
|
|
181
|
+
### See what model A3M chose
|
|
182
|
+
|
|
183
|
+
The proxy returns the selected `model` in the response:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
curl -s http://localhost:8787/v1/chat/completions \
|
|
187
|
+
-H "Content-Type: application/json" \
|
|
188
|
+
-d '{"model":"auto","messages":[{"role":"user","content":"Hello"}]}' \
|
|
189
|
+
| jq '.model, .choices[0].message.content'
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Check which providers are healthy
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
curl -s http://localhost:8787/health | jq '.providers.details | to_entries[] | select(.value.available == true) | .key'
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Token usage estimate
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
curl -s http://localhost:8787/v1/chat/completions \
|
|
202
|
+
-H "Content-Type: application/json" \
|
|
203
|
+
-d '{"model":"auto","messages":[{"role":"user","content":"Write a haiku"}]}' \
|
|
204
|
+
| jq '.usage'
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Cost summary (from A3M analytics)
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
curl -s http://localhost:8787/v1/route \
|
|
211
|
+
-H "Content-Type: application/json" \
|
|
212
|
+
-d '{"query":"Write a haiku"}' \
|
|
213
|
+
| jq '.estimated_cost'
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## One-Liner Cheat Sheet
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Groq — fastest free inference
|
|
222
|
+
curl -s https://api.groq.com/openai/v1/chat/completions -H "Authorization: Bearer $GROQ_API_KEY" -H "Content-Type: application/json" -d '{"model":"llama-3.3-70b-versatile","messages":[{"role":"user","content":"Hi"}]}' | jq -r '.choices[0].message.content'
|
|
223
|
+
|
|
224
|
+
# NVIDIA NIM — 100+ free models
|
|
225
|
+
curl -s https://integrate.api.nvidia.com/v1/chat/completions -H "Authorization: Bearer $NV_API_KEY" -H "Content-Type: application/json" -d '{"model":"meta/llama-3.3-70b-instruct","messages":[{"role":"user","content":"Hi"}]}' | jq -r '.choices[0].message.content'
|
|
226
|
+
|
|
227
|
+
# Cerebras — ultra-low latency
|
|
228
|
+
curl -s https://api.cerebras.ai/v1/chat/completions -H "Authorization: Bearer $CEREBRAS_API_KEY" -H "Content-Type: application/json" -d '{"model":"llama-3.3-70b","messages":[{"role":"user","content":"Hi"}]}' | jq -r '.choices[0].message.content'
|
|
229
|
+
|
|
230
|
+
# A3M Proxy — auto-route to cheapest
|
|
231
|
+
curl http://localhost:8787/v1/chat/completions -H "Content-Type: application/json" -d '{"model":"auto","messages":[{"role":"user","content":"Hi"}]}'
|
|
232
|
+
|
|
233
|
+
# Preview routing decision
|
|
234
|
+
curl -X POST http://localhost:8787/v1/route -H "Content-Type: application/json" -d '{"query":"Hi"}'
|
|
235
|
+
|
|
236
|
+
# Health check
|
|
237
|
+
curl http://localhost:8787/health | jq '.status'
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Next Steps
|
|
243
|
+
|
|
244
|
+
- [Full API Reference](API.md)
|
|
245
|
+
- [Quick Start Guide](QUICK_START.md)
|
|
246
|
+
- [Configuration](CONFIGURATION.md)
|
|
247
|
+
- [RunKit Browser Demo](https://runkit.com/npm/adaptive-memory-multi-model-router)
|