-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.html
More file actions
1212 lines (1024 loc) · 54.3 KB
/
Copy pathdocs.html
File metadata and controls
1212 lines (1024 loc) · 54.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NadirClaw Docs | Installation, API Reference & Configuration</title>
<meta name="description" content="Comprehensive documentation for NadirClaw, the open-source LLM router that cuts AI costs by 40-70%.">
<link rel="canonical" href="https://getnadir.com/docs.html" />
<meta property="og:type" content="website">
<meta property="og:url" content="https://getnadir.com/docs.html">
<meta property="og:title" content="NadirClaw Documentation | Installation, Configuration & API Reference">
<meta property="og:description" content="Comprehensive documentation for NadirClaw, the open-source LLM router that cuts AI costs by 40-70%.">
<meta property="og:image" content="https://getnadir.com/og-image.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="NadirClaw Documentation">
<meta name="twitter:description" content="Comprehensive documentation for NadirClaw, the open-source LLM router that cuts AI costs by 40-70%.">
<meta name="twitter:image" content="https://getnadir.com/og-image.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "TechArticle",
"headline": "NadirClaw Documentation | Installation, Configuration & API Reference",
"description": "Comprehensive documentation for NadirClaw, the open-source LLM router that cuts AI costs by 40-70%.",
"url": "https://getnadir.com/docs.html",
"publisher": { "@type": "Organization", "name": "NadirClaw", "url": "https://getnadir.com" }
}
</script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--bg: #ffffff;
--bg-subtle: #fafafa;
--bg-hover: #f5f5f5;
--text: #0a0a0a;
--text-secondary: #666666;
--text-tertiary: #999999;
--border: #e5e5e5;
--accent: #0066ff;
--accent-hover: #0052cc;
--success: #00a86b;
--code-bg: #f8f8f8;
--sidebar-w: 260px;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.6;
-webkit-font-smoothing: antialiased;
}
code, pre, .mono {
font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}
/* Header */
header {
padding: 20px 0;
border-bottom: 1px solid var(--border);
background: rgba(255,255,255,0.8);
backdrop-filter: blur(8px);
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 200;
}
.header-content {
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
font-size: 20px;
font-weight: 600;
color: var(--text);
text-decoration: none;
letter-spacing: -0.3px;
}
.nav-links { display: flex; gap: 24px; align-items: center; }
.nav-links a {
color: var(--text-secondary);
text-decoration: none;
font-size: 14px;
font-weight: 500;
transition: color 0.15s;
}
.nav-links a:hover { color: var(--text); }
.nav-links a.active { color: var(--accent); }
.github-link {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 14px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 6px;
color: var(--text);
text-decoration: none;
font-size: 14px;
font-weight: 500;
transition: all 0.15s ease;
}
.github-link:hover {
border-color: var(--text);
background: var(--bg-subtle);
}
/* Layout */
.layout {
display: flex;
margin-top: 65px;
min-height: calc(100vh - 65px);
}
/* Sidebar */
.sidebar {
width: var(--sidebar-w);
border-right: 1px solid var(--border);
padding: 32px 24px;
position: fixed;
top: 65px;
bottom: 0;
overflow-y: auto;
background: var(--bg-subtle);
}
.sidebar-section {
margin-bottom: 24px;
}
.sidebar-section-title {
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.8px;
color: var(--text-tertiary);
margin-bottom: 8px;
}
.sidebar a {
display: block;
padding: 5px 12px;
margin: 0 -12px;
color: var(--text-secondary);
text-decoration: none;
font-size: 14px;
border-radius: 6px;
transition: all 0.1s;
}
.sidebar a:hover {
background: var(--bg-hover);
color: var(--text);
}
.sidebar a.active {
background: rgba(0,102,255,0.08);
color: var(--accent);
font-weight: 500;
}
/* Content */
.content {
margin-left: var(--sidebar-w);
flex: 1;
max-width: 820px;
padding: 48px 64px 120px;
}
.content h1 {
font-size: 36px;
font-weight: 700;
letter-spacing: -0.8px;
margin-bottom: 12px;
}
.content h2 {
font-size: 26px;
font-weight: 700;
letter-spacing: -0.5px;
margin-top: 64px;
margin-bottom: 16px;
padding-top: 24px;
border-top: 1px solid var(--border);
}
.content h2:first-of-type {
margin-top: 48px;
}
.content h3 {
font-size: 19px;
font-weight: 600;
margin-top: 32px;
margin-bottom: 12px;
}
.content p, .content li {
font-size: 15px;
color: var(--text-secondary);
line-height: 1.7;
margin-bottom: 12px;
}
.content ul, .content ol {
padding-left: 24px;
margin-bottom: 16px;
}
.content a {
color: var(--accent);
text-decoration: none;
}
.content a:hover {
text-decoration: underline;
}
.content code {
background: var(--code-bg);
border: 1px solid var(--border);
padding: 2px 6px;
border-radius: 4px;
font-size: 13px;
}
.content pre {
background: var(--code-bg);
border: 1px solid var(--border);
border-radius: 8px;
padding: 20px;
overflow-x: auto;
font-size: 13px;
line-height: 1.7;
margin-bottom: 20px;
}
.content pre code {
background: none;
border: none;
padding: 0;
}
.content table {
width: 100%;
border-collapse: collapse;
border: 1px solid var(--border);
border-radius: 8px;
overflow: hidden;
margin-bottom: 20px;
font-size: 14px;
}
.content thead { background: var(--bg-subtle); }
.content th {
padding: 12px 16px;
text-align: left;
font-weight: 600;
font-size: 13px;
color: var(--text-secondary);
border-bottom: 1px solid var(--border);
}
.content td {
padding: 12px 16px;
border-bottom: 1px solid var(--border);
color: var(--text-secondary);
}
.content tbody tr:last-child td { border-bottom: none; }
.content tbody tr:hover { background: var(--bg-subtle); }
.lead {
font-size: 17px;
color: var(--text-secondary);
margin-bottom: 32px;
}
.callout {
background: rgba(0,102,255,0.04);
border: 1px solid rgba(0,102,255,0.15);
border-radius: 8px;
padding: 16px 20px;
margin-bottom: 20px;
}
.callout p { margin-bottom: 0; }
.callout-warn {
background: rgba(255,165,0,0.05);
border-color: rgba(255,165,0,0.2);
}
/* Mobile */
.menu-toggle { display: none; }
@media (max-width: 900px) {
.sidebar {
transform: translateX(-100%);
z-index: 150;
transition: transform 0.2s;
}
.sidebar.open { transform: translateX(0); }
.content { margin-left: 0; padding: 32px 20px 80px; }
.menu-toggle {
display: block;
background: none;
border: 1px solid var(--border);
border-radius: 6px;
padding: 6px 10px;
font-size: 16px;
cursor: pointer;
}
.docs-footer .footer-content { flex-direction: column; gap: 16px; text-align: center; }
.docs-footer .footer-links { justify-content: center; }
}
/* Footer */
.docs-footer {
padding: 32px 0;
border-top: 1px solid var(--border);
margin-left: var(--sidebar-w);
}
.docs-footer .footer-content {
max-width: 1120px;
margin: 0 auto;
padding: 0 32px;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 24px;
}
.docs-footer .footer-links { display: flex; gap: 32px; flex-wrap: wrap; }
.docs-footer .footer-links a {
color: var(--text-tertiary);
text-decoration: none;
font-size: 14px;
transition: color 0.15s;
}
.docs-footer .footer-links a:hover { color: var(--text); }
.docs-footer .footer-note { color: var(--text-tertiary); font-size: 14px; }
@media (max-width: 900px) {
.docs-footer { margin-left: 0; }
}
</style>
</head>
<body>
<header>
<div class="container">
<div class="header-content">
<a href="/" style="display:flex;align-items:center;gap:8px;text-decoration:none;">
<img src="/logo.png" alt="NadirClaw" style="height:32px;width:auto;">
<span style="color:var(--text);font-weight:600;font-size:15px;font-family:'SF Mono',Monaco,'Cascadia Code',monospace;">nadirclaw</span>
</a>
<div class="nav-links">
<a href="/">Home</a>
<a href="docs.html" class="active">Docs</a>
<a href="/#blog">Blog</a>
<a href="/openclaw">OpenClaw</a>
<a href="/optimize">Optimize</a>
<a href="https://github.com/NadirRouter/NadirClaw" class="github-link" target="_blank" rel="noopener noreferrer">
<span>★</span>
<span class="star-count" id="star-count">Loading stars...</span>
</a>
<script>
async function loadGitHubStars() {
try {
const res = await fetch("https://api.github.com/repos/NadirRouter/NadirClaw");
if (!res.ok) throw new Error("Failed to fetch GitHub repo data");
const data = await res.json();
const stars = data.stargazers_count;
document.getElementById("star-count").textContent =
`${stars.toLocaleString()} stars`;
} catch (error) {
console.error(error);
document.getElementById("star-count").textContent = "View on GitHub";
}
}
loadGitHubStars();
</script> </div>
</div>
</div>
</header>
<div class="layout">
<nav class="sidebar">
<div class="sidebar-section">
<div class="sidebar-section-title">Getting Started</div>
<a href="#installation">Installation</a>
<a href="#quick-start">Quick Start</a>
<a href="#first-run">First Run</a>
</div>
<div class="sidebar-section">
<div class="sidebar-section-title">Configuration</div>
<a href="#environment">Environment Variables</a>
<a href="#config-file">Config File</a>
<a href="#model-setup">Model Setup</a>
<a href="#authentication">Authentication</a>
</div>
<div class="sidebar-section">
<div class="sidebar-section-title">Core Concepts</div>
<a href="#routing">Routing</a>
<a href="#three-tier">Three-Tier Routing</a>
<a href="#routing-profiles">Routing Profiles</a>
<a href="#fallback-chains">Fallback Chains</a>
<a href="#rate-limiting">Rate Limiting</a>
<a href="#prompt-caching">Prompt Caching</a>
</div>
<div class="sidebar-section">
<div class="sidebar-section-title">Integrations</div>
<a href="#claude-code">Claude Code</a>
<a href="#openclaw">OpenClaw</a>
<a href="#codex">Codex</a>
<a href="#continue">Continue</a>
<a href="#cursor">Cursor</a>
<a href="#open-webui">Open WebUI</a>
<a href="#openai-compatible">Any OpenAI Client</a>
</div>
<div class="sidebar-section">
<div class="sidebar-section-title">CLI</div>
<a href="#cli-commands">CLI Reference</a>
</div>
<div class="sidebar-section">
<div class="sidebar-section-title">Operations</div>
<a href="#budget">Budget & Cost Tracking</a>
<a href="#prometheus">Prometheus Metrics</a>
<a href="#opentelemetry">OpenTelemetry</a>
<a href="#docker">Docker</a>
<a href="#api-reference">API Reference</a>
<a href="#troubleshooting">Troubleshooting</a>
</div>
</nav>
<main class="content">
<h1>NadirClaw Documentation</h1>
<p class="lead">Open-source LLM router that classifies prompt complexity and routes to the optimal model. Cut AI API costs by 40-70% with zero code changes.</p>
<!-- GETTING STARTED -->
<h2 id="installation">Installation</h2>
<h3>pip (recommended)</h3>
<pre><code>pip install nadirclaw</code></pre>
<h3>One-line install script</h3>
<pre><code>curl -fsSL https://raw.githubusercontent.com/NadirRouter/NadirClaw/main/install.sh | sh</code></pre>
<p>This clones to <code>~/.nadirclaw</code>, creates a venv, installs deps, and adds <code>nadirclaw</code> to your PATH. Run it again to update.</p>
<h3>From source</h3>
<pre><code>git clone https://github.com/NadirRouter/NadirClaw.git
cd NadirClaw
python3 -m venv venv
source venv/bin/activate
pip install -e .</code></pre>
<h3>Docker</h3>
<pre><code>git clone https://github.com/NadirRouter/NadirClaw.git && cd NadirClaw
docker compose up</code></pre>
<h3>Uninstall</h3>
<pre><code>rm -rf ~/.nadirclaw
sudo rm -f /usr/local/bin/nadirclaw</code></pre>
<h2 id="quick-start">Quick Start</h2>
<pre><code># Install
pip install nadirclaw
# Interactive setup (providers, API keys, models)
nadirclaw setup
# Start the router
nadirclaw serve --verbose</code></pre>
<p>NadirClaw starts on <code>http://localhost:8856</code> with sensible defaults (Gemini Flash for simple, Codex for complex). If you skip <code>nadirclaw setup</code>, the <code>serve</code> command will offer to run it on first launch.</p>
<h2 id="first-run">First Run</h2>
<p>On first request, NadirClaw downloads the <a href="https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2">all-MiniLM-L6-v2</a> sentence embedding model (~80 MB). This takes 2-3 seconds. Subsequent requests classify in ~10ms.</p>
<div class="callout">
<p><strong>Prerequisites:</strong> Python 3.10+ and at least one LLM provider: a <a href="https://aistudio.google.com/apikey">Gemini API key</a> (free tier available), <a href="https://ollama.com">Ollama</a> running locally (free), or any cloud provider API key.</p>
</div>
<!-- CONFIGURATION -->
<h2 id="environment">Environment Variables</h2>
<p>NadirClaw loads config from <code>~/.nadirclaw/.env</code>. If that doesn't exist, it falls back to <code>.env</code> in the current directory.</p>
<table>
<thead><tr><th>Variable</th><th>Default</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>NADIRCLAW_SIMPLE_MODEL</code></td><td><code>gemini-3-flash-preview</code></td><td>Model for simple prompts</td></tr>
<tr><td><code>NADIRCLAW_COMPLEX_MODEL</code></td><td><code>openai-codex/gpt-5.3-codex</code></td><td>Model for complex prompts</td></tr>
<tr><td><code>NADIRCLAW_REASONING_MODEL</code></td><td><em>falls back to complex</em></td><td>Model for reasoning tasks</td></tr>
<tr><td><code>NADIRCLAW_MID_MODEL</code></td><td><em>none (enables 3-tier)</em></td><td>Model for mid-complexity prompts</td></tr>
<tr><td><code>NADIRCLAW_FREE_MODEL</code></td><td><em>falls back to simple</em></td><td>Free/local fallback model</td></tr>
<tr><td><code>NADIRCLAW_TIER_THRESHOLDS</code></td><td><code>0.35,0.65</code></td><td>Score thresholds for simple/mid/complex boundaries</td></tr>
<tr><td><code>NADIRCLAW_FALLBACK_CHAIN</code></td><td><em>all tier models</em></td><td>Comma-separated global cascade on failure</td></tr>
<tr><td><code>NADIRCLAW_SIMPLE_FALLBACK</code></td><td><em>none</em></td><td>Per-tier fallback for simple model failures</td></tr>
<tr><td><code>NADIRCLAW_COMPLEX_FALLBACK</code></td><td><em>none</em></td><td>Per-tier fallback for complex model failures</td></tr>
<tr><td><code>NADIRCLAW_CONFIDENCE_THRESHOLD</code></td><td><code>0.06</code></td><td>Classification threshold (lower = more complex)</td></tr>
<tr><td><code>NADIRCLAW_PORT</code></td><td><code>8856</code></td><td>Server port</td></tr>
<tr><td><code>NADIRCLAW_AUTH_TOKEN</code></td><td><em>empty (auth disabled)</em></td><td>Bearer token requirement</td></tr>
<tr><td><code>NADIRCLAW_LOG_DIR</code></td><td><code>~/.nadirclaw/logs</code></td><td>Log directory</td></tr>
<tr><td><code>NADIRCLAW_LOG_RAW</code></td><td><code>false</code></td><td>Log full raw requests/responses</td></tr>
<tr><td><code>NADIRCLAW_DAILY_BUDGET</code></td><td><em>none</em></td><td>Daily spend limit in USD</td></tr>
<tr><td><code>NADIRCLAW_MONTHLY_BUDGET</code></td><td><em>none</em></td><td>Monthly spend limit in USD</td></tr>
<tr><td><code>NADIRCLAW_BUDGET_WARN_THRESHOLD</code></td><td><code>0.8</code></td><td>Alert at this fraction of budget</td></tr>
<tr><td><code>NADIRCLAW_BUDGET_WEBHOOK_URL</code></td><td><em>none</em></td><td>Webhook for budget alerts</td></tr>
<tr><td><code>NADIRCLAW_BUDGET_STDOUT_ALERTS</code></td><td><code>false</code></td><td>Print budget alerts to stdout</td></tr>
<tr><td><code>NADIRCLAW_CACHE_TTL</code></td><td><em>default</em></td><td>Cache time-to-live in seconds</td></tr>
<tr><td><code>NADIRCLAW_CACHE_MAX_SIZE</code></td><td><em>default</em></td><td>Max cache entries</td></tr>
<tr><td><code>NADIRCLAW_CACHE_ENABLED</code></td><td><code>true</code></td><td>Enable/disable prompt cache</td></tr>
<tr><td><code>NADIRCLAW_MODEL_RATE_LIMITS</code></td><td><em>none</em></td><td>Per-model RPM limits (e.g. <code>gemini-3-flash-preview=30,gpt-4.1=60</code>)</td></tr>
<tr><td><code>NADIRCLAW_DEFAULT_MODEL_RPM</code></td><td><code>0</code> (unlimited)</td><td>Default RPM limit for all models</td></tr>
<tr><td><code>NADIRCLAW_API_BASE</code></td><td><em>none</em></td><td>Custom OpenAI-compatible endpoint (vLLM, LocalAI, etc.)</td></tr>
<tr><td><code>GEMINI_API_KEY</code></td><td>-</td><td>Google Gemini API key</td></tr>
<tr><td><code>ANTHROPIC_API_KEY</code></td><td>-</td><td>Anthropic API key</td></tr>
<tr><td><code>OPENAI_API_KEY</code></td><td>-</td><td>OpenAI API key</td></tr>
<tr><td><code>OLLAMA_API_BASE</code></td><td><code>http://localhost:11434</code></td><td>Ollama base URL</td></tr>
<tr><td><code>OTEL_EXPORTER_OTLP_ENDPOINT</code></td><td><em>empty</em></td><td>OpenTelemetry collector endpoint</td></tr>
</tbody>
</table>
<h2 id="config-file">Config File</h2>
<p>The primary configuration lives in <code>~/.nadirclaw/.env</code>. Example:</p>
<pre><code># ~/.nadirclaw/.env
# API keys
GEMINI_API_KEY=AIza...
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
# Model routing
NADIRCLAW_SIMPLE_MODEL=gemini-3-flash-preview
NADIRCLAW_COMPLEX_MODEL=gemini-2.5-pro
# Server
NADIRCLAW_PORT=8856
# Budget
NADIRCLAW_DAILY_BUDGET=10.00
NADIRCLAW_MONTHLY_BUDGET=200.00</code></pre>
<p>Credentials are stored separately in <code>~/.nadirclaw/credentials.json</code> (managed via <code>nadirclaw auth</code>). Logs go to <code>~/.nadirclaw/logs/</code>.</p>
<h2 id="model-setup">Model Setup</h2>
<p>Configure which model handles each routing tier:</p>
<table>
<thead><tr><th>Setup</th><th>Simple Model</th><th>Complex Model</th><th>Keys Needed</th></tr></thead>
<tbody>
<tr><td>Gemini + Gemini</td><td><code>gemini-2.5-flash</code></td><td><code>gemini-2.5-pro</code></td><td><code>GEMINI_API_KEY</code></td></tr>
<tr><td>Gemini + Claude</td><td><code>gemini-2.5-flash</code></td><td><code>claude-sonnet-4-5-20250929</code></td><td><code>GEMINI_API_KEY</code> + <code>ANTHROPIC_API_KEY</code></td></tr>
<tr><td>Claude + Claude</td><td><code>claude-haiku-4-5-20251001</code></td><td><code>claude-sonnet-4-5-20250929</code></td><td><code>ANTHROPIC_API_KEY</code></td></tr>
<tr><td>OpenAI + OpenAI</td><td><code>gpt-4.1-mini</code></td><td><code>gpt-4.1</code></td><td><code>OPENAI_API_KEY</code></td></tr>
<tr><td>Fully local</td><td><code>ollama/llama3.1:8b</code></td><td><code>ollama/qwen3:32b</code></td><td>None</td></tr>
</tbody>
</table>
<p>Gemini models are called natively via the Google GenAI SDK. All other models go through <a href="https://docs.litellm.ai/docs/providers">LiteLLM</a> (100+ providers).</p>
<h3>Model Aliases</h3>
<p>Use short names instead of full model IDs:</p>
<table>
<thead><tr><th>Alias</th><th>Resolves To</th></tr></thead>
<tbody>
<tr><td><code>sonnet</code></td><td><code>claude-sonnet-4-5-20250929</code></td></tr>
<tr><td><code>opus</code></td><td><code>claude-opus-4-6-20250918</code></td></tr>
<tr><td><code>haiku</code></td><td><code>claude-haiku-4-5-20251001</code></td></tr>
<tr><td><code>gpt4</code></td><td><code>gpt-4.1</code></td></tr>
<tr><td><code>gpt5</code></td><td><code>gpt-5.2</code></td></tr>
<tr><td><code>flash</code></td><td><code>gemini-2.5-flash</code></td></tr>
<tr><td><code>gemini-pro</code></td><td><code>gemini-2.5-pro</code></td></tr>
<tr><td><code>deepseek</code></td><td><code>deepseek/deepseek-chat</code></td></tr>
<tr><td><code>deepseek-r1</code></td><td><code>deepseek/deepseek-reasoner</code></td></tr>
<tr><td><code>llama</code></td><td><code>ollama/llama3.1:8b</code></td></tr>
</tbody>
</table>
<h2 id="authentication">Authentication</h2>
<p>NadirClaw checks credentials in order: OpenClaw stored token → NadirClaw credential → environment variable.</p>
<pre><code># Add API keys
nadirclaw auth add --provider google --key AIza...
nadirclaw auth add --provider anthropic --key sk-ant-...
nadirclaw auth add --provider openai --key sk-...
# OAuth login (no API key needed)
nadirclaw auth openai login
nadirclaw auth anthropic login
nadirclaw auth gemini login
# Store Claude subscription token
nadirclaw auth setup-token
# Check status
nadirclaw auth status
# Remove
nadirclaw auth remove google</code></pre>
<!-- ROUTING -->
<h2 id="routing">Routing</h2>
<h3>How Classification Works</h3>
<p>NadirClaw uses a binary complexity classifier based on sentence embeddings:</p>
<ol>
<li><strong>Pre-computed centroids:</strong> two tiny vectors (~1.5 KB each) derived from ~170 seed prompts, shipped with the package.</li>
<li><strong>Classification:</strong> computes the prompt's embedding via <code>all-MiniLM-L6-v2</code> and measures cosine similarity to both centroids. Closer to complex centroid → complex model.</li>
<li><strong>Borderline handling:</strong> when confidence is below threshold (default <code>0.06</code>), defaults to complex. It's cheaper to over-serve than under-serve.</li>
</ol>
<h3>Routing Tiers</h3>
<table>
<thead><tr><th>Tier</th><th>When Used</th><th>Typical Prompts</th></tr></thead>
<tbody>
<tr><td><strong>Simple</strong></td><td>Prompt closer to simple centroid with confidence above threshold</td><td>"What does this function do?", "Format this JSON", "Add a docstring"</td></tr>
<tr><td><strong>Mid</strong></td><td>Score between tier thresholds (requires <code>NADIRCLAW_MID_MODEL</code>)</td><td>"Write a unit test for this function", "Explain this error"</td></tr>
<tr><td><strong>Complex</strong></td><td>Prompt closer to complex centroid, or borderline</td><td>"Refactor this module", "Design a caching layer", "Debug this deadlock"</td></tr>
<tr><td><strong>Reasoning</strong></td><td>2+ reasoning markers detected ("step by step", "prove that", "analyze tradeoffs")</td><td>Mathematical proofs, architecture analysis, critical evaluations</td></tr>
<tr><td><strong>Agentic</strong></td><td>Tool definitions, tool-role messages, agent system prompts, deep conversations (>10 messages)</td><td>Any multi-step agent workflow, coding agent sessions</td></tr>
<tr><td><strong>Vision</strong></td><td>Image content (<code>image_url</code>) detected in messages</td><td>Screenshot analysis, diagram reading, image-based questions</td></tr>
</tbody>
</table>
<h3>Routing Modifiers</h3>
<p>After base classification, these overrides apply in order:</p>
<ul>
<li><strong>Agentic detection:</strong> forces complex when tool definitions, tool-role messages, or agent system prompts are detected</li>
<li><strong>Reasoning detection:</strong> routes to reasoning model when 2+ reasoning markers found</li>
<li><strong>Vision detection:</strong> swaps to a vision-capable model (GPT-4o, Claude, Gemini) when <code>image_url</code> content is detected</li>
<li><strong>Context window check:</strong> swaps to a model with larger context if conversation exceeds model's limit</li>
<li><strong>Session persistence:</strong> reuses the same model for follow-up messages (30-minute TTL)</li>
</ul>
<h3>Confidence Threshold</h3>
<p>The <code>NADIRCLAW_CONFIDENCE_THRESHOLD</code> (default <code>0.06</code>) controls borderline routing. Lower values route more prompts to complex. Adjust based on your quality tolerance:</p>
<pre><code># More conservative (routes more to complex)
NADIRCLAW_CONFIDENCE_THRESHOLD=0.03
# More aggressive savings (routes more to simple)
NADIRCLAW_CONFIDENCE_THRESHOLD=0.10</code></pre>
<h2 id="routing-profiles">Routing Profiles</h2>
<p>Override routing strategy per-request via the <code>model</code> field:</p>
<table>
<thead><tr><th>Profile</th><th>Model Field</th><th>Behavior</th></tr></thead>
<tbody>
<tr><td><strong>auto</strong></td><td><code>auto</code> or omit</td><td>Smart routing (default)</td></tr>
<tr><td><strong>eco</strong></td><td><code>eco</code></td><td>Always use simple model</td></tr>
<tr><td><strong>premium</strong></td><td><code>premium</code></td><td>Always use complex model</td></tr>
<tr><td><strong>free</strong></td><td><code>free</code></td><td>Use free/local fallback model</td></tr>
<tr><td><strong>reasoning</strong></td><td><code>reasoning</code></td><td>Use reasoning model</td></tr>
</tbody>
</table>
<pre><code># Use eco mode for maximum savings
curl http://localhost:8856/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "eco", "messages": [{"role": "user", "content": "Hello"}]}'</code></pre>
<!-- THREE-TIER ROUTING -->
<h2 id="three-tier">Three-Tier Routing</h2>
<p>By default, NadirClaw uses binary routing (simple/complex). Enable three-tier routing by setting a mid model:</p>
<pre><code># Enable three-tier routing
NADIRCLAW_MID_MODEL=gpt-4.1-mini
# Customize tier boundaries (default: 0.35,0.65)
NADIRCLAW_TIER_THRESHOLDS=0.35,0.65</code></pre>
<p>With three-tier routing, classification scores map to tiers:</p>
<table>
<thead><tr><th>Score Range</th><th>Tier</th><th>Model</th></tr></thead>
<tbody>
<tr><td>0.00 - 0.35</td><td>Simple</td><td><code>NADIRCLAW_SIMPLE_MODEL</code></td></tr>
<tr><td>0.35 - 0.65</td><td>Mid</td><td><code>NADIRCLAW_MID_MODEL</code></td></tr>
<tr><td>0.65 - 1.00</td><td>Complex</td><td><code>NADIRCLAW_COMPLEX_MODEL</code></td></tr>
</tbody>
</table>
<p>If <code>NADIRCLAW_MID_MODEL</code> is not set, NadirClaw falls back to binary routing (simple/complex).</p>
<!-- FALLBACK CHAINS -->
<h2 id="fallback-chains">Fallback Chains</h2>
<p>When a model fails (429 rate limit, 5xx error, or timeout), NadirClaw cascades through a configurable chain of fallback models until one succeeds.</p>
<pre><code># Configure fallback order
NADIRCLAW_FALLBACK_CHAIN=gpt-4.1,claude-sonnet-4-5-20250929,gemini-2.5-flash</code></pre>
<h3>Per-tier fallback chains</h3>
<p>You can also configure fallback chains per tier for more granular control:</p>
<pre><code># Per-tier fallback chains
NADIRCLAW_SIMPLE_FALLBACK=gemini-2.5-flash,gemini-3-flash-preview
NADIRCLAW_COMPLEX_FALLBACK=gpt-4.1,claude-sonnet-4-5-20250929
NADIRCLAW_MID_FALLBACK=gpt-4.1-mini,gemini-2.5-flash</code></pre>
<p><strong>Default behavior:</strong> If no fallback chain is configured, NadirClaw uses all your configured tier models: [COMPLEX_MODEL, MID_MODEL, SIMPLE_MODEL, REASONING_MODEL, FREE_MODEL].</p>
<p><strong>Rate limit handling:</strong> On 429 errors, NadirClaw automatically retries once before moving to the next model in the chain. If all models are exhausted, it returns a friendly error message.</p>
<!-- RATE LIMITING -->
<h2 id="rate-limiting">Rate Limiting</h2>
<p>Configure per-model request rate limits to stay within provider quotas:</p>
<pre><code># Per-model RPM limits
NADIRCLAW_MODEL_RATE_LIMITS=gemini-3-flash-preview=30,gpt-4.1=60
# Default RPM for all models (0 = unlimited)
NADIRCLAW_DEFAULT_MODEL_RPM=0</code></pre>
<p>When a model hits its RPM limit, NadirClaw automatically triggers the fallback chain rather than returning an error. Monitor rate limit status via the API:</p>
<pre><code>curl http://localhost:8856/v1/rate-limits</code></pre>
<!-- PROMPT CACHING -->
<h2 id="prompt-caching">Prompt Caching</h2>
<p>NadirClaw includes an in-memory LRU cache for identical chat completions, skipping redundant LLM calls entirely.</p>
<pre><code># Configure cache
NADIRCLAW_CACHE_TTL=300 # TTL in seconds (default varies)
NADIRCLAW_CACHE_MAX_SIZE=1000 # Max cached entries</code></pre>
<p><strong>Monitor cache:</strong></p>
<pre><code># CLI
nadirclaw cache
# API endpoint
curl http://localhost:8856/v1/cache</code></pre>
<p>Cache is keyed on the full message content. Streaming requests with identical content will also hit the cache. Only exact matches count. No fuzzy matching.</p>
<!-- INTEGRATIONS -->
<h2 id="claude-code">Claude Code</h2>
<p>NadirClaw works as a drop-in proxy for <a href="https://docs.anthropic.com/en/docs/claude-code">Claude Code</a>:</p>
<pre><code># Point Claude Code at NadirClaw
export ANTHROPIC_BASE_URL=http://localhost:8856/v1
export ANTHROPIC_API_KEY=local
# Start NadirClaw, then use Claude Code normally
nadirclaw serve --verbose
claude</code></pre>
<p>Or use a shell alias:</p>
<pre><code>alias claude-routed='ANTHROPIC_BASE_URL=http://localhost:8856/v1 ANTHROPIC_API_KEY=local claude'</code></pre>
<p>Simple prompts ("read this file", "what does this function do?") route to a cheap model like Gemini Flash. Complex prompts ("refactor this module") stay on Claude. Typical savings: 40-70%.</p>
<h3>Using your Claude subscription</h3>
<pre><code># OAuth login (opens browser)
nadirclaw auth anthropic login
# Or store token directly
nadirclaw auth setup-token</code></pre>
<h2 id="openclaw">OpenClaw</h2>
<pre><code># Auto-configure OpenClaw to use NadirClaw
nadirclaw openclaw onboard
# Start the router
nadirclaw serve</code></pre>
<p>This writes NadirClaw as a provider in <code>~/.openclaw/openclaw.json</code> with model <code>nadirclaw/auto</code>. OpenClaw auto-reloads automatically, no restart needed.</p>
<p>The generated config:</p>
<pre><code>{
"models": {
"providers": {
"nadirclaw": {
"baseUrl": "http://localhost:8856/v1",
"apiKey": "local",
"api": "openai-completions",
"models": [{ "id": "auto", "name": "auto" }]
}
}
},
"agents": {
"defaults": {
"model": { "primary": "nadirclaw/auto" }
}
}
}</code></pre>
<h2 id="codex">Codex</h2>
<pre><code># Auto-configure Codex
nadirclaw codex onboard
# Start the router
nadirclaw serve</code></pre>
<p>This writes <code>~/.codex/config.toml</code>:</p>
<pre><code>model_provider = "nadirclaw"
[model_providers.nadirclaw]
base_url = "http://localhost:8856/v1"
api_key = "local"</code></pre>
<h3>OpenAI OAuth</h3>
<pre><code># Use ChatGPT subscription instead of API key
nadirclaw auth openai login</code></pre>
<h2 id="continue">Continue</h2>
<pre><code># Auto-configure Continue
nadirclaw continue onboard</code></pre>
<p>This writes NadirClaw as a provider in <code>~/.continue/config.json</code>. Continue reads the config on startup.</p>
<h2 id="cursor">Cursor</h2>
<pre><code># Show setup instructions
nadirclaw cursor onboard</code></pre>
<p>In Cursor: <strong>Settings > Models > OpenAI API Key:</strong> <code>local</code>, <strong>Base URL:</strong> <code>http://localhost:8856/v1</code>. Select a model or use <code>auto</code>.</p>
<h2 id="open-webui">Open WebUI</h2>
<pre><code># Show setup instructions
nadirclaw openwebui onboard</code></pre>
<p>In Open WebUI: <strong>Admin Settings > Connections > OpenAI > Add Connection</strong>. Set URL to <code>http://localhost:8856/v1</code> and API Key to <code>local</code>. Open WebUI auto-discovers NadirClaw's routing profiles and tier models via <code>/v1/models</code>.</p>
<h2 id="openai-compatible">Any OpenAI-Compatible Client</h2>
<p>NadirClaw exposes a standard OpenAI-compatible API. Point any tool at it:</p>
<pre><code># Base URL: http://localhost:8856/v1
# Model: "auto" (or omit)
# API Key: "local" (or anything - auth disabled by default)</code></pre>
<h3>Python (openai SDK)</h3>
<pre><code>from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8856/v1",
api_key="local",
)
response = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "What is 2+2?"}],
)
print(response.choices[0].message.content)</code></pre>
<h3>curl</h3>
<pre><code>curl http://localhost:8856/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "What is 2+2?"}],
"stream": true
}'</code></pre>
<p>Works with <strong>Continue</strong>, <strong>Aider</strong>, <strong>Cursor</strong>, <strong>Windsurf</strong>, or any tool that speaks the OpenAI chat completions API. Just set the base URL to <code>http://localhost:8856/v1</code>.</p>
<h3>Custom Endpoints (vLLM, LocalAI, LM Studio)</h3>
<p>NadirClaw can route to any OpenAI-compatible endpoint:</p>
<pre><code>NADIRCLAW_API_BASE=http://your-server:8000/v1 \
NADIRCLAW_SIMPLE_MODEL=openai/your-small-model \
NADIRCLAW_COMPLEX_MODEL=openai/your-large-model \
nadirclaw serve --verbose</code></pre>
<!-- CLI COMMANDS -->
<h2 id="cli-commands">CLI Reference</h2>
<h3>nadirclaw serve</h3>
<p>Start the router server.</p>
<pre><code>nadirclaw serve [OPTIONS]
Options:
--port INTEGER Port (default: 8856)
--simple-model TEXT Model for simple prompts
--complex-model TEXT Model for complex prompts
--token TEXT Auth token
--verbose Debug logging
--log-raw Log full raw requests/responses to JSONL</code></pre>
<h3>nadirclaw setup</h3>
<p>Interactive setup wizard. Guides you through providers, API keys, and model selection.</p>
<pre><code>nadirclaw setup</code></pre>
<h3>nadirclaw classify</h3>
<p>Classify a prompt locally without running the server:</p>
<pre><code>$ nadirclaw classify "What is 2+2?"
Tier: simple
Confidence: 0.2848
Score: 0.0000
Model: gemini-3-flash-preview
$ nadirclaw classify "Design a distributed system for real-time trading"
Tier: complex
Confidence: 0.1843
Score: 1.0000
Model: gemini-2.5-pro</code></pre>
<h3>nadirclaw report</h3>
<p>Analyze request logs:</p>
<pre><code>nadirclaw report # full report
nadirclaw report --since 24h # last 24 hours
nadirclaw report --since 7d # last 7 days
nadirclaw report --model gemini # filter by model
nadirclaw report --format json # machine-readable JSON
nadirclaw report --export report.txt # save to file</code></pre>
<h3>nadirclaw savings</h3>
<p>Show cost savings with monthly projections:</p>
<pre><code>nadirclaw savings
nadirclaw savings --since 7d</code></pre>
<h3>nadirclaw dashboard</h3>
<p>Live terminal dashboard with real-time stats. Also available as web UI at <code>http://localhost:8856/dashboard</code>.</p>
<pre><code>pip install nadirclaw[dashboard]
nadirclaw dashboard</code></pre>
<h3>nadirclaw status</h3>
<p>Show current config, credentials, and server status:</p>
<pre><code>$ nadirclaw status
NadirClaw Status
----------------------------------------
Simple model: gemini-3-flash-preview
Complex model: gemini-2.5-pro
Port: 8856
Threshold: 0.06
Server: RUNNING (ok)</code></pre>
<h3>nadirclaw test</h3>
<p>Probe each configured model to verify credentials and connectivity. CI-friendly (exits 1 on failure):</p>
<pre><code>nadirclaw test
nadirclaw test --simple-model gemini-2.5-flash --complex-model gpt-4.1</code></pre>
<h3>nadirclaw export</h3>
<p>Export request logs for offline analysis:</p>
<pre><code>nadirclaw export --format csv --since 7d
nadirclaw export --format jsonl</code></pre>
<h3>nadirclaw budget</h3>
<p>Show real-time budget status and alerts:</p>
<pre><code>nadirclaw budget</code></pre>
<h3>Other Commands</h3>
<pre><code>nadirclaw auth add/status/remove # Manage credentials
nadirclaw auth openai login # OAuth login (ChatGPT subscription)
nadirclaw auth anthropic login # OAuth login (Claude subscription)
nadirclaw auth gemini login # OAuth login (Google Gemini)
nadirclaw auth setup-token # Store Claude subscription token
nadirclaw codex onboard # Configure Codex integration
nadirclaw openclaw onboard # Configure OpenClaw integration
nadirclaw continue onboard # Configure Continue integration
nadirclaw cursor onboard # Show Cursor setup instructions
nadirclaw openwebui onboard # Show Open WebUI setup
nadirclaw ollama discover # Auto-discover Ollama instances
nadirclaw ollama discover --scan-network # Network-wide scan
nadirclaw cache # View cache stats
nadirclaw build-centroids # Regenerate centroid vectors</code></pre>
<!-- BUDGET -->
<h2 id="budget">Budget & Cost Tracking</h2>
<p>NadirClaw tracks per-request costs in real time and supports budget limits with alerts.</p>
<h3>Setting Budgets</h3>
<pre><code># In ~/.nadirclaw/.env
NADIRCLAW_DAILY_BUDGET=10.00
NADIRCLAW_MONTHLY_BUDGET=200.00
NADIRCLAW_BUDGET_WARN_THRESHOLD=0.8 # Alert at 80% of budget</code></pre>
<h3>Alerts</h3>
<p>When spend crosses the warning threshold, NadirClaw can:</p>
<ul>
<li><strong>Webhook:</strong> POST a JSON payload to <code>NADIRCLAW_BUDGET_WEBHOOK_URL</code></li>
<li><strong>Stdout:</strong> Print alerts if <code>NADIRCLAW_BUDGET_STDOUT_ALERTS=true</code></li>
</ul>
<h3>Reporting</h3>
<pre><code># See savings
nadirclaw savings
# Detailed report with cost breakdown
nadirclaw report --since 7d
# Live monitoring
nadirclaw dashboard</code></pre>
<p>Reports include: total requests, tier distribution, per-model usage and tokens, latency percentiles (p50/p95), fallback counts, and error rates.</p>
<!-- PROMETHEUS -->
<h2 id="prometheus">Prometheus Metrics</h2>
<p>NadirClaw exposes a <code>/metrics</code> endpoint in Prometheus format with zero extra dependencies.</p>
<pre><code>curl http://localhost:8856/metrics</code></pre>