tokeven 0.1.0__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.
- tokeven-0.1.0/LICENSE +27 -0
- tokeven-0.1.0/PKG-INFO +233 -0
- tokeven-0.1.0/README.md +170 -0
- tokeven-0.1.0/pyproject.toml +88 -0
- tokeven-0.1.0/setup.cfg +4 -0
- tokeven-0.1.0/src/tokeven/__init__.py +112 -0
- tokeven-0.1.0/src/tokeven/_base.py +118 -0
- tokeven-0.1.0/src/tokeven/_model_registry_generated.py +297 -0
- tokeven-0.1.0/src/tokeven/advisor.py +873 -0
- tokeven-0.1.0/src/tokeven/cli.py +282 -0
- tokeven-0.1.0/src/tokeven/client.py +865 -0
- tokeven-0.1.0/src/tokeven/config.py +203 -0
- tokeven-0.1.0/src/tokeven/efficiency.py +393 -0
- tokeven-0.1.0/src/tokeven/emitter.py +496 -0
- tokeven-0.1.0/src/tokeven/entitlements.py +76 -0
- tokeven-0.1.0/src/tokeven/gemini_client.py +462 -0
- tokeven-0.1.0/src/tokeven/guardrails.py +437 -0
- tokeven-0.1.0/src/tokeven/mcp_server.py +287 -0
- tokeven-0.1.0/src/tokeven/openai_client.py +839 -0
- tokeven-0.1.0/src/tokeven/proxy/__init__.py +28 -0
- tokeven-0.1.0/src/tokeven/proxy/app.py +463 -0
- tokeven-0.1.0/src/tokeven/proxy/config.py +68 -0
- tokeven-0.1.0/src/tokeven/proxy/emitter.py +348 -0
- tokeven-0.1.0/src/tokeven/proxy/main.py +54 -0
- tokeven-0.1.0/src/tokeven/proxy/providers/__init__.py +17 -0
- tokeven-0.1.0/src/tokeven/proxy/providers/anthropic.py +96 -0
- tokeven-0.1.0/src/tokeven/proxy/providers/base.py +94 -0
- tokeven-0.1.0/src/tokeven/proxy/providers/google.py +149 -0
- tokeven-0.1.0/src/tokeven/proxy/providers/openai.py +196 -0
- tokeven-0.1.0/src/tokeven/proxy/router.py +55 -0
- tokeven-0.1.0/src/tokeven/proxy/sanitize.py +16 -0
- tokeven-0.1.0/src/tokeven/py.typed +0 -0
- tokeven-0.1.0/src/tokeven/registry.py +101 -0
- tokeven-0.1.0/src/tokeven/widget/__init__.py +19 -0
- tokeven-0.1.0/src/tokeven/widget/api.py +149 -0
- tokeven-0.1.0/src/tokeven/widget/cli.py +121 -0
- tokeven-0.1.0/src/tokeven/widget/config.py +79 -0
- tokeven-0.1.0/src/tokeven/widget/render.py +58 -0
- tokeven-0.1.0/src/tokeven.egg-info/PKG-INFO +233 -0
- tokeven-0.1.0/src/tokeven.egg-info/SOURCES.txt +55 -0
- tokeven-0.1.0/src/tokeven.egg-info/dependency_links.txt +1 -0
- tokeven-0.1.0/src/tokeven.egg-info/entry_points.txt +5 -0
- tokeven-0.1.0/src/tokeven.egg-info/requires.txt +42 -0
- tokeven-0.1.0/src/tokeven.egg-info/top_level.txt +1 -0
- tokeven-0.1.0/tests/test_advisor.py +1111 -0
- tokeven-0.1.0/tests/test_client.py +784 -0
- tokeven-0.1.0/tests/test_config.py +171 -0
- tokeven-0.1.0/tests/test_efficiency.py +203 -0
- tokeven-0.1.0/tests/test_emitter.py +379 -0
- tokeven-0.1.0/tests/test_gemini_client.py +538 -0
- tokeven-0.1.0/tests/test_guardrails.py +326 -0
- tokeven-0.1.0/tests/test_improve.py +239 -0
- tokeven-0.1.0/tests/test_mcp_server.py +135 -0
- tokeven-0.1.0/tests/test_openai_client.py +1068 -0
- tokeven-0.1.0/tests/test_registry_sync.py +114 -0
- tokeven-0.1.0/tests/test_session_id_propagation.py +188 -0
- tokeven-0.1.0/tests/test_wrap_dispatch.py +97 -0
tokeven-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Tokeven Client Software License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tokeven. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is granted to any person obtaining a copy of this software to install,
|
|
6
|
+
execute, and use it for the purpose of instrumenting their own applications and
|
|
7
|
+
reporting usage metrics to the Tokeven service.
|
|
8
|
+
|
|
9
|
+
The following are not permitted without prior written permission from Tokeven:
|
|
10
|
+
|
|
11
|
+
1. Redistribution of this software, in source or binary form, whether modified
|
|
12
|
+
or unmodified.
|
|
13
|
+
2. Modification, adaptation, reverse engineering, decompilation, or disassembly
|
|
14
|
+
of this software, except to the extent that applicable law expressly permits
|
|
15
|
+
it despite this limitation.
|
|
16
|
+
3. Use of this software to build or operate a product that competes with the
|
|
17
|
+
Tokeven service.
|
|
18
|
+
4. Sublicensing, sale, rental, lease, or transfer of this software.
|
|
19
|
+
|
|
20
|
+
This software is provided "as is", without warranty of any kind, express or
|
|
21
|
+
implied, including but not limited to the warranties of merchantability, fitness
|
|
22
|
+
for a particular purpose, and noninfringement. In no event shall the authors or
|
|
23
|
+
copyright holders be liable for any claim, damages, or other liability, whether
|
|
24
|
+
in an action of contract, tort, or otherwise, arising from, out of, or in
|
|
25
|
+
connection with the software or the use or other dealings in the software.
|
|
26
|
+
|
|
27
|
+
Questions about licensing: team@tokeven.com
|
tokeven-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tokeven
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Privacy first cost visibility for Claude, ChatGPT, and Gemini API calls. Metrics only, and your provider keys and prompts stay on your machine.
|
|
5
|
+
Author-email: Tokeven <team@tokeven.com>
|
|
6
|
+
Maintainer-email: Tokeven <team@tokeven.com>
|
|
7
|
+
License-Expression: LicenseRef-Tokeven-Proprietary
|
|
8
|
+
Project-URL: Homepage, https://tokeven.com
|
|
9
|
+
Project-URL: Documentation, https://tokeven.com/docs
|
|
10
|
+
Project-URL: Pricing, https://tokeven.com/pricing
|
|
11
|
+
Project-URL: Privacy, https://tokeven.com/privacy
|
|
12
|
+
Project-URL: Security, https://tokeven.com/security
|
|
13
|
+
Project-URL: Changelog, https://tokeven.com/docs#changelog
|
|
14
|
+
Keywords: anthropic,claude,openai,gemini,llm,cost,observability,tokens,finops,mcp
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: System :: Monitoring
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: httpx>=0.24
|
|
29
|
+
Provides-Extra: anthropic
|
|
30
|
+
Requires-Dist: anthropic>=0.40; extra == "anthropic"
|
|
31
|
+
Provides-Extra: openai
|
|
32
|
+
Requires-Dist: openai>=1.0; extra == "openai"
|
|
33
|
+
Provides-Extra: google-genai
|
|
34
|
+
Requires-Dist: google-genai>=1.0; extra == "google-genai"
|
|
35
|
+
Provides-Extra: requests
|
|
36
|
+
Requires-Dist: requests>=2.28; extra == "requests"
|
|
37
|
+
Provides-Extra: mcp
|
|
38
|
+
Requires-Dist: mcp>=1.0; extra == "mcp"
|
|
39
|
+
Provides-Extra: proxy
|
|
40
|
+
Requires-Dist: starlette>=0.37; extra == "proxy"
|
|
41
|
+
Requires-Dist: uvicorn>=0.29; extra == "proxy"
|
|
42
|
+
Requires-Dist: pydantic-settings>=2.2; extra == "proxy"
|
|
43
|
+
Provides-Extra: all
|
|
44
|
+
Requires-Dist: anthropic>=0.40; extra == "all"
|
|
45
|
+
Requires-Dist: openai>=1.0; extra == "all"
|
|
46
|
+
Requires-Dist: google-genai>=1.0; extra == "all"
|
|
47
|
+
Requires-Dist: mcp>=1.0; extra == "all"
|
|
48
|
+
Requires-Dist: starlette>=0.37; extra == "all"
|
|
49
|
+
Requires-Dist: uvicorn>=0.29; extra == "all"
|
|
50
|
+
Requires-Dist: pydantic-settings>=2.2; extra == "all"
|
|
51
|
+
Provides-Extra: dev
|
|
52
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
53
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
54
|
+
Requires-Dist: httpx>=0.24; extra == "dev"
|
|
55
|
+
Requires-Dist: anthropic>=0.40; extra == "dev"
|
|
56
|
+
Requires-Dist: openai>=1.0; extra == "dev"
|
|
57
|
+
Requires-Dist: google-genai>=1.0; extra == "dev"
|
|
58
|
+
Requires-Dist: mcp>=1.0; extra == "dev"
|
|
59
|
+
Requires-Dist: starlette>=0.37; extra == "dev"
|
|
60
|
+
Requires-Dist: uvicorn>=0.29; extra == "dev"
|
|
61
|
+
Requires-Dist: pydantic-settings>=2.2; extra == "dev"
|
|
62
|
+
Dynamic: license-file
|
|
63
|
+
|
|
64
|
+
# tokeven
|
|
65
|
+
|
|
66
|
+
Per prompt cost visibility for the Claude, OpenAI, and Google SDKs, without
|
|
67
|
+
Tokeven ever holding a provider key or seeing a prompt.
|
|
68
|
+
|
|
69
|
+
`tokeven` wraps the official provider SDKs. Your call goes to the provider
|
|
70
|
+
exactly as before, and the wrapper reads the `usage` block off the response and
|
|
71
|
+
pushes a small metrics event to your Tokeven dashboard. It also answers the
|
|
72
|
+
question that saves the most money, which is what a call is about to cost before
|
|
73
|
+
you send it.
|
|
74
|
+
|
|
75
|
+
- Website: https://tokeven.com
|
|
76
|
+
- Documentation: https://tokeven.com/docs
|
|
77
|
+
- Pricing: https://tokeven.com/pricing
|
|
78
|
+
- Free teardown tool, no account needed: https://tokeven.com/teardown
|
|
79
|
+
|
|
80
|
+
## What it does
|
|
81
|
+
|
|
82
|
+
- Estimates cost and confidence across all three providers before you send a
|
|
83
|
+
call, so model choice is an informed decision rather than a default.
|
|
84
|
+
- Records what each call actually cost, with cache aware pricing recomputed
|
|
85
|
+
server side.
|
|
86
|
+
- Runs as an MCP server, so Claude Code can ask for an estimate directly.
|
|
87
|
+
- Ships a live cost widget for your shell prompt or status line, and a self
|
|
88
|
+
hosted sidecar for capturing usage without an SDK wrapper.
|
|
89
|
+
- Suggests cheaper models and prompt level efficiency improvements, and always
|
|
90
|
+
leaves the decision to you. Nothing is rerouted silently.
|
|
91
|
+
|
|
92
|
+
## Privacy
|
|
93
|
+
|
|
94
|
+
- Tokeven receives token counts and metadata such as model, latency, and a
|
|
95
|
+
character count computed locally. Prompt and completion content never reaches
|
|
96
|
+
Tokeven through this pipeline.
|
|
97
|
+
- Every outgoing event passes a strict key allowlist, so content cannot be
|
|
98
|
+
transmitted by accident.
|
|
99
|
+
- Authentication to Tokeven uses a write only ingest token, which cannot read
|
|
100
|
+
your data or manage your account. It is not a provider key, and Tokeven never
|
|
101
|
+
asks for one.
|
|
102
|
+
- Two features are opt in exceptions that do send prompt text you explicitly hand
|
|
103
|
+
them, because rewriting a prompt requires reading it: the prompt revision tool
|
|
104
|
+
on the website and `advisor.improve()`. Both are disclosed at the point of use.
|
|
105
|
+
Details at https://tokeven.com/privacy
|
|
106
|
+
- If any part of the instrumentation fails, your provider call is returned
|
|
107
|
+
unchanged. Tokeven is designed not to break your application.
|
|
108
|
+
|
|
109
|
+
## Install
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install tokeven # wrapper, advisor, CLI, widget
|
|
113
|
+
pip install "tokeven[anthropic]" # with the Anthropic SDK
|
|
114
|
+
pip install "tokeven[openai]" # with the OpenAI SDK
|
|
115
|
+
pip install "tokeven[google-genai]" # with the Google SDK
|
|
116
|
+
pip install "tokeven[mcp]" # with the MCP server
|
|
117
|
+
pip install "tokeven[proxy]" # with the self hosted sidecar
|
|
118
|
+
pip install "tokeven[all]" # everything
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
For the command line tools on their own, without touching a project environment:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pipx install tokeven
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Quickstart
|
|
128
|
+
|
|
129
|
+
Wrap your existing provider client. Configuration is read from the environment:
|
|
130
|
+
`TOKEVEN_INGEST_TOKEN`, `TOKEVEN_BASE_URL`, `TOKEVEN_PROJECT`, `TOKEVEN_MODE`.
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from anthropic import Anthropic
|
|
134
|
+
from tokeven import TokevenAnthropic
|
|
135
|
+
|
|
136
|
+
client = TokevenAnthropic(Anthropic(), project="billing-agent")
|
|
137
|
+
|
|
138
|
+
resp = client.messages.create(
|
|
139
|
+
model="claude-sonnet-4-6",
|
|
140
|
+
max_tokens=512,
|
|
141
|
+
messages=[{"role": "user", "content": "Hello"}],
|
|
142
|
+
)
|
|
143
|
+
print(resp.content) # unchanged Anthropic response
|
|
144
|
+
|
|
145
|
+
client.flush() # optional: force-push buffered events before exit
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`TokevenOpenAI` and `TokevenGemini` wrap the OpenAI and Google SDKs the same way.
|
|
149
|
+
|
|
150
|
+
## First run
|
|
151
|
+
|
|
152
|
+
Set your write only ingest token:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
export TOKEVEN_INGEST_TOKEN="tkv_ing_..."
|
|
156
|
+
export TOKEVEN_BASE_URL="https://api.tokeven.com"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Create a token at https://tokeven.com/settings
|
|
160
|
+
|
|
161
|
+
Estimate the cost of a call before you send it:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
tokeven estimate --model claude-opus-4-8 "your prompt here"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The estimate runs entirely on your machine and needs no account at all.
|
|
168
|
+
|
|
169
|
+
## The sidecar (optional)
|
|
170
|
+
|
|
171
|
+
If you would rather not wrap an SDK, run the self hosted sidecar and point your
|
|
172
|
+
provider base URL at it. It forwards every request to the provider verbatim and
|
|
173
|
+
captures usage on a fail open side channel. Provider keys and prompt content
|
|
174
|
+
never reach Tokeven.
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
pip install "tokeven[proxy]"
|
|
178
|
+
tokeven-proxy
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
A container image and an example `docker-compose.yml` ship alongside this package.
|
|
182
|
+
|
|
183
|
+
## The live cost widget (optional)
|
|
184
|
+
|
|
185
|
+
A one line spend gauge for your shell prompt, tmux, or editor status line. It
|
|
186
|
+
reuses your dashboard login, never an ingest token or a provider key.
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
tokeven-widget # print one status line and exit
|
|
190
|
+
tokeven-widget watch # poll and reprint on an interval
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## What is and is not tracked
|
|
194
|
+
|
|
195
|
+
Tokeven sees the traffic you instrument. Calls made through the provider
|
|
196
|
+
consoles, through the Anthropic Workbench, or from applications you have not
|
|
197
|
+
wrapped will not appear on the dashboard.
|
|
198
|
+
|
|
199
|
+
## Free and paid
|
|
200
|
+
|
|
201
|
+
Everything this package does on your machine is free, and there is no trial clock
|
|
202
|
+
on it. That includes pre send cost estimates, the model picker, efficiency
|
|
203
|
+
suggestions, the MCP server, the sidecar, and the live cost widget. A free
|
|
204
|
+
Tokeven account adds a dashboard covering 1,000 tracked calls per month.
|
|
205
|
+
|
|
206
|
+
The paid tier is priced as gainshare. Tokeven earns 10 percent of verified
|
|
207
|
+
savings, measured per call against live token prices rather than a frozen
|
|
208
|
+
baseline, and you keep the other 90 percent. If you save nothing, you pay
|
|
209
|
+
nothing, and the fee falls automatically when model prices fall. There is no per
|
|
210
|
+
seat charge.
|
|
211
|
+
|
|
212
|
+
Paid adds:
|
|
213
|
+
|
|
214
|
+
- Unlimited tracked calls
|
|
215
|
+
- Prompt revision suggestions
|
|
216
|
+
- Organization wide savings dashboard and per person savings tracking
|
|
217
|
+
- Analytics across all three providers
|
|
218
|
+
- Embeddable widgets
|
|
219
|
+
- n8n and webhook integrations
|
|
220
|
+
- CSV, JSON, and API export
|
|
221
|
+
|
|
222
|
+
Enterprise terms, including capped arrangements for teams that budget fixed line
|
|
223
|
+
items, SSO, and custom retention, are handled case by case.
|
|
224
|
+
|
|
225
|
+
If you are weighing the paid tier or want a hand sizing what you would actually
|
|
226
|
+
save, email team@tokeven.com. We are happy to look at your numbers with you, and
|
|
227
|
+
there is no obligation attached to asking. Full pricing detail is at
|
|
228
|
+
https://tokeven.com/pricing
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
Proprietary. The full terms ship in the `LICENSE` file bundled with this
|
|
233
|
+
package. Questions: team@tokeven.com
|
tokeven-0.1.0/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# tokeven
|
|
2
|
+
|
|
3
|
+
Per prompt cost visibility for the Claude, OpenAI, and Google SDKs, without
|
|
4
|
+
Tokeven ever holding a provider key or seeing a prompt.
|
|
5
|
+
|
|
6
|
+
`tokeven` wraps the official provider SDKs. Your call goes to the provider
|
|
7
|
+
exactly as before, and the wrapper reads the `usage` block off the response and
|
|
8
|
+
pushes a small metrics event to your Tokeven dashboard. It also answers the
|
|
9
|
+
question that saves the most money, which is what a call is about to cost before
|
|
10
|
+
you send it.
|
|
11
|
+
|
|
12
|
+
- Website: https://tokeven.com
|
|
13
|
+
- Documentation: https://tokeven.com/docs
|
|
14
|
+
- Pricing: https://tokeven.com/pricing
|
|
15
|
+
- Free teardown tool, no account needed: https://tokeven.com/teardown
|
|
16
|
+
|
|
17
|
+
## What it does
|
|
18
|
+
|
|
19
|
+
- Estimates cost and confidence across all three providers before you send a
|
|
20
|
+
call, so model choice is an informed decision rather than a default.
|
|
21
|
+
- Records what each call actually cost, with cache aware pricing recomputed
|
|
22
|
+
server side.
|
|
23
|
+
- Runs as an MCP server, so Claude Code can ask for an estimate directly.
|
|
24
|
+
- Ships a live cost widget for your shell prompt or status line, and a self
|
|
25
|
+
hosted sidecar for capturing usage without an SDK wrapper.
|
|
26
|
+
- Suggests cheaper models and prompt level efficiency improvements, and always
|
|
27
|
+
leaves the decision to you. Nothing is rerouted silently.
|
|
28
|
+
|
|
29
|
+
## Privacy
|
|
30
|
+
|
|
31
|
+
- Tokeven receives token counts and metadata such as model, latency, and a
|
|
32
|
+
character count computed locally. Prompt and completion content never reaches
|
|
33
|
+
Tokeven through this pipeline.
|
|
34
|
+
- Every outgoing event passes a strict key allowlist, so content cannot be
|
|
35
|
+
transmitted by accident.
|
|
36
|
+
- Authentication to Tokeven uses a write only ingest token, which cannot read
|
|
37
|
+
your data or manage your account. It is not a provider key, and Tokeven never
|
|
38
|
+
asks for one.
|
|
39
|
+
- Two features are opt in exceptions that do send prompt text you explicitly hand
|
|
40
|
+
them, because rewriting a prompt requires reading it: the prompt revision tool
|
|
41
|
+
on the website and `advisor.improve()`. Both are disclosed at the point of use.
|
|
42
|
+
Details at https://tokeven.com/privacy
|
|
43
|
+
- If any part of the instrumentation fails, your provider call is returned
|
|
44
|
+
unchanged. Tokeven is designed not to break your application.
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install tokeven # wrapper, advisor, CLI, widget
|
|
50
|
+
pip install "tokeven[anthropic]" # with the Anthropic SDK
|
|
51
|
+
pip install "tokeven[openai]" # with the OpenAI SDK
|
|
52
|
+
pip install "tokeven[google-genai]" # with the Google SDK
|
|
53
|
+
pip install "tokeven[mcp]" # with the MCP server
|
|
54
|
+
pip install "tokeven[proxy]" # with the self hosted sidecar
|
|
55
|
+
pip install "tokeven[all]" # everything
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
For the command line tools on their own, without touching a project environment:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pipx install tokeven
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Quickstart
|
|
65
|
+
|
|
66
|
+
Wrap your existing provider client. Configuration is read from the environment:
|
|
67
|
+
`TOKEVEN_INGEST_TOKEN`, `TOKEVEN_BASE_URL`, `TOKEVEN_PROJECT`, `TOKEVEN_MODE`.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from anthropic import Anthropic
|
|
71
|
+
from tokeven import TokevenAnthropic
|
|
72
|
+
|
|
73
|
+
client = TokevenAnthropic(Anthropic(), project="billing-agent")
|
|
74
|
+
|
|
75
|
+
resp = client.messages.create(
|
|
76
|
+
model="claude-sonnet-4-6",
|
|
77
|
+
max_tokens=512,
|
|
78
|
+
messages=[{"role": "user", "content": "Hello"}],
|
|
79
|
+
)
|
|
80
|
+
print(resp.content) # unchanged Anthropic response
|
|
81
|
+
|
|
82
|
+
client.flush() # optional: force-push buffered events before exit
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`TokevenOpenAI` and `TokevenGemini` wrap the OpenAI and Google SDKs the same way.
|
|
86
|
+
|
|
87
|
+
## First run
|
|
88
|
+
|
|
89
|
+
Set your write only ingest token:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
export TOKEVEN_INGEST_TOKEN="tkv_ing_..."
|
|
93
|
+
export TOKEVEN_BASE_URL="https://api.tokeven.com"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Create a token at https://tokeven.com/settings
|
|
97
|
+
|
|
98
|
+
Estimate the cost of a call before you send it:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
tokeven estimate --model claude-opus-4-8 "your prompt here"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The estimate runs entirely on your machine and needs no account at all.
|
|
105
|
+
|
|
106
|
+
## The sidecar (optional)
|
|
107
|
+
|
|
108
|
+
If you would rather not wrap an SDK, run the self hosted sidecar and point your
|
|
109
|
+
provider base URL at it. It forwards every request to the provider verbatim and
|
|
110
|
+
captures usage on a fail open side channel. Provider keys and prompt content
|
|
111
|
+
never reach Tokeven.
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pip install "tokeven[proxy]"
|
|
115
|
+
tokeven-proxy
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
A container image and an example `docker-compose.yml` ship alongside this package.
|
|
119
|
+
|
|
120
|
+
## The live cost widget (optional)
|
|
121
|
+
|
|
122
|
+
A one line spend gauge for your shell prompt, tmux, or editor status line. It
|
|
123
|
+
reuses your dashboard login, never an ingest token or a provider key.
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
tokeven-widget # print one status line and exit
|
|
127
|
+
tokeven-widget watch # poll and reprint on an interval
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## What is and is not tracked
|
|
131
|
+
|
|
132
|
+
Tokeven sees the traffic you instrument. Calls made through the provider
|
|
133
|
+
consoles, through the Anthropic Workbench, or from applications you have not
|
|
134
|
+
wrapped will not appear on the dashboard.
|
|
135
|
+
|
|
136
|
+
## Free and paid
|
|
137
|
+
|
|
138
|
+
Everything this package does on your machine is free, and there is no trial clock
|
|
139
|
+
on it. That includes pre send cost estimates, the model picker, efficiency
|
|
140
|
+
suggestions, the MCP server, the sidecar, and the live cost widget. A free
|
|
141
|
+
Tokeven account adds a dashboard covering 1,000 tracked calls per month.
|
|
142
|
+
|
|
143
|
+
The paid tier is priced as gainshare. Tokeven earns 10 percent of verified
|
|
144
|
+
savings, measured per call against live token prices rather than a frozen
|
|
145
|
+
baseline, and you keep the other 90 percent. If you save nothing, you pay
|
|
146
|
+
nothing, and the fee falls automatically when model prices fall. There is no per
|
|
147
|
+
seat charge.
|
|
148
|
+
|
|
149
|
+
Paid adds:
|
|
150
|
+
|
|
151
|
+
- Unlimited tracked calls
|
|
152
|
+
- Prompt revision suggestions
|
|
153
|
+
- Organization wide savings dashboard and per person savings tracking
|
|
154
|
+
- Analytics across all three providers
|
|
155
|
+
- Embeddable widgets
|
|
156
|
+
- n8n and webhook integrations
|
|
157
|
+
- CSV, JSON, and API export
|
|
158
|
+
|
|
159
|
+
Enterprise terms, including capped arrangements for teams that budget fixed line
|
|
160
|
+
items, SSO, and custom retention, are handled case by case.
|
|
161
|
+
|
|
162
|
+
If you are weighing the paid tier or want a hand sizing what you would actually
|
|
163
|
+
save, email team@tokeven.com. We are happy to look at your numbers with you, and
|
|
164
|
+
there is no obligation attached to asking. Full pricing detail is at
|
|
165
|
+
https://tokeven.com/pricing
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
Proprietary. The full terms ship in the `LICENSE` file bundled with this
|
|
170
|
+
package. Questions: team@tokeven.com
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tokeven"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Privacy first cost visibility for Claude, ChatGPT, and Gemini API calls. Metrics only, and your provider keys and prompts stay on your machine."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "LicenseRef-Tokeven-Proprietary"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Tokeven", email = "team@tokeven.com" }]
|
|
14
|
+
maintainers = [{ name = "Tokeven", email = "team@tokeven.com" }]
|
|
15
|
+
keywords = [
|
|
16
|
+
"anthropic", "claude", "openai", "gemini", "llm", "cost",
|
|
17
|
+
"observability", "tokens", "finops", "mcp",
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
"Topic :: System :: Monitoring",
|
|
29
|
+
"Typing :: Typed",
|
|
30
|
+
]
|
|
31
|
+
dependencies = [
|
|
32
|
+
"httpx>=0.24",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
anthropic = ["anthropic>=0.40"]
|
|
37
|
+
openai = ["openai>=1.0"]
|
|
38
|
+
google-genai = ["google-genai>=1.0"]
|
|
39
|
+
requests = ["requests>=2.28"]
|
|
40
|
+
mcp = ["mcp>=1.0"]
|
|
41
|
+
proxy = ["starlette>=0.37", "uvicorn>=0.29", "pydantic-settings>=2.2"]
|
|
42
|
+
all = [
|
|
43
|
+
"anthropic>=0.40",
|
|
44
|
+
"openai>=1.0",
|
|
45
|
+
"google-genai>=1.0",
|
|
46
|
+
"mcp>=1.0",
|
|
47
|
+
"starlette>=0.37",
|
|
48
|
+
"uvicorn>=0.29",
|
|
49
|
+
"pydantic-settings>=2.2",
|
|
50
|
+
]
|
|
51
|
+
dev = [
|
|
52
|
+
"pytest>=8.0",
|
|
53
|
+
"pytest-asyncio>=0.23",
|
|
54
|
+
"httpx>=0.24",
|
|
55
|
+
"anthropic>=0.40",
|
|
56
|
+
"openai>=1.0",
|
|
57
|
+
"google-genai>=1.0",
|
|
58
|
+
"mcp>=1.0",
|
|
59
|
+
"starlette>=0.37",
|
|
60
|
+
"uvicorn>=0.29",
|
|
61
|
+
"pydantic-settings>=2.2",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[project.scripts]
|
|
65
|
+
tokeven = "tokeven.cli:main"
|
|
66
|
+
tokeven-mcp = "tokeven.mcp_server:main"
|
|
67
|
+
tokeven-widget = "tokeven.widget.cli:main"
|
|
68
|
+
tokeven-proxy = "tokeven.proxy.main:main"
|
|
69
|
+
|
|
70
|
+
[project.urls]
|
|
71
|
+
Homepage = "https://tokeven.com"
|
|
72
|
+
Documentation = "https://tokeven.com/docs"
|
|
73
|
+
Pricing = "https://tokeven.com/pricing"
|
|
74
|
+
Privacy = "https://tokeven.com/privacy"
|
|
75
|
+
Security = "https://tokeven.com/security"
|
|
76
|
+
Changelog = "https://tokeven.com/docs#changelog"
|
|
77
|
+
|
|
78
|
+
[tool.setuptools.packages.find]
|
|
79
|
+
where = ["src"]
|
|
80
|
+
|
|
81
|
+
[tool.setuptools.package-data]
|
|
82
|
+
tokeven = ["py.typed"]
|
|
83
|
+
|
|
84
|
+
[tool.pytest.ini_options]
|
|
85
|
+
testpaths = ["tests"]
|
|
86
|
+
pythonpath = ["src"]
|
|
87
|
+
addopts = "--import-mode=importlib"
|
|
88
|
+
asyncio_mode = "auto"
|
tokeven-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Tokeven client SDK -- privacy-first, metric-only instrumentation.
|
|
2
|
+
|
|
3
|
+
Public API::
|
|
4
|
+
|
|
5
|
+
from tokeven import TokevenAnthropic, TokevenOpenAI, TokevenGemini, TokevenConfig
|
|
6
|
+
|
|
7
|
+
The wrappers capture only token counts + metadata (never prompt/response text),
|
|
8
|
+
fail open (instrumentation errors never break underlying calls), and push
|
|
9
|
+
batched events to Tokeven using a write-only ingest token.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from .advisor import (
|
|
15
|
+
CONFIDENCE_GREEN,
|
|
16
|
+
CONFIDENCE_YELLOW,
|
|
17
|
+
AdvisorResult,
|
|
18
|
+
ImproveResult,
|
|
19
|
+
ModelOption,
|
|
20
|
+
classify_task,
|
|
21
|
+
detect_modality,
|
|
22
|
+
estimate,
|
|
23
|
+
estimate_cost,
|
|
24
|
+
estimate_output_tokens,
|
|
25
|
+
format_options_table,
|
|
26
|
+
improve,
|
|
27
|
+
optimize_prompt,
|
|
28
|
+
)
|
|
29
|
+
from .client import TokevenAnthropic, wrap
|
|
30
|
+
from .config import MODE_PER_PROMPT, MODE_PER_SESSION, TokevenConfig
|
|
31
|
+
from .efficiency import (
|
|
32
|
+
Nudge,
|
|
33
|
+
cache_nudge,
|
|
34
|
+
compact_conversation,
|
|
35
|
+
estimate_messages_tokens,
|
|
36
|
+
estimate_tokens,
|
|
37
|
+
max_tokens_nudge,
|
|
38
|
+
model_mix_nudge,
|
|
39
|
+
pick_model,
|
|
40
|
+
prompt_length_nudge,
|
|
41
|
+
should_compact,
|
|
42
|
+
streaming_nudge,
|
|
43
|
+
)
|
|
44
|
+
from .entitlements import fetch_entitlements, is_entitled
|
|
45
|
+
from .gemini_client import TokevenGemini
|
|
46
|
+
from .guardrails import (
|
|
47
|
+
GuardConfig,
|
|
48
|
+
IdleReaper,
|
|
49
|
+
post_tool_use_reset,
|
|
50
|
+
pre_tool_use_decision,
|
|
51
|
+
touch_heartbeat,
|
|
52
|
+
)
|
|
53
|
+
from .openai_client import TokevenOpenAI
|
|
54
|
+
from .registry import (
|
|
55
|
+
TIER_DEEP,
|
|
56
|
+
TIER_QUICK,
|
|
57
|
+
TIER_STANDARD,
|
|
58
|
+
all_models,
|
|
59
|
+
get_model,
|
|
60
|
+
model_id_for_tier,
|
|
61
|
+
tier_to_model_id,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
__version__ = "0.1.0"
|
|
65
|
+
|
|
66
|
+
__all__ = [
|
|
67
|
+
"TokevenAnthropic",
|
|
68
|
+
"TokevenOpenAI",
|
|
69
|
+
"TokevenGemini",
|
|
70
|
+
"wrap",
|
|
71
|
+
"TokevenConfig",
|
|
72
|
+
"AdvisorResult",
|
|
73
|
+
"ModelOption",
|
|
74
|
+
"CONFIDENCE_GREEN",
|
|
75
|
+
"CONFIDENCE_YELLOW",
|
|
76
|
+
"classify_task",
|
|
77
|
+
"detect_modality",
|
|
78
|
+
"estimate",
|
|
79
|
+
"estimate_cost",
|
|
80
|
+
"estimate_output_tokens",
|
|
81
|
+
"format_options_table",
|
|
82
|
+
"optimize_prompt",
|
|
83
|
+
"improve",
|
|
84
|
+
"ImproveResult",
|
|
85
|
+
"fetch_entitlements",
|
|
86
|
+
"is_entitled",
|
|
87
|
+
"MODE_PER_PROMPT",
|
|
88
|
+
"MODE_PER_SESSION",
|
|
89
|
+
"pick_model",
|
|
90
|
+
"compact_conversation",
|
|
91
|
+
"should_compact",
|
|
92
|
+
"estimate_tokens",
|
|
93
|
+
"estimate_messages_tokens",
|
|
94
|
+
"Nudge",
|
|
95
|
+
"max_tokens_nudge",
|
|
96
|
+
"prompt_length_nudge",
|
|
97
|
+
"cache_nudge",
|
|
98
|
+
"streaming_nudge",
|
|
99
|
+
"model_mix_nudge",
|
|
100
|
+
"all_models",
|
|
101
|
+
"get_model",
|
|
102
|
+
"model_id_for_tier",
|
|
103
|
+
"tier_to_model_id",
|
|
104
|
+
"TIER_QUICK",
|
|
105
|
+
"TIER_STANDARD",
|
|
106
|
+
"TIER_DEEP",
|
|
107
|
+
"GuardConfig",
|
|
108
|
+
"IdleReaper",
|
|
109
|
+
"pre_tool_use_decision",
|
|
110
|
+
"post_tool_use_reset",
|
|
111
|
+
"touch_heartbeat",
|
|
112
|
+
]
|