token-sentinel 1.0.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.
- token_sentinel-1.0.0/LICENSE +201 -0
- token_sentinel-1.0.0/PKG-INFO +253 -0
- token_sentinel-1.0.0/README.md +169 -0
- token_sentinel-1.0.0/docs/architecture.md +103 -0
- token_sentinel-1.0.0/docs/integration-patterns.md +224 -0
- token_sentinel-1.0.0/docs/providers.md +94 -0
- token_sentinel-1.0.0/docs/quickstart-anthropic.md +162 -0
- token_sentinel-1.0.0/docs/quickstart-bedrock.md +177 -0
- token_sentinel-1.0.0/docs/quickstart-gemini.md +187 -0
- token_sentinel-1.0.0/docs/quickstart-openai.md +207 -0
- token_sentinel-1.0.0/docs/user/01-installation.md +108 -0
- token_sentinel-1.0.0/docs/user/02-quickstart.md +159 -0
- token_sentinel-1.0.0/docs/user/03-modes.md +216 -0
- token_sentinel-1.0.0/docs/user/04-waste-rules.md +542 -0
- token_sentinel-1.0.0/docs/user/05-providers.md +239 -0
- token_sentinel-1.0.0/docs/user/06-integrations.md +301 -0
- token_sentinel-1.0.0/docs/user/07-api-reference.md +408 -0
- token_sentinel-1.0.0/docs/user/08-troubleshooting.md +377 -0
- token_sentinel-1.0.0/docs/user/09-faq.md +136 -0
- token_sentinel-1.0.0/docs/user/README.md +75 -0
- token_sentinel-1.0.0/docs/waste-taxonomy.md +204 -0
- token_sentinel-1.0.0/examples/anthropic_basic.py +54 -0
- token_sentinel-1.0.0/examples/bedrock_basic.py +81 -0
- token_sentinel-1.0.0/examples/gemini_basic.py +70 -0
- token_sentinel-1.0.0/examples/tool_loop_demo.py +189 -0
- token_sentinel-1.0.0/pyproject.toml +124 -0
- token_sentinel-1.0.0/tests/__init__.py +0 -0
- token_sentinel-1.0.0/tests/conftest.py +288 -0
- token_sentinel-1.0.0/tests/test_anthropic_wrapper.py +766 -0
- token_sentinel-1.0.0/tests/test_bedrock_wrapper.py +861 -0
- token_sentinel-1.0.0/tests/test_cloud_client.py +973 -0
- token_sentinel-1.0.0/tests/test_cohere_wrapper.py +982 -0
- token_sentinel-1.0.0/tests/test_coverage_gaps.py +773 -0
- token_sentinel-1.0.0/tests/test_deepgram_wrapper.py +846 -0
- token_sentinel-1.0.0/tests/test_elevenlabs_wrapper.py +764 -0
- token_sentinel-1.0.0/tests/test_events_usage_extra.py +181 -0
- token_sentinel-1.0.0/tests/test_gemini_wrapper.py +889 -0
- token_sentinel-1.0.0/tests/test_langchain_enricher.py +438 -0
- token_sentinel-1.0.0/tests/test_openai_compat.py +348 -0
- token_sentinel-1.0.0/tests/test_openai_stream_block_warning.py +468 -0
- token_sentinel-1.0.0/tests/test_openai_streaming.py +1178 -0
- token_sentinel-1.0.0/tests/test_openai_wrapper.py +930 -0
- token_sentinel-1.0.0/tests/test_otel_enricher.py +647 -0
- token_sentinel-1.0.0/tests/test_policy_client.py +1023 -0
- token_sentinel-1.0.0/tests/test_properties.py +555 -0
- token_sentinel-1.0.0/tests/test_properties_v031.py +732 -0
- token_sentinel-1.0.0/tests/test_rebrand_aliases.py +181 -0
- token_sentinel-1.0.0/tests/test_repair_loop.py +437 -0
- token_sentinel-1.0.0/tests/test_replicate_wrapper.py +385 -0
- token_sentinel-1.0.0/tests/test_rules_audio_multichannel_doubling.py +341 -0
- token_sentinel-1.0.0/tests/test_rules_context_bloat.py +251 -0
- token_sentinel-1.0.0/tests/test_rules_dos_caps.py +420 -0
- token_sentinel-1.0.0/tests/test_rules_embedding_waste.py +200 -0
- token_sentinel-1.0.0/tests/test_rules_keyword_word_boundary.py +275 -0
- token_sentinel-1.0.0/tests/test_rules_model_misroute.py +569 -0
- token_sentinel-1.0.0/tests/test_rules_redaction.py +317 -0
- token_sentinel-1.0.0/tests/test_rules_rerank_thrash.py +307 -0
- token_sentinel-1.0.0/tests/test_rules_retrieval_thrash.py +349 -0
- token_sentinel-1.0.0/tests/test_rules_retry_storm.py +209 -0
- token_sentinel-1.0.0/tests/test_rules_tool_definition_bloat.py +253 -0
- token_sentinel-1.0.0/tests/test_rules_tool_definition_redact_names.py +203 -0
- token_sentinel-1.0.0/tests/test_rules_tool_loop.py +367 -0
- token_sentinel-1.0.0/tests/test_rules_vision_cost_concentration.py +311 -0
- token_sentinel-1.0.0/tests/test_rules_vision_high_detail_misroute.py +263 -0
- token_sentinel-1.0.0/tests/test_rules_vision_re_upload.py +471 -0
- token_sentinel-1.0.0/tests/test_rules_voice_switching_loop.py +446 -0
- token_sentinel-1.0.0/tests/test_rules_zombie.py +260 -0
- token_sentinel-1.0.0/tests/test_sentinel.py +388 -0
- token_sentinel-1.0.0/tests/test_sentinel_concurrency.py +370 -0
- token_sentinel-1.0.0/tests/test_sentinel_dedup.py +338 -0
- token_sentinel-1.0.0/tests/test_sentinel_dispatch_ordering.py +349 -0
- token_sentinel-1.0.0/tests/test_sentinel_unknown_rules_warning.py +153 -0
- token_sentinel-1.0.0/tests/test_sentinel_wrap_errors.py +270 -0
- token_sentinel-1.0.0/tests/test_session_tags.py +378 -0
- token_sentinel-1.0.0/tests/test_tracer.py +119 -0
- token_sentinel-1.0.0/tests/test_v032_lows_and_nits.py +308 -0
- token_sentinel-1.0.0/tests/test_vision_re_upload_perceptual.py +435 -0
- token_sentinel-1.0.0/tests/test_voyage_wrapper.py +581 -0
- token_sentinel-1.0.0/tests/test_whisper_streaming.py +433 -0
- token_sentinel-1.0.0/token_sentinel/__init__.py +33 -0
- token_sentinel-1.0.0/token_sentinel/cloud_client.py +455 -0
- token_sentinel-1.0.0/token_sentinel/enrichers/__init__.py +22 -0
- token_sentinel-1.0.0/token_sentinel/enrichers/langchain.py +816 -0
- token_sentinel-1.0.0/token_sentinel/enrichers/otel.py +601 -0
- token_sentinel-1.0.0/token_sentinel/events.py +240 -0
- token_sentinel-1.0.0/token_sentinel/policy_client.py +645 -0
- token_sentinel-1.0.0/token_sentinel/py.typed +0 -0
- token_sentinel-1.0.0/token_sentinel/rules/__init__.py +79 -0
- token_sentinel-1.0.0/token_sentinel/rules/audio_multichannel_doubling.py +207 -0
- token_sentinel-1.0.0/token_sentinel/rules/base.py +31 -0
- token_sentinel-1.0.0/token_sentinel/rules/context_bloat.py +63 -0
- token_sentinel-1.0.0/token_sentinel/rules/embedding_waste.py +58 -0
- token_sentinel-1.0.0/token_sentinel/rules/model_misroute.py +400 -0
- token_sentinel-1.0.0/token_sentinel/rules/repair_loop.py +532 -0
- token_sentinel-1.0.0/token_sentinel/rules/rerank_thrash.py +171 -0
- token_sentinel-1.0.0/token_sentinel/rules/retrieval_thrash.py +172 -0
- token_sentinel-1.0.0/token_sentinel/rules/retry_storm.py +45 -0
- token_sentinel-1.0.0/token_sentinel/rules/tool_definition_bloat.py +324 -0
- token_sentinel-1.0.0/token_sentinel/rules/tool_loop.py +517 -0
- token_sentinel-1.0.0/token_sentinel/rules/vision_cost_concentration.py +182 -0
- token_sentinel-1.0.0/token_sentinel/rules/vision_high_detail_misroute.py +154 -0
- token_sentinel-1.0.0/token_sentinel/rules/vision_re_upload.py +651 -0
- token_sentinel-1.0.0/token_sentinel/rules/voice_switching_loop.py +241 -0
- token_sentinel-1.0.0/token_sentinel/rules/zombie.py +48 -0
- token_sentinel-1.0.0/token_sentinel/sentinel.py +1251 -0
- token_sentinel-1.0.0/token_sentinel/tracer.py +71 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/__init__.py +57 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/anthropic.py +629 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/bedrock.py +560 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/cohere.py +800 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/deepgram.py +853 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/elevenlabs.py +740 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/gemini.py +691 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/openai.py +1612 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/replicate.py +650 -0
- token_sentinel-1.0.0/token_sentinel/wrappers/voyage.py +407 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 TokenSentinel contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: token-sentinel
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Predictive token-waste detection for AI agents
|
|
5
|
+
Project-URL: Homepage, https://tokensentinel.dev
|
|
6
|
+
Project-URL: Documentation, https://docs.tokensentinel.dev
|
|
7
|
+
Project-URL: Issues, https://github.com/tokensentinel/tokensentinel-sdk-python/issues
|
|
8
|
+
Project-URL: Repository, https://github.com/tokensentinel/tokensentinel-sdk-python
|
|
9
|
+
Project-URL: Changelog, https://github.com/tokensentinel/tokensentinel-sdk-python/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: TokenSentinel contributors <shakyasmreta@gmail.com>
|
|
11
|
+
License: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: agents,anthropic,cost,finops,llm,observability,openai,tokens
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: System :: Monitoring
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Provides-Extra: all
|
|
26
|
+
Requires-Dist: anthropic>=0.39.0; extra == 'all'
|
|
27
|
+
Requires-Dist: boto3>=1.35.0; extra == 'all'
|
|
28
|
+
Requires-Dist: cohere>=5.0; extra == 'all'
|
|
29
|
+
Requires-Dist: deepgram-sdk>=3.0; extra == 'all'
|
|
30
|
+
Requires-Dist: elevenlabs>=1.0; extra == 'all'
|
|
31
|
+
Requires-Dist: google-genai>=1.0.0; extra == 'all'
|
|
32
|
+
Requires-Dist: imagehash>=4.3; extra == 'all'
|
|
33
|
+
Requires-Dist: langchain-core>=0.3; extra == 'all'
|
|
34
|
+
Requires-Dist: mutagen>=1.47; extra == 'all'
|
|
35
|
+
Requires-Dist: numpy>=1.26.0; extra == 'all'
|
|
36
|
+
Requires-Dist: openai>=1.50.0; extra == 'all'
|
|
37
|
+
Requires-Dist: opentelemetry-api>=1.27; extra == 'all'
|
|
38
|
+
Requires-Dist: opentelemetry-sdk>=1.27; extra == 'all'
|
|
39
|
+
Requires-Dist: opentelemetry-semantic-conventions>=0.48b0; extra == 'all'
|
|
40
|
+
Requires-Dist: pillow>=10; extra == 'all'
|
|
41
|
+
Requires-Dist: replicate>=0.40; extra == 'all'
|
|
42
|
+
Requires-Dist: sentence-transformers>=2.7.0; extra == 'all'
|
|
43
|
+
Requires-Dist: voyageai>=0.2; extra == 'all'
|
|
44
|
+
Provides-Extra: anthropic
|
|
45
|
+
Requires-Dist: anthropic>=0.39.0; extra == 'anthropic'
|
|
46
|
+
Provides-Extra: audio-metadata
|
|
47
|
+
Requires-Dist: mutagen>=1.47; extra == 'audio-metadata'
|
|
48
|
+
Provides-Extra: bedrock
|
|
49
|
+
Requires-Dist: boto3>=1.35.0; extra == 'bedrock'
|
|
50
|
+
Provides-Extra: cohere
|
|
51
|
+
Requires-Dist: cohere>=5.0; extra == 'cohere'
|
|
52
|
+
Provides-Extra: deepgram
|
|
53
|
+
Requires-Dist: deepgram-sdk>=3.0; extra == 'deepgram'
|
|
54
|
+
Provides-Extra: dev
|
|
55
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
56
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
57
|
+
Requires-Dist: pytest-cov>=7.0; extra == 'dev'
|
|
58
|
+
Requires-Dist: pytest-mock>=3.15; extra == 'dev'
|
|
59
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
60
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
61
|
+
Provides-Extra: elevenlabs
|
|
62
|
+
Requires-Dist: elevenlabs>=1.0; extra == 'elevenlabs'
|
|
63
|
+
Provides-Extra: embeddings
|
|
64
|
+
Requires-Dist: numpy>=1.26.0; extra == 'embeddings'
|
|
65
|
+
Requires-Dist: sentence-transformers>=2.7.0; extra == 'embeddings'
|
|
66
|
+
Provides-Extra: gemini
|
|
67
|
+
Requires-Dist: google-genai>=1.0.0; extra == 'gemini'
|
|
68
|
+
Provides-Extra: langchain
|
|
69
|
+
Requires-Dist: langchain-core>=0.3; extra == 'langchain'
|
|
70
|
+
Provides-Extra: openai
|
|
71
|
+
Requires-Dist: openai>=1.50.0; extra == 'openai'
|
|
72
|
+
Provides-Extra: otel
|
|
73
|
+
Requires-Dist: opentelemetry-api>=1.27; extra == 'otel'
|
|
74
|
+
Requires-Dist: opentelemetry-sdk>=1.27; extra == 'otel'
|
|
75
|
+
Requires-Dist: opentelemetry-semantic-conventions>=0.48b0; extra == 'otel'
|
|
76
|
+
Provides-Extra: replicate
|
|
77
|
+
Requires-Dist: replicate>=0.40; extra == 'replicate'
|
|
78
|
+
Provides-Extra: vision-perceptual
|
|
79
|
+
Requires-Dist: imagehash>=4.3; extra == 'vision-perceptual'
|
|
80
|
+
Requires-Dist: pillow>=10; extra == 'vision-perceptual'
|
|
81
|
+
Provides-Extra: voyage
|
|
82
|
+
Requires-Dist: voyageai>=0.2; extra == 'voyage'
|
|
83
|
+
Description-Content-Type: text/markdown
|
|
84
|
+
|
|
85
|
+
# token-sentinel
|
|
86
|
+
|
|
87
|
+
Predictive token-waste detection for AI agents.
|
|
88
|
+
|
|
89
|
+
A Python SDK that catches token waste *mid-run* — before the meter spins — and gives your app a callback to log, alert, or hard-stop the agent. Apache-2.0 licensed, zero-dependency core. Pair the SDK with the optional TokenSentinel Cloud for hosted dashboards, budget enforcement, drift detection, and judge ratification on Pro.
|
|
90
|
+
|
|
91
|
+
Existing observability tools (Langfuse, LangSmith, Helicone, Datadog LLM) tell you what your bill was. TokenSentinel tells you which agent is leaking *right now*.
|
|
92
|
+
|
|
93
|
+
## What it catches
|
|
94
|
+
|
|
95
|
+
Fifteen deterministic rules, all in-process, sub-millisecond per rule:
|
|
96
|
+
|
|
97
|
+
| Leak / Waste | Signal |
|
|
98
|
+
|---|---|
|
|
99
|
+
| **Tool-loop** | Same tool, ≥3 cosine-similar calls in a window |
|
|
100
|
+
| **Context bloat** | Prompt-tokens-per-turn slope rising past threshold |
|
|
101
|
+
| **Embedding waste** | Same embedding lookup repeated within session |
|
|
102
|
+
| **Zombie agent** | No user-facing output for N min, calls still firing |
|
|
103
|
+
| **Model misroute** | Classification-shaped prompt sent to a frontier model |
|
|
104
|
+
| **Retry storm** | Same call retried >N times without parameter change |
|
|
105
|
+
| **Tool-definition bloat** | A single request ships ≥30 tool defs or ≥30KB of tool JSON (the MCP problem) |
|
|
106
|
+
| **Retrieval thrash** | Retrieval tool called repeatedly with overlapping queries (the RAG problem) |
|
|
107
|
+
| **Vision re-upload** | Same image (SHA-256 or perceptual hash) uploaded repeatedly across turns |
|
|
108
|
+
| **Vision detail misroute** | High-detail vision flag on low-detail-suitable images (e.g. icons, low-res) |
|
|
109
|
+
| **Vision concentration** | Visual tokens heavily concentrated in a single/few outlier sessions |
|
|
110
|
+
| **Audio channel doubling** | Stereo/multichannel audio transcription when mono-channel would suffice |
|
|
111
|
+
| **Voice switching loop** | Rapid shifting of ElevenLabs voice IDs on identical text payloads |
|
|
112
|
+
| **Rerank thrash** | Cohere rerank API requests repeated for identical search lists |
|
|
113
|
+
| **Repair loop** | Conversational loop with repeated user corrections and similar agent regenerations |
|
|
114
|
+
|
|
115
|
+
**Composite signals (Pro tier, cloud-side)**
|
|
116
|
+
|
|
117
|
+
| Composite | Fires when |
|
|
118
|
+
|---|---|
|
|
119
|
+
| **lost_agent** | `tool_loop` + `context_bloat` + `model_misroute` all hit on the same session inside a 30s window |
|
|
120
|
+
| **runaway_retrieval** | `retrieval_thrash` + `embedding_waste` co-fire while the per-turn token slope is still climbing |
|
|
121
|
+
| **zombie_loop** | `zombie` + `retry_storm` co-fire on a session with no user-facing output |
|
|
122
|
+
|
|
123
|
+
## Supported providers
|
|
124
|
+
|
|
125
|
+
Native wrappers — `pip install token-sentinel[<provider>]`:
|
|
126
|
+
|
|
127
|
+
| Provider | SDK | Streaming | Async |
|
|
128
|
+
|---|---|---|---|
|
|
129
|
+
| Anthropic | `anthropic` | yes | yes |
|
|
130
|
+
| OpenAI | `openai` | yes¹ | yes |
|
|
131
|
+
| Google Gemini | `google-genai` | yes | yes |
|
|
132
|
+
| AWS Bedrock | `boto3` | yes | sync only |
|
|
133
|
+
|
|
134
|
+
¹ OpenAI streaming instrumentation shipped in stable release.
|
|
135
|
+
|
|
136
|
+
Transparent through the OpenAI wrapper (just set `base_url`):
|
|
137
|
+
|
|
138
|
+
DeepSeek · Together AI · Fireworks · Groq · OpenRouter · Anyscale · Mistral La Plateforme · Perplexity · vLLM · Ollama · text-generation-inference · LM Studio
|
|
139
|
+
|
|
140
|
+
Google Vertex AI is reached via the same Gemini wrapper by passing `vertexai=True` to `genai.Client(...)`.
|
|
141
|
+
|
|
142
|
+
See [docs/providers.md](docs/providers.md) for the full matrix and per-provider snippets.
|
|
143
|
+
|
|
144
|
+
## Quick start
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
pip install token-sentinel[anthropic]
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from token_sentinel import Sentinel
|
|
152
|
+
import anthropic
|
|
153
|
+
|
|
154
|
+
sentinel = Sentinel(project="my-agent", mode="log") # log | alert | block
|
|
155
|
+
|
|
156
|
+
@sentinel.on_leak
|
|
157
|
+
def handle(event):
|
|
158
|
+
print(f"LEAK [{event.type}] confidence={event.confidence:.2f} burn=${event.estimated_burn:.4f}")
|
|
159
|
+
|
|
160
|
+
client = sentinel.wrap(anthropic.Anthropic())
|
|
161
|
+
# use the client normally — Sentinel watches in-process
|
|
162
|
+
client.messages.create(
|
|
163
|
+
model="claude-sonnet-4-6",
|
|
164
|
+
max_tokens=100,
|
|
165
|
+
messages=[{"role": "user", "content": "Hello"}],
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Switch providers by installing the right extra and changing one line:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
# DeepSeek (or any OpenAI-compatible endpoint)
|
|
173
|
+
import openai
|
|
174
|
+
client = sentinel.wrap(openai.OpenAI(base_url="https://api.deepseek.com"))
|
|
175
|
+
|
|
176
|
+
# Google Gemini
|
|
177
|
+
from google import genai
|
|
178
|
+
client = sentinel.wrap(genai.Client())
|
|
179
|
+
|
|
180
|
+
# AWS Bedrock
|
|
181
|
+
import boto3
|
|
182
|
+
client = sentinel.wrap(boto3.client("bedrock-runtime"))
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Per-provider deep dives — install, wrap, leak, stream, async, production:
|
|
186
|
+
|
|
187
|
+
- [Anthropic quickstart](docs/quickstart-anthropic.md)
|
|
188
|
+
- [OpenAI quickstart](docs/quickstart-openai.md) (covers DeepSeek, Together, Groq, vLLM, Ollama, …)
|
|
189
|
+
- [Gemini quickstart](docs/quickstart-gemini.md) (covers Vertex AI)
|
|
190
|
+
- [Bedrock quickstart](docs/quickstart-bedrock.md)
|
|
191
|
+
|
|
192
|
+
## Modes
|
|
193
|
+
|
|
194
|
+
| Mode | Behavior |
|
|
195
|
+
|---|---|
|
|
196
|
+
| `log` | Emit events to your handler. Default. Safe for production from day one. |
|
|
197
|
+
| `alert` | Same as `log` plus optional cloud-sink delivery for dashboards and webhooks. |
|
|
198
|
+
| `block` | Raise `LeakDetected` to halt the agent at the next boundary. Opt-in. |
|
|
199
|
+
|
|
200
|
+
## Works with MCP, RAG, and orchestration frameworks
|
|
201
|
+
|
|
202
|
+
TokenSentinel instruments at the LLM-client layer, so it transparently catches traffic from MCP hosts, RAG pipelines, and orchestration frameworks (LangChain, LangGraph, CrewAI, AutoGen, Pydantic AI). See [docs/integration-patterns.md](docs/integration-patterns.md).
|
|
203
|
+
|
|
204
|
+
## Cloud (optional)
|
|
205
|
+
|
|
206
|
+
The hosted TokenSentinel Cloud is closed-source, opt-in, configured via the SDK's `cloud_endpoint=` and `api_key=` constructor args. Without those, nothing leaves the process. The cloud provides retention, a hosted dashboard, the **Intervention Pack** (budget caps + velocity ceilings + kill-switch), and on Pro: LLM-as-judge ratification, drift detection, trace consolidation, RBAC, audit logs, multi-environment routing, the cost estimator, and OAuth login.
|
|
207
|
+
|
|
208
|
+
Tier comparison and pricing are detailed on the official website: see [tokensentinel.dev](https://tokensentinel.dev) for the customer-facing tier story.
|
|
209
|
+
|
|
210
|
+
## Migrate from Helicone / Langfuse / LangSmith
|
|
211
|
+
|
|
212
|
+
The `tokensentinel-migrate` companion package replays your existing trace history through the rules and backfills events into your TokenSentinel cloud project. See the [tokensentinel-migrate package on PyPI](https://pypi.org/project/tokensentinel-migrate/).
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
pip install tokensentinel-migrate
|
|
216
|
+
python -m tokensentinel_migrate helicone --helicone-api-key sk-... --tokensentinel-endpoint https://... --tokensentinel-api-key tsk_... --project my-agent --since 2026-04-09 --dry-run
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
> **Self-hosted note.** vLLM / Ollama / TGI all expose OpenAI-compatible endpoints, so TokenSentinel works against them out of the box. Leak signals are real, but the dollar burn estimate assumes priced API usage — for self-hosted, treat the burn estimate as a quality signal, not a billing signal.
|
|
220
|
+
|
|
221
|
+
## Status
|
|
222
|
+
|
|
223
|
+
**Stable Release** — 15 deterministic rules, 9 native providers (Anthropic, OpenAI, Gemini, Bedrock, Voyage, Cohere, Replicate, Deepgram, ElevenLabs), streaming + async, and full integration with the optional TokenSentinel Cloud policy engine.
|
|
224
|
+
|
|
225
|
+
**Tests**: 912 SDK tests passing. Codebase is clean of ruff, mypy, and typecheck warnings.
|
|
226
|
+
|
|
227
|
+
The public API surface (`Sentinel`, `wrap`, `on_leak`, `record_call`, `LeakEvent`, `CallRecord`, `LeakDetected`, plus the enforcement exceptions `BudgetExceeded`, `VelocityExceeded`, `KillSwitchActive`) is stable and follows semver — pin to a minor version (e.g., `token-sentinel>=0.10,<0.11`) and upgrade deliberately.
|
|
228
|
+
|
|
229
|
+
## Architecture
|
|
230
|
+
|
|
231
|
+
- **SDK (this package)** — Python wrapper around all major LLM clients. Apache-2.0 licensed.
|
|
232
|
+
- **Optional cloud dashboard** — closed-source, hosted at `api.tokensentinel.dev`. Provides retention, dashboards, the Intervention Pack policy plane, the LLM-as-judge ratification pipeline, drift / stability scoring, RBAC + audit, and multi-environment routing. The SDK works perfectly without it; nothing phones home unless you explicitly configure `cloud_endpoint` and `api_key`.
|
|
233
|
+
|
|
234
|
+
rule detection runs entirely in-process. The composite rules and judge ratification run cloud-side on top of the same `LeakEvent` stream. Cloud is opt-in for retention, dashboards, team features, and the chargeback attribution coming in V2.
|
|
235
|
+
|
|
236
|
+
## Docs
|
|
237
|
+
|
|
238
|
+
User-facing docs (published with the OSS SDK):
|
|
239
|
+
|
|
240
|
+
- [User Guide](docs/user/) — installation, quickstart, modes, leak rules, providers, integrations, API reference
|
|
241
|
+
- [Architecture](docs/architecture.md) — how the wrapper, tracer, and rules engine fit together
|
|
242
|
+
- [Leak taxonomy](docs/waste-taxonomy.md) — the rules in detail with thresholds and false-positive hazards
|
|
243
|
+
- [Providers](docs/providers.md) — full matrix of supported providers
|
|
244
|
+
- [Integration patterns](docs/integration-patterns.md) — MCP, RAG, LangChain, LangGraph, CrewAI, AutoGen, Pydantic AI
|
|
245
|
+
- [Changelog](CHANGELOG.md)
|
|
246
|
+
|
|
247
|
+
## Contact & Support
|
|
248
|
+
|
|
249
|
+
For support, feedback, or inquiries, please contact shakyasmreta@gmail.com or visit our official website at [tokensentinel.dev](https://tokensentinel.dev).
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
Apache-2.0 — see [LICENSE](LICENSE). The patent grant in Apache-2.0 is the right OSS contract for an SDK that runs inline against enterprise customers' production AI calls.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# token-sentinel
|
|
2
|
+
|
|
3
|
+
Predictive token-waste detection for AI agents.
|
|
4
|
+
|
|
5
|
+
A Python SDK that catches token waste *mid-run* — before the meter spins — and gives your app a callback to log, alert, or hard-stop the agent. Apache-2.0 licensed, zero-dependency core. Pair the SDK with the optional TokenSentinel Cloud for hosted dashboards, budget enforcement, drift detection, and judge ratification on Pro.
|
|
6
|
+
|
|
7
|
+
Existing observability tools (Langfuse, LangSmith, Helicone, Datadog LLM) tell you what your bill was. TokenSentinel tells you which agent is leaking *right now*.
|
|
8
|
+
|
|
9
|
+
## What it catches
|
|
10
|
+
|
|
11
|
+
Fifteen deterministic rules, all in-process, sub-millisecond per rule:
|
|
12
|
+
|
|
13
|
+
| Leak / Waste | Signal |
|
|
14
|
+
|---|---|
|
|
15
|
+
| **Tool-loop** | Same tool, ≥3 cosine-similar calls in a window |
|
|
16
|
+
| **Context bloat** | Prompt-tokens-per-turn slope rising past threshold |
|
|
17
|
+
| **Embedding waste** | Same embedding lookup repeated within session |
|
|
18
|
+
| **Zombie agent** | No user-facing output for N min, calls still firing |
|
|
19
|
+
| **Model misroute** | Classification-shaped prompt sent to a frontier model |
|
|
20
|
+
| **Retry storm** | Same call retried >N times without parameter change |
|
|
21
|
+
| **Tool-definition bloat** | A single request ships ≥30 tool defs or ≥30KB of tool JSON (the MCP problem) |
|
|
22
|
+
| **Retrieval thrash** | Retrieval tool called repeatedly with overlapping queries (the RAG problem) |
|
|
23
|
+
| **Vision re-upload** | Same image (SHA-256 or perceptual hash) uploaded repeatedly across turns |
|
|
24
|
+
| **Vision detail misroute** | High-detail vision flag on low-detail-suitable images (e.g. icons, low-res) |
|
|
25
|
+
| **Vision concentration** | Visual tokens heavily concentrated in a single/few outlier sessions |
|
|
26
|
+
| **Audio channel doubling** | Stereo/multichannel audio transcription when mono-channel would suffice |
|
|
27
|
+
| **Voice switching loop** | Rapid shifting of ElevenLabs voice IDs on identical text payloads |
|
|
28
|
+
| **Rerank thrash** | Cohere rerank API requests repeated for identical search lists |
|
|
29
|
+
| **Repair loop** | Conversational loop with repeated user corrections and similar agent regenerations |
|
|
30
|
+
|
|
31
|
+
**Composite signals (Pro tier, cloud-side)**
|
|
32
|
+
|
|
33
|
+
| Composite | Fires when |
|
|
34
|
+
|---|---|
|
|
35
|
+
| **lost_agent** | `tool_loop` + `context_bloat` + `model_misroute` all hit on the same session inside a 30s window |
|
|
36
|
+
| **runaway_retrieval** | `retrieval_thrash` + `embedding_waste` co-fire while the per-turn token slope is still climbing |
|
|
37
|
+
| **zombie_loop** | `zombie` + `retry_storm` co-fire on a session with no user-facing output |
|
|
38
|
+
|
|
39
|
+
## Supported providers
|
|
40
|
+
|
|
41
|
+
Native wrappers — `pip install token-sentinel[<provider>]`:
|
|
42
|
+
|
|
43
|
+
| Provider | SDK | Streaming | Async |
|
|
44
|
+
|---|---|---|---|
|
|
45
|
+
| Anthropic | `anthropic` | yes | yes |
|
|
46
|
+
| OpenAI | `openai` | yes¹ | yes |
|
|
47
|
+
| Google Gemini | `google-genai` | yes | yes |
|
|
48
|
+
| AWS Bedrock | `boto3` | yes | sync only |
|
|
49
|
+
|
|
50
|
+
¹ OpenAI streaming instrumentation shipped in stable release.
|
|
51
|
+
|
|
52
|
+
Transparent through the OpenAI wrapper (just set `base_url`):
|
|
53
|
+
|
|
54
|
+
DeepSeek · Together AI · Fireworks · Groq · OpenRouter · Anyscale · Mistral La Plateforme · Perplexity · vLLM · Ollama · text-generation-inference · LM Studio
|
|
55
|
+
|
|
56
|
+
Google Vertex AI is reached via the same Gemini wrapper by passing `vertexai=True` to `genai.Client(...)`.
|
|
57
|
+
|
|
58
|
+
See [docs/providers.md](docs/providers.md) for the full matrix and per-provider snippets.
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install token-sentinel[anthropic]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from token_sentinel import Sentinel
|
|
68
|
+
import anthropic
|
|
69
|
+
|
|
70
|
+
sentinel = Sentinel(project="my-agent", mode="log") # log | alert | block
|
|
71
|
+
|
|
72
|
+
@sentinel.on_leak
|
|
73
|
+
def handle(event):
|
|
74
|
+
print(f"LEAK [{event.type}] confidence={event.confidence:.2f} burn=${event.estimated_burn:.4f}")
|
|
75
|
+
|
|
76
|
+
client = sentinel.wrap(anthropic.Anthropic())
|
|
77
|
+
# use the client normally — Sentinel watches in-process
|
|
78
|
+
client.messages.create(
|
|
79
|
+
model="claude-sonnet-4-6",
|
|
80
|
+
max_tokens=100,
|
|
81
|
+
messages=[{"role": "user", "content": "Hello"}],
|
|
82
|
+
)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Switch providers by installing the right extra and changing one line:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# DeepSeek (or any OpenAI-compatible endpoint)
|
|
89
|
+
import openai
|
|
90
|
+
client = sentinel.wrap(openai.OpenAI(base_url="https://api.deepseek.com"))
|
|
91
|
+
|
|
92
|
+
# Google Gemini
|
|
93
|
+
from google import genai
|
|
94
|
+
client = sentinel.wrap(genai.Client())
|
|
95
|
+
|
|
96
|
+
# AWS Bedrock
|
|
97
|
+
import boto3
|
|
98
|
+
client = sentinel.wrap(boto3.client("bedrock-runtime"))
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Per-provider deep dives — install, wrap, leak, stream, async, production:
|
|
102
|
+
|
|
103
|
+
- [Anthropic quickstart](docs/quickstart-anthropic.md)
|
|
104
|
+
- [OpenAI quickstart](docs/quickstart-openai.md) (covers DeepSeek, Together, Groq, vLLM, Ollama, …)
|
|
105
|
+
- [Gemini quickstart](docs/quickstart-gemini.md) (covers Vertex AI)
|
|
106
|
+
- [Bedrock quickstart](docs/quickstart-bedrock.md)
|
|
107
|
+
|
|
108
|
+
## Modes
|
|
109
|
+
|
|
110
|
+
| Mode | Behavior |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `log` | Emit events to your handler. Default. Safe for production from day one. |
|
|
113
|
+
| `alert` | Same as `log` plus optional cloud-sink delivery for dashboards and webhooks. |
|
|
114
|
+
| `block` | Raise `LeakDetected` to halt the agent at the next boundary. Opt-in. |
|
|
115
|
+
|
|
116
|
+
## Works with MCP, RAG, and orchestration frameworks
|
|
117
|
+
|
|
118
|
+
TokenSentinel instruments at the LLM-client layer, so it transparently catches traffic from MCP hosts, RAG pipelines, and orchestration frameworks (LangChain, LangGraph, CrewAI, AutoGen, Pydantic AI). See [docs/integration-patterns.md](docs/integration-patterns.md).
|
|
119
|
+
|
|
120
|
+
## Cloud (optional)
|
|
121
|
+
|
|
122
|
+
The hosted TokenSentinel Cloud is closed-source, opt-in, configured via the SDK's `cloud_endpoint=` and `api_key=` constructor args. Without those, nothing leaves the process. The cloud provides retention, a hosted dashboard, the **Intervention Pack** (budget caps + velocity ceilings + kill-switch), and on Pro: LLM-as-judge ratification, drift detection, trace consolidation, RBAC, audit logs, multi-environment routing, the cost estimator, and OAuth login.
|
|
123
|
+
|
|
124
|
+
Tier comparison and pricing are detailed on the official website: see [tokensentinel.dev](https://tokensentinel.dev) for the customer-facing tier story.
|
|
125
|
+
|
|
126
|
+
## Migrate from Helicone / Langfuse / LangSmith
|
|
127
|
+
|
|
128
|
+
The `tokensentinel-migrate` companion package replays your existing trace history through the rules and backfills events into your TokenSentinel cloud project. See the [tokensentinel-migrate package on PyPI](https://pypi.org/project/tokensentinel-migrate/).
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pip install tokensentinel-migrate
|
|
132
|
+
python -m tokensentinel_migrate helicone --helicone-api-key sk-... --tokensentinel-endpoint https://... --tokensentinel-api-key tsk_... --project my-agent --since 2026-04-09 --dry-run
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
> **Self-hosted note.** vLLM / Ollama / TGI all expose OpenAI-compatible endpoints, so TokenSentinel works against them out of the box. Leak signals are real, but the dollar burn estimate assumes priced API usage — for self-hosted, treat the burn estimate as a quality signal, not a billing signal.
|
|
136
|
+
|
|
137
|
+
## Status
|
|
138
|
+
|
|
139
|
+
**Stable Release** — 15 deterministic rules, 9 native providers (Anthropic, OpenAI, Gemini, Bedrock, Voyage, Cohere, Replicate, Deepgram, ElevenLabs), streaming + async, and full integration with the optional TokenSentinel Cloud policy engine.
|
|
140
|
+
|
|
141
|
+
**Tests**: 912 SDK tests passing. Codebase is clean of ruff, mypy, and typecheck warnings.
|
|
142
|
+
|
|
143
|
+
The public API surface (`Sentinel`, `wrap`, `on_leak`, `record_call`, `LeakEvent`, `CallRecord`, `LeakDetected`, plus the enforcement exceptions `BudgetExceeded`, `VelocityExceeded`, `KillSwitchActive`) is stable and follows semver — pin to a minor version (e.g., `token-sentinel>=0.10,<0.11`) and upgrade deliberately.
|
|
144
|
+
|
|
145
|
+
## Architecture
|
|
146
|
+
|
|
147
|
+
- **SDK (this package)** — Python wrapper around all major LLM clients. Apache-2.0 licensed.
|
|
148
|
+
- **Optional cloud dashboard** — closed-source, hosted at `api.tokensentinel.dev`. Provides retention, dashboards, the Intervention Pack policy plane, the LLM-as-judge ratification pipeline, drift / stability scoring, RBAC + audit, and multi-environment routing. The SDK works perfectly without it; nothing phones home unless you explicitly configure `cloud_endpoint` and `api_key`.
|
|
149
|
+
|
|
150
|
+
rule detection runs entirely in-process. The composite rules and judge ratification run cloud-side on top of the same `LeakEvent` stream. Cloud is opt-in for retention, dashboards, team features, and the chargeback attribution coming in V2.
|
|
151
|
+
|
|
152
|
+
## Docs
|
|
153
|
+
|
|
154
|
+
User-facing docs (published with the OSS SDK):
|
|
155
|
+
|
|
156
|
+
- [User Guide](docs/user/) — installation, quickstart, modes, leak rules, providers, integrations, API reference
|
|
157
|
+
- [Architecture](docs/architecture.md) — how the wrapper, tracer, and rules engine fit together
|
|
158
|
+
- [Leak taxonomy](docs/waste-taxonomy.md) — the rules in detail with thresholds and false-positive hazards
|
|
159
|
+
- [Providers](docs/providers.md) — full matrix of supported providers
|
|
160
|
+
- [Integration patterns](docs/integration-patterns.md) — MCP, RAG, LangChain, LangGraph, CrewAI, AutoGen, Pydantic AI
|
|
161
|
+
- [Changelog](CHANGELOG.md)
|
|
162
|
+
|
|
163
|
+
## Contact & Support
|
|
164
|
+
|
|
165
|
+
For support, feedback, or inquiries, please contact shakyasmreta@gmail.com or visit our official website at [tokensentinel.dev](https://tokensentinel.dev).
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
Apache-2.0 — see [LICENSE](LICENSE). The patent grant in Apache-2.0 is the right OSS contract for an SDK that runs inline against enterprise customers' production AI calls.
|