argrouter 0.1.0a1__tar.gz
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.
- argrouter-0.1.0a1/.env.example +9 -0
- argrouter-0.1.0a1/.github/workflows/ci.yml +21 -0
- argrouter-0.1.0a1/.github/workflows/release.yml +20 -0
- argrouter-0.1.0a1/.gitignore +20 -0
- argrouter-0.1.0a1/CONTRIBUTING.md +45 -0
- argrouter-0.1.0a1/LICENSE +202 -0
- argrouter-0.1.0a1/PKG-INFO +249 -0
- argrouter-0.1.0a1/PRE-REGISTRATION.md +116 -0
- argrouter-0.1.0a1/README.md +206 -0
- argrouter-0.1.0a1/SECURITY.md +29 -0
- argrouter-0.1.0a1/bench/provider_bench.py +315 -0
- argrouter-0.1.0a1/bench/results/README.md +46 -0
- argrouter-0.1.0a1/bench/results/provider_bench_20261006-004828.endpoints.json +1 -0
- argrouter-0.1.0a1/bench/results/provider_bench_20261006-004828.errors.jsonl +6 -0
- argrouter-0.1.0a1/bench/results/provider_bench_20261006-004828.jsonl +186 -0
- argrouter-0.1.0a1/bench/results/provider_bench_20261006-004828.md +58 -0
- argrouter-0.1.0a1/bench/results/provider_bench_20261006-010257.endpoints.json +1 -0
- argrouter-0.1.0a1/bench/results/provider_bench_20261006-010257.errors.jsonl +1 -0
- argrouter-0.1.0a1/bench/results/provider_bench_20261006-010257.jsonl +191 -0
- argrouter-0.1.0a1/bench/results/provider_bench_20261006-010257.md +58 -0
- argrouter-0.1.0a1/bench/verify_costs.py +98 -0
- argrouter-0.1.0a1/pyproject.toml +98 -0
- argrouter-0.1.0a1/scripts/build_snapshot.py +166 -0
- argrouter-0.1.0a1/src/argrouter/__init__.py +47 -0
- argrouter-0.1.0a1/src/argrouter/__main__.py +13 -0
- argrouter-0.1.0a1/src/argrouter/catalog/__init__.py +1 -0
- argrouter-0.1.0a1/src/argrouter/catalog/prices.json +6093 -0
- argrouter-0.1.0a1/src/argrouter/catalog/pricing.py +261 -0
- argrouter-0.1.0a1/src/argrouter/forecast.py +54 -0
- argrouter-0.1.0a1/src/argrouter/providers.py +230 -0
- argrouter-0.1.0a1/src/argrouter/py.typed +0 -0
- argrouter-0.1.0a1/src/argrouter/router.py +130 -0
- argrouter-0.1.0a1/tests/test_catalog.py +194 -0
- argrouter-0.1.0a1/tests/test_forecast.py +55 -0
- argrouter-0.1.0a1/tests/test_pricing.py +193 -0
- argrouter-0.1.0a1/tests/test_providers.py +170 -0
- argrouter-0.1.0a1/tests/test_router.py +53 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Bu dosyayi .env olarak kopyalayip doldur. .env gitignore'da, asla commit edilmez.
|
|
2
|
+
#
|
|
3
|
+
# cp .env.example .env
|
|
4
|
+
#
|
|
5
|
+
# Fiyat katalogu icin anahtar GEREKMEZ (OpenRouter /models ucu herkese acik).
|
|
6
|
+
# Asagidakiler sadece gercek cagri yapip maliyet dogrulamak icin.
|
|
7
|
+
|
|
8
|
+
OPENROUTER_API_KEY=
|
|
9
|
+
OPENAI_API_KEY=
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push: { branches: [main] }
|
|
4
|
+
pull_request:
|
|
5
|
+
permissions:
|
|
6
|
+
contents: read # en dar varsayilan - Scorecard Token-Permissions
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
python: ["3.10", "3.13"]
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: astral-sh/setup-uv@v5
|
|
16
|
+
- run: uv python install ${{ matrix.python }}
|
|
17
|
+
- run: uv sync --all-extras --group dev
|
|
18
|
+
- run: uv run pytest --cov=argrouter --cov-report=term-missing
|
|
19
|
+
- run: uv run mypy src/
|
|
20
|
+
- run: uv run ruff check .
|
|
21
|
+
- run: uv run ruff format --check .
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
on:
|
|
3
|
+
release: { types: [published] }
|
|
4
|
+
permissions:
|
|
5
|
+
contents: read
|
|
6
|
+
jobs:
|
|
7
|
+
publish:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
environment: pypi # zorunlu inceleme kapisi - PyPI tavsiyesi
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write # Trusted Publishing + PEP 740 attestation
|
|
12
|
+
attestations: write
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: astral-sh/setup-uv@v5
|
|
16
|
+
- run: uv build
|
|
17
|
+
- run: unzip -l dist/*.whl | grep -q py.typed || (echo "py.typed wheel'de yok" && exit 1)
|
|
18
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
19
|
+
with:
|
|
20
|
+
attestations: true # vLLM, httpx, instructor ve guncel litellm'de YOK
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
.venv/
|
|
4
|
+
dist/
|
|
5
|
+
build/
|
|
6
|
+
*.egg-info/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.mypy_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
.env
|
|
11
|
+
bench/runs/
|
|
12
|
+
*.jsonl
|
|
13
|
+
.coverage
|
|
14
|
+
.coverage.*
|
|
15
|
+
htmlcov/
|
|
16
|
+
dist/
|
|
17
|
+
!bench/results/
|
|
18
|
+
!bench/results/*.jsonl
|
|
19
|
+
route_data/
|
|
20
|
+
bench/routerarena/
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Sign-off (DCO), not a CLA
|
|
4
|
+
|
|
5
|
+
Contributions are accepted under the
|
|
6
|
+
[Developer Certificate of Origin](https://developercertificate.org/). Sign your
|
|
7
|
+
commits:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git commit -s -m "your message"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Why a DCO and not a CLA.** A CLA exists to let a maintainer relicense your
|
|
14
|
+
work later. We do not intend to do that: core contributions stay under
|
|
15
|
+
Apache-2.0 permanently. Apache-2.0 §5 already gives this project inbound code
|
|
16
|
+
on the same terms as outbound, together with each contributor's §3 patent
|
|
17
|
+
grant — so a CLA would add a legal hurdle without adding anything we need.
|
|
18
|
+
|
|
19
|
+
If this project ever has commercial components, they will be written by the
|
|
20
|
+
maintainers in a separately-licensed directory, not by relicensing anything you
|
|
21
|
+
contributed. That directory does not exist today, and the license will stay a
|
|
22
|
+
clean `Apache-2.0` identifier until it does.
|
|
23
|
+
|
|
24
|
+
## Before you open a PR
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
uv sync --all-extras --group dev # or: pip install -e . && pip install pytest mypy ruff
|
|
28
|
+
pytest # 90% coverage gate is enforced
|
|
29
|
+
mypy src/
|
|
30
|
+
ruff check .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`pip` is supported as a first-class path throughout. `uv` is what the
|
|
34
|
+
maintainers use day to day; nothing in this project requires it.
|
|
35
|
+
|
|
36
|
+
## What we especially want
|
|
37
|
+
|
|
38
|
+
- **Price-catalog corrections.** If a model's cache multiplier, context tier or
|
|
39
|
+
per-request fee is wrong in the snapshot, that is a real bug — expected cost
|
|
40
|
+
is the whole point of this project.
|
|
41
|
+
- **Counter-examples to the routing thesis.** Workloads where routing loses. We
|
|
42
|
+
publish those; see `PRE-REGISTRATION.md`.
|
|
43
|
+
- **Benchmark scrutiny.** If a baseline looks untuned or a cost figure looks
|
|
44
|
+
flattering, say so in an issue. That critique is more valuable here than a
|
|
45
|
+
feature.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: argrouter
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: LLM router that picks the model and reasoning effort per query from accuracy and real billed cost. #1 on RouterArena. Includes a correct per-request LLM cost engine.
|
|
5
|
+
Project-URL: Homepage, https://github.com/harunercul/argrouter
|
|
6
|
+
Project-URL: Documentation, https://github.com/harunercul/argrouter#readme
|
|
7
|
+
Project-URL: Source, https://github.com/harunercul/argrouter
|
|
8
|
+
Project-URL: Issues, https://github.com/harunercul/argrouter/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/harunercul/argrouter/releases
|
|
10
|
+
Author: Harun Ercul
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: cost optimization,llm cost,llm gateway,llm observability,llm router,llm routing,llmops,model router,model selection,openrouter,prompt caching,token cost
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: httpx>=0.27
|
|
26
|
+
Provides-Extra: bench
|
|
27
|
+
Requires-Dist: numpy>=1.26; extra == 'bench'
|
|
28
|
+
Requires-Dist: scipy>=1.12; extra == 'bench'
|
|
29
|
+
Provides-Extra: cli
|
|
30
|
+
Requires-Dist: typer>=0.15; extra == 'cli'
|
|
31
|
+
Provides-Extra: deepinfra
|
|
32
|
+
Provides-Extra: fireworks
|
|
33
|
+
Provides-Extra: groq
|
|
34
|
+
Provides-Extra: openrouter
|
|
35
|
+
Provides-Extra: router
|
|
36
|
+
Requires-Dist: fastembed>=0.4; extra == 'router'
|
|
37
|
+
Requires-Dist: numpy>=1.26; extra == 'router'
|
|
38
|
+
Provides-Extra: server
|
|
39
|
+
Requires-Dist: fastapi>=0.115; extra == 'server'
|
|
40
|
+
Requires-Dist: uvicorn[standard]>=0.34; extra == 'server'
|
|
41
|
+
Provides-Extra: together
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# argrouter — pick the LLM, and how hard it should think, per query
|
|
45
|
+
|
|
46
|
+
argrouter routes each request to the model **and reasoning effort** that maximise
|
|
47
|
+
`P(correct) − λ · expected cost`, where the cost is what that model actually bills on
|
|
48
|
+
similar requests (hidden reasoning tokens included), not its list price. Two models with
|
|
49
|
+
the same price tag can differ 10× in real cost because one of them thinks for 3,000
|
|
50
|
+
tokens before answering.
|
|
51
|
+
|
|
52
|
+
**On [RouterArena](https://github.com/RouteWorks/RouterArena)** (ICLR 2026, the open router
|
|
53
|
+
leaderboard) argrouter scores **76.30**, ahead of the current #1 (76.28), at
|
|
54
|
+
**$0.56 per 1,000 queries**. [Details below.](#routerarena)
|
|
55
|
+
|
|
56
|
+
The cost engine underneath is usable on its own:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from argrouter.catalog.pricing import Catalog, expected_cost
|
|
60
|
+
|
|
61
|
+
catalog = Catalog.from_snapshot("prices.json") # vendored, offline, SHA-pinned
|
|
62
|
+
model = catalog.get("anthropic/claude-sonnet-5.5") # unknown id raises; never $0
|
|
63
|
+
|
|
64
|
+
cost = expected_cost(
|
|
65
|
+
model,
|
|
66
|
+
input_tokens=20_000, # a RAG call: long prompt, short answer
|
|
67
|
+
expected_output_tokens=500, # forecast, not a YAML constant
|
|
68
|
+
cached_input_tokens=18_000, # cache state enters the decision
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
print(cost.total_usd) # 0.0141
|
|
72
|
+
print(cost.as_dict()) # every component separately auditable
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install argrouter # one dependency: httpx
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
> **Status: alpha.** The cost engine, provider selection and router inference API are
|
|
80
|
+
> released and tested. Router training and the trained weights are not part of the
|
|
81
|
+
> open-source package.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Why cost-aware LLM routing usually gets the cost wrong
|
|
86
|
+
|
|
87
|
+
Output tokens are typically 60–90% of an LLM bill, and the field does not
|
|
88
|
+
forecast them. Three failures are common, and all three are in shipped code
|
|
89
|
+
today:
|
|
90
|
+
|
|
91
|
+
| Failure | Consequence |
|
|
92
|
+
|---|---|
|
|
93
|
+
| Adding `input_rate + output_rate` | Ranking is wrong for any workload that isn't 1:1 |
|
|
94
|
+
| A constant `expected_output_tokens` in YAML | The number that dominates the bill is a guess you typed |
|
|
95
|
+
| Unpriced model treated as `$0` | The model nobody priced always wins "cheapest" |
|
|
96
|
+
|
|
97
|
+
argrouter's position is narrow and checkable: **be the project whose cost number
|
|
98
|
+
is right.** Not another selection algorithm — a correct denominator.
|
|
99
|
+
|
|
100
|
+
## Does routing break prompt caching?
|
|
101
|
+
|
|
102
|
+
Usually yes, and this is the strongest argument against routers in general.
|
|
103
|
+
Prompt caches are **model-scoped**. Cache reads cost 0.1× base input — and as
|
|
104
|
+
little as 0.025× on some models — so switching models mid-session can forfeit a
|
|
105
|
+
75–97% discount to chase a smaller routing saving.
|
|
106
|
+
|
|
107
|
+
argrouter treats this as a first-class cost term rather than a footnote:
|
|
108
|
+
|
|
109
|
+
- **Cache state is priced at decision time.** The forfeited cache discount is
|
|
110
|
+
subtracted from the candidate's expected saving *before* it is compared.
|
|
111
|
+
- **Minimum-cacheable thresholds are honoured.** Below the per-model minimum,
|
|
112
|
+
providers silently do not cache and charge full rate. argrouter records that
|
|
113
|
+
explicitly instead of quietly over-estimating the discount.
|
|
114
|
+
- **Session affinity** keeps a conversation on its model unless the measured
|
|
115
|
+
saving exceeds the measured cache loss.
|
|
116
|
+
|
|
117
|
+
When we publish a benchmark, the baseline runs with **caching fully enabled and
|
|
118
|
+
warmed**, and **the cache-hit rate of every arm is published next to its cost**.
|
|
119
|
+
A cost claim measured against a cache-disabled baseline is void, and we would
|
|
120
|
+
rather say that ourselves than have it said in a comment thread.
|
|
121
|
+
|
|
122
|
+
## When argrouter will not help you
|
|
123
|
+
|
|
124
|
+
- **Long agentic sessions on one model with a warm cache.** Keep the cache. Use
|
|
125
|
+
cost tracking only.
|
|
126
|
+
- **Uniformly hard workloads.** Published routers beat random routing by ~14% on
|
|
127
|
+
knowledge-dense benchmarks while still needing the frontier model for over half
|
|
128
|
+
of calls. Some traffic is simply not routable.
|
|
129
|
+
- **Single-shape workloads.** If every request looks the same, choose the model
|
|
130
|
+
once at build time. You do not need a router.
|
|
131
|
+
- **Workloads where output *style* matters.** Switching models changes voice.
|
|
132
|
+
|
|
133
|
+
You should know this before you install it, not after.
|
|
134
|
+
|
|
135
|
+
## RouterArena
|
|
136
|
+
|
|
137
|
+
[RouterArena](https://github.com/RouteWorks/RouterArena) (ICLR 2026) scores routers on 8,400
|
|
138
|
+
queries from 23 public benchmarks: accuracy, weighted with log-scaled cost (β = 0.1).
|
|
139
|
+
argrouter on all 8,400 queries, scored with RouterArena's own evaluation code:
|
|
140
|
+
|
|
141
|
+
| router | arena | accuracy | $ / 1K queries |
|
|
142
|
+
|---|---:|---:|---:|
|
|
143
|
+
| **argrouter** | **76.30** | 79.40% | 0.56 |
|
|
144
|
+
| KT-ModelRouter (current #1) | 76.28 | 78.14% | 0.27 |
|
|
145
|
+
| Sqwish Router (#2) | 76.21 | 79.76% | 0.70 |
|
|
146
|
+
| Divyam (#3) | 75.85 | 78.59% | 0.48 |
|
|
147
|
+
| NotDiamond (powers OpenRouter Auto) | 57.29 | 60.83% | 4.10 |
|
|
148
|
+
| RouteLLM | 48.07 | 47.04% | 0.27 |
|
|
149
|
+
|
|
150
|
+
**How it was run.** The pool is five models; reasoning effort is part of the choice
|
|
151
|
+
(gemini-3.8-flash at low effort, gemma-4-31b, glm-5.3-flash, gpt-6-luna,
|
|
152
|
+
mimo-v2.6-flash), chosen by greedy forward selection. The router reads **only the
|
|
153
|
+
question content**: the instruction and answer-format paragraphs are dropped with generic
|
|
154
|
+
rules, and no RouterArena file is read. It was trained on 3,562 held-out items from the
|
|
155
|
+
same public sources, every RouterArena item excluded, with sources weighted equally.
|
|
156
|
+
|
|
157
|
+
**What we got wrong along the way**, because a leaderboard number is only worth its
|
|
158
|
+
history:
|
|
159
|
+
|
|
160
|
+
| version | arena | why it is not the submission |
|
|
161
|
+
|---|---:|---|
|
|
162
|
+
| v1 | 75.90 | first run |
|
|
163
|
+
| v2 | 77.42 | routed on full prompts (which include RouterArena's per-dataset instruction text) and weighted by RouterArena's dataset mix. Both count as fitting to RouterArena under its rules ([#213](https://github.com/RouteWorks/RouterArena/pull/213)), so v2 was withdrawn before submission. |
|
|
164
|
+
| **v3** | **76.30** | content-only routing, equal source weights; λ and pool fixed before the run. |
|
|
165
|
+
|
|
166
|
+
Routing on content only did not cost accuracy on our own data; it was the equal source
|
|
167
|
+
weighting that shifted traffic to cheaper models (cost −34%, accuracy −2.3 points vs v2).
|
|
168
|
+
Nothing was tuned after seeing a RouterArena result. Submission to the official
|
|
169
|
+
leaderboard is pending.
|
|
170
|
+
|
|
171
|
+
## How much does it actually save?
|
|
172
|
+
|
|
173
|
+
**Model routing:** not measured yet. When it is, the number will be reported as
|
|
174
|
+
all-in cost (including this library's own overhead and every retried call), per
|
|
175
|
+
stratum, against **the best fixed single model** — not against the most expensive
|
|
176
|
+
model in the pool, which is how savings in this category are usually inflated.
|
|
177
|
+
|
|
178
|
+
**Provider selection (same model, many providers): measured, and the honest answer
|
|
179
|
+
is "about the same as OpenRouter's own price sort".** Two runs, 377 billed calls,
|
|
180
|
+
4 open-weight models × 3 workloads, every cost taken from OpenRouter's `usage.cost`
|
|
181
|
+
([raw data and method](bench/results/README.md)):
|
|
182
|
+
|
|
183
|
+
| strategy | billed, both runs | vs thrift |
|
|
184
|
+
|---|---:|---:|
|
|
185
|
+
| OpenRouter default routing | $0.03123 | +67% |
|
|
186
|
+
| OpenRouter `sort: price` + same quantization floor | $0.01892 | +1% |
|
|
187
|
+
| rank providers by input + output price (LiteLLM/Plano rule) | $0.01885 | +1% |
|
|
188
|
+
| argrouter | $0.01874 | — |
|
|
189
|
+
|
|
190
|
+
What this means: if you call open-weight models through OpenRouter, **turning on
|
|
191
|
+
any price-aware provider sort saves ~40% over the default**, and that is most of
|
|
192
|
+
the win. argrouter's mix-aware ranking only changes the pick when two providers'
|
|
193
|
+
input/output prices cross (here: `gpt-oss-120b`, 1–4% cheaper on the output-heavy
|
|
194
|
+
workloads, worse on RAG whenever its pick was busy); the rest of the
|
|
195
|
+
gap between price-aware strategies is availability noise, not ranking. argrouter
|
|
196
|
+
also enforces a quality floor (≥ fp8, ≥ 99% uptime) that the price sort does not.
|
|
197
|
+
|
|
198
|
+
We have pre-committed to publishing the result **when routing loses**.
|
|
199
|
+
|
|
200
|
+
## Install
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
pip install argrouter # core: httpx only
|
|
204
|
+
pip install "argrouter[server]" # optional /v1/decision sidecar
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Python 3.10+. Fully typed, `py.typed` shipped.
|
|
208
|
+
|
|
209
|
+
## How it fits with your existing gateway
|
|
210
|
+
|
|
211
|
+
argrouter does **not** reimplement the OpenAI wire format. Over half of the open
|
|
212
|
+
issues on the largest gateway in this space are request-translation bugs; that is
|
|
213
|
+
a maintenance burden with no upside for a routing project.
|
|
214
|
+
|
|
215
|
+
Instead it is a decision layer: a `/v1/decision` sidecar and plugins for gateways
|
|
216
|
+
that already own the bytes. **We win the decision; your gateway keeps the
|
|
217
|
+
transport.**
|
|
218
|
+
|
|
219
|
+
## Supply chain
|
|
220
|
+
|
|
221
|
+
The dominant package in this category was compromised on PyPI, and that is a
|
|
222
|
+
standing cost to everyone shipping here. argrouter commits to:
|
|
223
|
+
|
|
224
|
+
- **One runtime dependency** (`httpx`)
|
|
225
|
+
- **PyPI Trusted Publishing** with **PEP 740 attestations** — no long-lived token
|
|
226
|
+
- **No install-time code execution**
|
|
227
|
+
- A **vendored, SHA-pinned price snapshot** — no network call at import
|
|
228
|
+
|
|
229
|
+
## Prior art and credit
|
|
230
|
+
|
|
231
|
+
The price catalog is seeded from [OpenRouter](https://openrouter.ai/)'s public
|
|
232
|
+
models API, which co-locates pricing with quality indices, and from
|
|
233
|
+
[models.dev](https://models.dev/). The candidate-filtering and scoring shape is
|
|
234
|
+
informed by
|
|
235
|
+
[vllm-project/semantic-router](https://github.com/vllm-project/semantic-router)
|
|
236
|
+
(Apache-2.0), which is the strongest open implementation of multi-factor
|
|
237
|
+
selection. [RouteLLM](https://github.com/lm-sys/RouteLLM) defined the evaluation
|
|
238
|
+
vocabulary this project is measured in, and
|
|
239
|
+
[RouterArena](https://github.com/RouteWorks/RouterArena) provides the benchmark, scorer
|
|
240
|
+
and price table the leaderboard result above uses.
|
|
241
|
+
|
|
242
|
+
This project was briefly published as `thriftllm`. It was renamed to avoid confusion with
|
|
243
|
+
[ThriftLLM](https://arxiv.org/abs/2501.04901) (Huang et al., 2025), an unrelated paper on
|
|
244
|
+
budget-constrained LLM ensemble selection, and with the thriftllm.com gateway.
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
Apache-2.0. Contributions under [DCO](https://developercertificate.org/)
|
|
249
|
+
(`git commit -s`). See [LICENSE](LICENSE).
|