cachecanary 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.
- cachecanary-0.1.0/.github/workflows/ci.yml +69 -0
- cachecanary-0.1.0/.github/workflows/publish.yml +77 -0
- cachecanary-0.1.0/LICENSE +202 -0
- cachecanary-0.1.0/MANIFEST.in +8 -0
- cachecanary-0.1.0/NOTICE +4 -0
- cachecanary-0.1.0/PKG-INFO +153 -0
- cachecanary-0.1.0/README.md +120 -0
- cachecanary-0.1.0/action.yml +45 -0
- cachecanary-0.1.0/examples/request_bad.json +23 -0
- cachecanary-0.1.0/examples/request_good.json +23 -0
- cachecanary-0.1.0/examples/request_next.json +23 -0
- cachecanary-0.1.0/examples/request_too_short.json +23 -0
- cachecanary-0.1.0/pyproject.toml +50 -0
- cachecanary-0.1.0/scripts/check_site.mjs +72 -0
- cachecanary-0.1.0/scripts/live_logs_test.py +241 -0
- cachecanary-0.1.0/scripts/live_test.py +209 -0
- cachecanary-0.1.0/scripts/make_log_fixture.py +73 -0
- cachecanary-0.1.0/scripts/serve_site.py +36 -0
- cachecanary-0.1.0/setup.cfg +4 -0
- cachecanary-0.1.0/site/404.html +17 -0
- cachecanary-0.1.0/site/_headers +6 -0
- cachecanary-0.1.0/site/favicon.svg +1 -0
- cachecanary-0.1.0/site/index.html +101 -0
- cachecanary-0.1.0/site/main.js +25 -0
- cachecanary-0.1.0/site/robots.txt +2 -0
- cachecanary-0.1.0/site/style.css +98 -0
- cachecanary-0.1.0/src/cachecanary/__init__.py +3 -0
- cachecanary-0.1.0/src/cachecanary/cli.py +202 -0
- cachecanary-0.1.0/src/cachecanary/diff.py +91 -0
- cachecanary-0.1.0/src/cachecanary/github.py +50 -0
- cachecanary-0.1.0/src/cachecanary/lint.py +163 -0
- cachecanary-0.1.0/src/cachecanary/logs.py +129 -0
- cachecanary-0.1.0/src/cachecanary/models.py +77 -0
- cachecanary-0.1.0/src/cachecanary/probe.py +108 -0
- cachecanary-0.1.0/src/cachecanary/request.py +178 -0
- cachecanary-0.1.0/src/cachecanary/usage.py +96 -0
- cachecanary-0.1.0/src/cachecanary.egg-info/PKG-INFO +153 -0
- cachecanary-0.1.0/src/cachecanary.egg-info/SOURCES.txt +48 -0
- cachecanary-0.1.0/src/cachecanary.egg-info/dependency_links.txt +1 -0
- cachecanary-0.1.0/src/cachecanary.egg-info/entry_points.txt +2 -0
- cachecanary-0.1.0/src/cachecanary.egg-info/requires.txt +7 -0
- cachecanary-0.1.0/src/cachecanary.egg-info/top_level.txt +1 -0
- cachecanary-0.1.0/tests/fixtures/bedrock_invocation_logs_2026-10.json +500 -0
- cachecanary-0.1.0/tests/test_action.py +119 -0
- cachecanary-0.1.0/tests/test_cachecanary.py +281 -0
- cachecanary-0.1.0/tests/test_edge_cases.py +409 -0
- cachecanary-0.1.0/tests/test_github.py +132 -0
- cachecanary-0.1.0/tests/test_readme.py +45 -0
- cachecanary-0.1.0/tests/test_scripts_and_formats.py +245 -0
- cachecanary-0.1.0/tests/test_site.py +45 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
tests:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v7
|
|
20
|
+
- uses: actions/setup-python@v7
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
- run: python -m pip install --quiet -e ".[dev]"
|
|
24
|
+
- run: python -m pytest -q
|
|
25
|
+
|
|
26
|
+
action-selftest:
|
|
27
|
+
# Runs the GitHub Action from this repo exactly as users would (no AWS needed for lint/diff).
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v7
|
|
31
|
+
|
|
32
|
+
- name: lint on a good request (must pass)
|
|
33
|
+
uses: ./
|
|
34
|
+
with:
|
|
35
|
+
command: lint
|
|
36
|
+
args: examples/request_good.json
|
|
37
|
+
|
|
38
|
+
- name: lint on a too-short request (must fail)
|
|
39
|
+
id: lint_short
|
|
40
|
+
continue-on-error: true
|
|
41
|
+
uses: ./
|
|
42
|
+
with:
|
|
43
|
+
command: lint
|
|
44
|
+
args: examples/request_too_short.json
|
|
45
|
+
|
|
46
|
+
- name: diff of two requests with a changing date (must fail)
|
|
47
|
+
id: diff_changed
|
|
48
|
+
continue-on-error: true
|
|
49
|
+
uses: ./
|
|
50
|
+
with:
|
|
51
|
+
command: diff
|
|
52
|
+
args: examples/request_bad.json examples/request_next.json
|
|
53
|
+
|
|
54
|
+
- name: unknown command (must fail)
|
|
55
|
+
id: bad_command
|
|
56
|
+
continue-on-error: true
|
|
57
|
+
uses: ./
|
|
58
|
+
with:
|
|
59
|
+
command: nope
|
|
60
|
+
args: examples/request_good.json
|
|
61
|
+
|
|
62
|
+
- name: check expected failures
|
|
63
|
+
shell: bash
|
|
64
|
+
run: |
|
|
65
|
+
set -euo pipefail
|
|
66
|
+
for o in "${{ steps.lint_short.outcome }}" "${{ steps.diff_changed.outcome }}" "${{ steps.bad_command.outcome }}"; do
|
|
67
|
+
if [ "$o" != "failure" ]; then echo "::error::expected failure, got '$o'"; exit 1; fi
|
|
68
|
+
done
|
|
69
|
+
echo "All expected failures happened."
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
# Release to PyPI: push a tag like v0.1.0 (it must equal cachecanary.__version__).
|
|
4
|
+
# Dry run to TestPyPI: run this workflow manually ("Run workflow").
|
|
5
|
+
# Uses PyPI trusted publishing (OIDC): no API tokens or passwords are stored anywhere.
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
tags: ["v*.*.*"]
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v7
|
|
20
|
+
- uses: actions/setup-python@v7
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
- name: Install
|
|
24
|
+
run: python -m pip install --quiet -e ".[dev]" build twine
|
|
25
|
+
- name: Tests
|
|
26
|
+
run: python -m pytest -q
|
|
27
|
+
- name: Tag must match the package version
|
|
28
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
29
|
+
run: |
|
|
30
|
+
version=$(python -c "import cachecanary; print(cachecanary.__version__)")
|
|
31
|
+
if [ "$GITHUB_REF_NAME" != "v$version" ]; then
|
|
32
|
+
echo "::error::Tag $GITHUB_REF_NAME does not match package version $version"
|
|
33
|
+
exit 1
|
|
34
|
+
fi
|
|
35
|
+
- name: Build and check
|
|
36
|
+
run: |
|
|
37
|
+
python -m build
|
|
38
|
+
python -m twine check --strict dist/*
|
|
39
|
+
- uses: actions/upload-artifact@v7
|
|
40
|
+
with:
|
|
41
|
+
name: dist
|
|
42
|
+
path: dist/
|
|
43
|
+
if-no-files-found: error
|
|
44
|
+
|
|
45
|
+
publish-pypi:
|
|
46
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
47
|
+
needs: build
|
|
48
|
+
runs-on: ubuntu-latest
|
|
49
|
+
environment:
|
|
50
|
+
name: pypi
|
|
51
|
+
url: https://pypi.org/p/cachecanary
|
|
52
|
+
permissions:
|
|
53
|
+
id-token: write
|
|
54
|
+
steps:
|
|
55
|
+
- uses: actions/download-artifact@v8
|
|
56
|
+
with:
|
|
57
|
+
name: dist
|
|
58
|
+
path: dist/
|
|
59
|
+
- uses: pypa/gh-action-pypi-publish@v1.14.2
|
|
60
|
+
|
|
61
|
+
publish-testpypi:
|
|
62
|
+
if: github.event_name == 'workflow_dispatch'
|
|
63
|
+
needs: build
|
|
64
|
+
runs-on: ubuntu-latest
|
|
65
|
+
environment:
|
|
66
|
+
name: testpypi
|
|
67
|
+
url: https://test.pypi.org/p/cachecanary
|
|
68
|
+
permissions:
|
|
69
|
+
id-token: write
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/download-artifact@v8
|
|
72
|
+
with:
|
|
73
|
+
name: dist
|
|
74
|
+
path: dist/
|
|
75
|
+
- uses: pypa/gh-action-pypi-publish@v1.14.2
|
|
76
|
+
with:
|
|
77
|
+
repository-url: https://test.pypi.org/legacy/
|
|
@@ -0,0 +1,202 @@
|
|
|
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 reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and 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 [yyyy] [name of copyright owner]
|
|
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.
|
|
202
|
+
|
cachecanary-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cachecanary
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CacheCanary: know the moment your Claude prompt cache breaks on Amazon Bedrock, not when the bill arrives.
|
|
5
|
+
Author-email: Haris Farooq <harisf98@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Haarris/cachecanary
|
|
8
|
+
Project-URL: Source, https://github.com/Haarris/cachecanary
|
|
9
|
+
Project-URL: Issues, https://github.com/Haarris/cachecanary/issues
|
|
10
|
+
Keywords: claude,anthropic,amazon-bedrock,bedrock,prompt-caching,llm,cost,observability,ci
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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 :: Software Development :: Quality Assurance
|
|
22
|
+
Classifier: Topic :: System :: Monitoring
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
License-File: NOTICE
|
|
27
|
+
Provides-Extra: aws
|
|
28
|
+
Requires-Dist: boto3[crt]>=1.34; extra == "aws"
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
31
|
+
Requires-Dist: pyyaml>=6; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# CacheCanary
|
|
35
|
+
|
|
36
|
+
Know the moment your Claude prompt cache breaks on Amazon Bedrock, not when the bill arrives.
|
|
37
|
+
|
|
38
|
+
[](https://github.com/Haarris/cachecanary/actions/workflows/ci.yml)
|
|
39
|
+
[](https://github.com/Haarris/cachecanary/blob/main/LICENSE)
|
|
40
|
+
|
|
41
|
+
Cache reads on Bedrock cost about a tenth of normal input tokens, so a long system prompt or tool list gets a lot cheaper once it's cached. The catch is that caching fails quietly. Bump a library, switch to a new model ID, put today's date in the system prompt, or let your tools come out in a different order, and the cache stops hitting. Requests still return 200 and the answers are still right. You find out from the bill.
|
|
42
|
+
|
|
43
|
+
LiteLLM hit this in [July 2026](https://docs.litellm.ai/blog/bedrock-invoke-prompt-caching-incident). After an upgrade, Claude Code traffic on Bedrock went from about 90% cache hits to 25-45%, and daily spend went up 2-3x for six days before anyone noticed. Anthropic has a cache diagnostics feature, but it only works on their own API, not on Bedrock.
|
|
44
|
+
|
|
45
|
+
CacheCanary is a small CLI and GitHub Action for this. It checks your requests in CI, tells you why a request missed the cache, and reads your Bedrock logs to show hit rates in production.
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install cachecanary # lint, diff, logs (no AWS needed)
|
|
51
|
+
pip install "cachecanary[aws]" # adds probe, which calls Bedrock
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Try it
|
|
55
|
+
|
|
56
|
+
Save a request your app sends to Bedrock as JSON (Converse or InvokeModel format) and run:
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
$ cachecanary lint examples/request_bad.json
|
|
60
|
+
[warn] dynamic-in-prefix: Found ISO date text inside the cached prefix. If it changes per request, every call misses. (system[0])
|
|
61
|
+
|
|
62
|
+
$ cachecanary diff examples/request_bad.json examples/request_next.json
|
|
63
|
+
system-changed: The system prompt changed inside the cached prefix (look for dates, IDs or per-user text). (system[0])
|
|
64
|
+
|
|
65
|
+
$ cachecanary lint examples/request_good.json --model us.anthropic.claude-haiku-4-5-20251001-v1:0
|
|
66
|
+
[error] prefix-too-short: Prefix up to this checkpoint is ~1892 tokens; claude-haiku-4-5 needs at least 4096. The request succeeds but nothing is cached. (system[0])
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The last one is easy to miss. The same prompt caches fine on Sonnet 4.6 (minimum 1,024 tokens) and never caches on Haiku 4.5 (minimum 4,096).
|
|
70
|
+
|
|
71
|
+
## Commands
|
|
72
|
+
|
|
73
|
+
| Command | What it does | Fails (exit 1) when |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `lint request.json [--model ID]` | Checks one request for things that stop caching | it finds an error |
|
|
76
|
+
| `diff previous.json next.json` | Explains why the second request missed the first one's cache | the cached part changed |
|
|
77
|
+
| `probe request.json --model ID [--region R] [--stream]` | Sends the request twice and checks the second one read from cache | nothing was read from cache |
|
|
78
|
+
| `logs files... [--by model\|principal] [--min-hit 0.5]` | Hit rate per model or IAM principal from Bedrock invocation logs | a group is under the threshold |
|
|
79
|
+
|
|
80
|
+
Exit code 2 means it couldn't run at all (bad file, no model access, no AWS credentials). `--json` and `--github` go before the command.
|
|
81
|
+
|
|
82
|
+
## What it looks for
|
|
83
|
+
|
|
84
|
+
- Dates, times, UUIDs or user-specific text before the cache checkpoint.
|
|
85
|
+
- A cached prefix shorter than the model's minimum (512 to 4,096 tokens depending on the model).
|
|
86
|
+
- Tools listed in a different order, or a tool definition that changed. Tools come first, so this throws away the whole cache.
|
|
87
|
+
- More than about 20 new content blocks since the last checkpoint, which is common after many parallel tool calls. Bedrock only looks back that far.
|
|
88
|
+
- Model IDs or application inference profile ARNs that your library may not recognize, so it quietly stops sending cache markers.
|
|
89
|
+
- A switch between the Converse and InvokeModel APIs, which builds a different prompt.
|
|
90
|
+
- More than 4 checkpoints, an unknown TTL, or a 1-hour checkpoint after a 5-minute one.
|
|
91
|
+
- A plain-string `system` field in InvokeModel, which can't carry `cache_control`.
|
|
92
|
+
|
|
93
|
+
## GitHub Action
|
|
94
|
+
|
|
95
|
+
Problems show up as annotations on the pull request, plus a short table in the job summary.
|
|
96
|
+
|
|
97
|
+
```yaml
|
|
98
|
+
- uses: actions/checkout@v7
|
|
99
|
+
|
|
100
|
+
# Checks a saved request. No AWS needed.
|
|
101
|
+
- uses: Haarris/cachecanary@v0
|
|
102
|
+
with:
|
|
103
|
+
command: lint
|
|
104
|
+
args: tests/fixtures/agent_request.json --model us.anthropic.claude-sonnet-4-6
|
|
105
|
+
|
|
106
|
+
# Calls Bedrock. Set up AWS credentials first (for example with aws-actions/configure-aws-credentials and OIDC).
|
|
107
|
+
- uses: Haarris/cachecanary@v0
|
|
108
|
+
with:
|
|
109
|
+
command: probe
|
|
110
|
+
args: tests/fixtures/agent_request.json --model us.anthropic.claude-sonnet-4-6 --region us-west-2
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`args` takes the same arguments as the CLI, separated by spaces. Paths with spaces aren't supported.
|
|
114
|
+
|
|
115
|
+
## Production hit rates
|
|
116
|
+
|
|
117
|
+
Turn on [Bedrock model invocation logging](https://docs.aws.amazon.com/bedrock/latest/userguide/model-invocation-logging.html) to S3 or CloudWatch, then point `logs` at the files:
|
|
118
|
+
|
|
119
|
+
```text
|
|
120
|
+
$ cachecanary logs tests/fixtures/bedrock_invocation_logs_2026-10.json --min-hit 0.4
|
|
121
|
+
us.anthropic.claude-sonnet-4-6: hit 50% over 8 calls (read 11496, write 11496, uncached 80, unparsed 0)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
It reads S3 deliveries, CloudWatch exports and `aws logs filter-log-events` output, gzipped or not, including streamed responses. Bedrock logs InvokeModel calls under an inference profile ARN and Converse calls under the short model ID, so CacheCanary merges the two.
|
|
125
|
+
|
|
126
|
+
## Tested on real Bedrock
|
|
127
|
+
|
|
128
|
+
I ran the main cases against Amazon Bedrock in October 2026 using made-up prompts. The rest of the checks (checkpoint counts, TTL order, a plain-string `system`) follow the AWS documentation and are covered by unit tests.
|
|
129
|
+
|
|
130
|
+
- 11 of 11 scenarios behaved as expected: cache hits on Converse and InvokeModel, 5-minute and 1-hour TTLs, streaming, model minimums, a date in the system prompt, reordered tools, a model switch, and the 20-block lookback (3,097 tokens read from cache without an extra checkpoint, 5,121 with one).
|
|
131
|
+
- The log parser matched the token counts the API returned, for all four call types. The redacted log records are in [tests/fixtures](https://github.com/Haarris/cachecanary/tree/main/tests/fixtures).
|
|
132
|
+
|
|
133
|
+
You can rerun this in an AWS Region with no production traffic: `python scripts/live_test.py --region <region>`.
|
|
134
|
+
|
|
135
|
+
## Privacy
|
|
136
|
+
|
|
137
|
+
Everything runs on your machine or CI runner. Nothing is sent anywhere. `probe` only calls your own Bedrock endpoint with your own credentials.
|
|
138
|
+
|
|
139
|
+
## Limits
|
|
140
|
+
|
|
141
|
+
- Token counts in `lint` are estimates. On English text Bedrock counted about 11% more than CacheCanary did, so near a model's minimum it warns you and suggests running `probe`.
|
|
142
|
+
- Bedrock keeps cache counts inside the logged response body, and only bodies up to 100 KB are stored inline. Bigger ones show up as `unparsed`.
|
|
143
|
+
- Bedrock only for now.
|
|
144
|
+
|
|
145
|
+
## What's next
|
|
146
|
+
|
|
147
|
+
A hosted dashboard: cache hit rate and wasted spend per app, an alert when the rate drops, and the reason for each miss. It would run inside your own AWS account, so prompts never leave it. If you'd use that, email [hello@cachecanary.com](mailto:hello@cachecanary.com).
|
|
148
|
+
|
|
149
|
+
Vertex AI and LiteLLM support are also planned.
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
Apache 2.0. See [LICENSE](https://github.com/Haarris/cachecanary/blob/main/LICENSE). Copyright 2026 Haris Farooq.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# CacheCanary
|
|
2
|
+
|
|
3
|
+
Know the moment your Claude prompt cache breaks on Amazon Bedrock, not when the bill arrives.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/Haarris/cachecanary/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/Haarris/cachecanary/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Cache reads on Bedrock cost about a tenth of normal input tokens, so a long system prompt or tool list gets a lot cheaper once it's cached. The catch is that caching fails quietly. Bump a library, switch to a new model ID, put today's date in the system prompt, or let your tools come out in a different order, and the cache stops hitting. Requests still return 200 and the answers are still right. You find out from the bill.
|
|
9
|
+
|
|
10
|
+
LiteLLM hit this in [July 2026](https://docs.litellm.ai/blog/bedrock-invoke-prompt-caching-incident). After an upgrade, Claude Code traffic on Bedrock went from about 90% cache hits to 25-45%, and daily spend went up 2-3x for six days before anyone noticed. Anthropic has a cache diagnostics feature, but it only works on their own API, not on Bedrock.
|
|
11
|
+
|
|
12
|
+
CacheCanary is a small CLI and GitHub Action for this. It checks your requests in CI, tells you why a request missed the cache, and reads your Bedrock logs to show hit rates in production.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install cachecanary # lint, diff, logs (no AWS needed)
|
|
18
|
+
pip install "cachecanary[aws]" # adds probe, which calls Bedrock
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Try it
|
|
22
|
+
|
|
23
|
+
Save a request your app sends to Bedrock as JSON (Converse or InvokeModel format) and run:
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
$ cachecanary lint examples/request_bad.json
|
|
27
|
+
[warn] dynamic-in-prefix: Found ISO date text inside the cached prefix. If it changes per request, every call misses. (system[0])
|
|
28
|
+
|
|
29
|
+
$ cachecanary diff examples/request_bad.json examples/request_next.json
|
|
30
|
+
system-changed: The system prompt changed inside the cached prefix (look for dates, IDs or per-user text). (system[0])
|
|
31
|
+
|
|
32
|
+
$ cachecanary lint examples/request_good.json --model us.anthropic.claude-haiku-4-5-20251001-v1:0
|
|
33
|
+
[error] prefix-too-short: Prefix up to this checkpoint is ~1892 tokens; claude-haiku-4-5 needs at least 4096. The request succeeds but nothing is cached. (system[0])
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The last one is easy to miss. The same prompt caches fine on Sonnet 4.6 (minimum 1,024 tokens) and never caches on Haiku 4.5 (minimum 4,096).
|
|
37
|
+
|
|
38
|
+
## Commands
|
|
39
|
+
|
|
40
|
+
| Command | What it does | Fails (exit 1) when |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| `lint request.json [--model ID]` | Checks one request for things that stop caching | it finds an error |
|
|
43
|
+
| `diff previous.json next.json` | Explains why the second request missed the first one's cache | the cached part changed |
|
|
44
|
+
| `probe request.json --model ID [--region R] [--stream]` | Sends the request twice and checks the second one read from cache | nothing was read from cache |
|
|
45
|
+
| `logs files... [--by model\|principal] [--min-hit 0.5]` | Hit rate per model or IAM principal from Bedrock invocation logs | a group is under the threshold |
|
|
46
|
+
|
|
47
|
+
Exit code 2 means it couldn't run at all (bad file, no model access, no AWS credentials). `--json` and `--github` go before the command.
|
|
48
|
+
|
|
49
|
+
## What it looks for
|
|
50
|
+
|
|
51
|
+
- Dates, times, UUIDs or user-specific text before the cache checkpoint.
|
|
52
|
+
- A cached prefix shorter than the model's minimum (512 to 4,096 tokens depending on the model).
|
|
53
|
+
- Tools listed in a different order, or a tool definition that changed. Tools come first, so this throws away the whole cache.
|
|
54
|
+
- More than about 20 new content blocks since the last checkpoint, which is common after many parallel tool calls. Bedrock only looks back that far.
|
|
55
|
+
- Model IDs or application inference profile ARNs that your library may not recognize, so it quietly stops sending cache markers.
|
|
56
|
+
- A switch between the Converse and InvokeModel APIs, which builds a different prompt.
|
|
57
|
+
- More than 4 checkpoints, an unknown TTL, or a 1-hour checkpoint after a 5-minute one.
|
|
58
|
+
- A plain-string `system` field in InvokeModel, which can't carry `cache_control`.
|
|
59
|
+
|
|
60
|
+
## GitHub Action
|
|
61
|
+
|
|
62
|
+
Problems show up as annotations on the pull request, plus a short table in the job summary.
|
|
63
|
+
|
|
64
|
+
```yaml
|
|
65
|
+
- uses: actions/checkout@v7
|
|
66
|
+
|
|
67
|
+
# Checks a saved request. No AWS needed.
|
|
68
|
+
- uses: Haarris/cachecanary@v0
|
|
69
|
+
with:
|
|
70
|
+
command: lint
|
|
71
|
+
args: tests/fixtures/agent_request.json --model us.anthropic.claude-sonnet-4-6
|
|
72
|
+
|
|
73
|
+
# Calls Bedrock. Set up AWS credentials first (for example with aws-actions/configure-aws-credentials and OIDC).
|
|
74
|
+
- uses: Haarris/cachecanary@v0
|
|
75
|
+
with:
|
|
76
|
+
command: probe
|
|
77
|
+
args: tests/fixtures/agent_request.json --model us.anthropic.claude-sonnet-4-6 --region us-west-2
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`args` takes the same arguments as the CLI, separated by spaces. Paths with spaces aren't supported.
|
|
81
|
+
|
|
82
|
+
## Production hit rates
|
|
83
|
+
|
|
84
|
+
Turn on [Bedrock model invocation logging](https://docs.aws.amazon.com/bedrock/latest/userguide/model-invocation-logging.html) to S3 or CloudWatch, then point `logs` at the files:
|
|
85
|
+
|
|
86
|
+
```text
|
|
87
|
+
$ cachecanary logs tests/fixtures/bedrock_invocation_logs_2026-10.json --min-hit 0.4
|
|
88
|
+
us.anthropic.claude-sonnet-4-6: hit 50% over 8 calls (read 11496, write 11496, uncached 80, unparsed 0)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
It reads S3 deliveries, CloudWatch exports and `aws logs filter-log-events` output, gzipped or not, including streamed responses. Bedrock logs InvokeModel calls under an inference profile ARN and Converse calls under the short model ID, so CacheCanary merges the two.
|
|
92
|
+
|
|
93
|
+
## Tested on real Bedrock
|
|
94
|
+
|
|
95
|
+
I ran the main cases against Amazon Bedrock in October 2026 using made-up prompts. The rest of the checks (checkpoint counts, TTL order, a plain-string `system`) follow the AWS documentation and are covered by unit tests.
|
|
96
|
+
|
|
97
|
+
- 11 of 11 scenarios behaved as expected: cache hits on Converse and InvokeModel, 5-minute and 1-hour TTLs, streaming, model minimums, a date in the system prompt, reordered tools, a model switch, and the 20-block lookback (3,097 tokens read from cache without an extra checkpoint, 5,121 with one).
|
|
98
|
+
- The log parser matched the token counts the API returned, for all four call types. The redacted log records are in [tests/fixtures](https://github.com/Haarris/cachecanary/tree/main/tests/fixtures).
|
|
99
|
+
|
|
100
|
+
You can rerun this in an AWS Region with no production traffic: `python scripts/live_test.py --region <region>`.
|
|
101
|
+
|
|
102
|
+
## Privacy
|
|
103
|
+
|
|
104
|
+
Everything runs on your machine or CI runner. Nothing is sent anywhere. `probe` only calls your own Bedrock endpoint with your own credentials.
|
|
105
|
+
|
|
106
|
+
## Limits
|
|
107
|
+
|
|
108
|
+
- Token counts in `lint` are estimates. On English text Bedrock counted about 11% more than CacheCanary did, so near a model's minimum it warns you and suggests running `probe`.
|
|
109
|
+
- Bedrock keeps cache counts inside the logged response body, and only bodies up to 100 KB are stored inline. Bigger ones show up as `unparsed`.
|
|
110
|
+
- Bedrock only for now.
|
|
111
|
+
|
|
112
|
+
## What's next
|
|
113
|
+
|
|
114
|
+
A hosted dashboard: cache hit rate and wasted spend per app, an alert when the rate drops, and the reason for each miss. It would run inside your own AWS account, so prompts never leave it. If you'd use that, email [hello@cachecanary.com](mailto:hello@cachecanary.com).
|
|
115
|
+
|
|
116
|
+
Vertex AI and LiteLLM support are also planned.
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
Apache 2.0. See [LICENSE](https://github.com/Haarris/cachecanary/blob/main/LICENSE). Copyright 2026 Haris Farooq.
|