cohesion-sdk 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.
- cohesion_sdk-1.0.0/.gitignore +87 -0
- cohesion_sdk-1.0.0/CHANGELOG.md +21 -0
- cohesion_sdk-1.0.0/LICENSE +202 -0
- cohesion_sdk-1.0.0/MIGRATION.md +7 -0
- cohesion_sdk-1.0.0/NOTICE +7 -0
- cohesion_sdk-1.0.0/PKG-INFO +262 -0
- cohesion_sdk-1.0.0/PUBLISH.md +63 -0
- cohesion_sdk-1.0.0/README.md +226 -0
- cohesion_sdk-1.0.0/pyproject.toml +89 -0
- cohesion_sdk-1.0.0/src/cohesion/__init__.py +65 -0
- cohesion_sdk-1.0.0/src/cohesion/_version.py +8 -0
- cohesion_sdk-1.0.0/src/cohesion/cli.py +118 -0
- cohesion_sdk-1.0.0/src/cohesion/client.py +349 -0
- cohesion_sdk-1.0.0/src/cohesion/exceptions.py +262 -0
- cohesion_sdk-1.0.0/src/cohesion/langchain.py +117 -0
- cohesion_sdk-1.0.0/src/cohesion/logging.py +169 -0
- cohesion_sdk-1.0.0/src/cohesion/models.py +319 -0
- cohesion_sdk-1.0.0/src/cohesion/retry.py +58 -0
- cohesion_sdk-1.0.0/src/cohesion/telemetry.py +97 -0
- cohesion_sdk-1.0.0/src/cohesion/wrappers.py +171 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# ============================================================================
|
|
2
|
+
# COHESION — gitignore
|
|
3
|
+
# Principle: nothing sensitive or machine-specific gets committed.
|
|
4
|
+
# ============================================================================
|
|
5
|
+
|
|
6
|
+
# --- OS / editor cruft ------------------------------------------------------
|
|
7
|
+
.DS_Store
|
|
8
|
+
Thumbs.db
|
|
9
|
+
.obsidian/workspace.json
|
|
10
|
+
.obsidian/cache/
|
|
11
|
+
.vscode/
|
|
12
|
+
.idea/
|
|
13
|
+
|
|
14
|
+
# --- Logs -------------------------------------------------------------------
|
|
15
|
+
*.log
|
|
16
|
+
*.pid
|
|
17
|
+
*.seed
|
|
18
|
+
|
|
19
|
+
# --- Secrets / credentials (defense in depth) -------------------------------
|
|
20
|
+
.env
|
|
21
|
+
.env.*
|
|
22
|
+
*.env
|
|
23
|
+
!.env.example
|
|
24
|
+
secrets.json
|
|
25
|
+
secrets.local
|
|
26
|
+
credentials.json
|
|
27
|
+
credentials.local
|
|
28
|
+
*.key
|
|
29
|
+
*.pem
|
|
30
|
+
*.p12
|
|
31
|
+
*.pfx
|
|
32
|
+
*.crt
|
|
33
|
+
*.cer
|
|
34
|
+
*.der
|
|
35
|
+
|
|
36
|
+
# --- Cloudflare wrangler local caches (contain account id + geolocation) ---
|
|
37
|
+
.wrangler/
|
|
38
|
+
**/.wrangler/
|
|
39
|
+
|
|
40
|
+
# --- Claude Code per-machine tool allowlists (may contain demo keys) --------
|
|
41
|
+
**/.claude/settings.local.json
|
|
42
|
+
.claude/settings.local.json
|
|
43
|
+
|
|
44
|
+
# --- Claude worktrees (git manages these via .git/worktrees metadata) --------
|
|
45
|
+
.claude/worktrees/
|
|
46
|
+
**/.claude/worktrees/
|
|
47
|
+
|
|
48
|
+
# --- Dependencies -----------------------------------------------------------
|
|
49
|
+
node_modules/
|
|
50
|
+
.venv/
|
|
51
|
+
venv/
|
|
52
|
+
__pycache__/
|
|
53
|
+
*.pyc
|
|
54
|
+
|
|
55
|
+
# --- Test / coverage / build artifacts --------------------------------------
|
|
56
|
+
coverage/
|
|
57
|
+
test-results/
|
|
58
|
+
playwright-report/
|
|
59
|
+
*.lcov
|
|
60
|
+
.nyc_output/
|
|
61
|
+
.coverage
|
|
62
|
+
.coverage.*
|
|
63
|
+
.pytest_cache/
|
|
64
|
+
.ruff_cache/
|
|
65
|
+
htmlcov/
|
|
66
|
+
.tox/
|
|
67
|
+
.mypy_cache/
|
|
68
|
+
|
|
69
|
+
# --- Lighthouse CI ----------------------------------------------------------
|
|
70
|
+
.lighthouseci/
|
|
71
|
+
.lhci-chrome-profile/
|
|
72
|
+
.lhci-tmp/
|
|
73
|
+
website/.lighthouseci/
|
|
74
|
+
website/.lhci-chrome-profile/
|
|
75
|
+
website/.lhci-tmp/
|
|
76
|
+
lighthouse-*.json
|
|
77
|
+
|
|
78
|
+
# --- Local scratch / deploy staging -----------------------------------------
|
|
79
|
+
.deploy-stage/
|
|
80
|
+
.deploy-prod/
|
|
81
|
+
.superpowers/
|
|
82
|
+
|
|
83
|
+
# --- Backup + swap files ----------------------------------------------------
|
|
84
|
+
*.bak
|
|
85
|
+
*.swp
|
|
86
|
+
*.swo
|
|
87
|
+
*~
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `cohesion-sdk` (Python) are documented here. Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-04-22
|
|
6
|
+
|
|
7
|
+
Initial public release.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- `Client` with the 9 locked methods covering all 13 API endpoints (6 scoring, 3 admin; 2 public-demo endpoints remain REST-only).
|
|
11
|
+
- Typed error taxonomy: `CohesionError`, `AuthenticationError`, `RateLimitError`, `ValidationError`, `ServerError`, `NetworkError`. Every error carries `request_id` and `next_step`.
|
|
12
|
+
- Pydantic v2 request/response models for every endpoint.
|
|
13
|
+
- Exponential backoff with full jitter (max 3 retries, 429 + 5xx only, honors RFC-7231 `Retry-After`).
|
|
14
|
+
- Auto-generated `Idempotency-Key` header on every POST (override via kwarg).
|
|
15
|
+
- `User-Agent: cohesion-sdk-python/{version}`.
|
|
16
|
+
- Deny-list log redaction for API keys and `operator_id` values. JSON format when `COHESION_LOG_FORMAT=json`.
|
|
17
|
+
- Opt-in Sentry telemetry with PII scrubber.
|
|
18
|
+
- Provider wrappers: `wrap_openai`, `wrap_anthropic`, `wrap_azure_openai`.
|
|
19
|
+
- LangChain callback handler `LangChainCallback`.
|
|
20
|
+
- `cohesion` CLI (`cohesion score --operator-id X --from-file y.json`, `-` for stdin).
|
|
21
|
+
- SBOM generation documented in `PUBLISH.md`.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Migration Guide
|
|
2
|
+
|
|
3
|
+
## Migrating to 1.0.0
|
|
4
|
+
|
|
5
|
+
`cohesion-sdk` 1.0.0 is the initial public release. There is no prior published version; nothing to migrate.
|
|
6
|
+
|
|
7
|
+
Future major versions will document their breaking changes here, alongside `Deprecation` and `Sunset` response headers emitted by the API for 12 months before removal.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
COHESION cohesion-sdk (Python)
|
|
2
|
+
Copyright 2026 COHESION AUTH LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0.
|
|
5
|
+
|
|
6
|
+
The COHESION Judgment Independence Score methodology, scoring engine, and
|
|
7
|
+
intervention protocol are subject to provisional patent filed 2026-04-13.
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cohesion-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for the COHESION Judgment Independence Score API.
|
|
5
|
+
Project-URL: Homepage, https://cohesionauth.com
|
|
6
|
+
Project-URL: Documentation, https://cohesionauth.com/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/peytonflockk-web/cohesion-launch
|
|
8
|
+
Project-URL: Issues, https://github.com/peytonflockk-web/cohesion-launch/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/peytonflockk-web/cohesion-launch/blob/main/sdk/python/CHANGELOG.md
|
|
10
|
+
Author-email: COHESION AUTH LLC <dev@cohesionauth.com>
|
|
11
|
+
License: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: NOTICE
|
|
14
|
+
Keywords: ai-oversight,article-14,cohesion,eu-ai-act,human-oversight,judgment-independence-score
|
|
15
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: httpx>=0.27
|
|
25
|
+
Requires-Dist: pydantic>=2.6
|
|
26
|
+
Requires-Dist: typing-extensions>=4.9
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-cov>=4.1; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-httpx>=0.30; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
33
|
+
Provides-Extra: telemetry
|
|
34
|
+
Requires-Dist: sentry-sdk>=2.0; extra == 'telemetry'
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# cohesion-sdk (Python)
|
|
38
|
+
|
|
39
|
+
Official Python SDK for the COHESION Judgment Independence Score API.
|
|
40
|
+
|
|
41
|
+
COHESION is the global certification standard for human oversight of AI. The API scores whether humans are genuinely exercising judgment over AI outputs, and produces the compliance proof regulators require (EU AI Act Article 14, Colorado SB 205, NYC Local Law 144, SR 11-7).
|
|
42
|
+
|
|
43
|
+
Full product documentation: https://cohesionauth.com/docs
|
|
44
|
+
API reference: https://cohesionauth.com/api
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install cohesion-sdk
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Requires Python 3.11 or newer.
|
|
53
|
+
|
|
54
|
+
## Quickstart
|
|
55
|
+
|
|
56
|
+
Get a key at https://cohesionauth.com/dashboard/api-keys, then:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from cohesion import Client
|
|
60
|
+
|
|
61
|
+
client = Client(api_key="ck_live_...your_key...")
|
|
62
|
+
|
|
63
|
+
response = client.score(
|
|
64
|
+
session_id="sess-001",
|
|
65
|
+
operator_id="analyst-42",
|
|
66
|
+
domain="financial",
|
|
67
|
+
interaction={
|
|
68
|
+
"ai_recommendation_presented": True,
|
|
69
|
+
"time_to_decision_ms": 1800,
|
|
70
|
+
"decision": "modified",
|
|
71
|
+
"modification_extent": 0.3,
|
|
72
|
+
"ai_available": True,
|
|
73
|
+
"scenario_type": "standard",
|
|
74
|
+
"outcome_correct": None,
|
|
75
|
+
"hover_events": 2,
|
|
76
|
+
"scroll_depth": 0.7,
|
|
77
|
+
"alternative_views_checked": 1,
|
|
78
|
+
},
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
print(response.jis, response.band)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Same call, three languages
|
|
85
|
+
|
|
86
|
+
### cURL
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
curl -X POST https://api.cohesionauth.com/v1/score \
|
|
90
|
+
-H "X-API-Key: ck_live_...your_key..." \ # gitleaks:allow (placeholder in doc example)
|
|
91
|
+
-H "Content-Type: application/json" \
|
|
92
|
+
-d '{
|
|
93
|
+
"session_id": "sess-001",
|
|
94
|
+
"operator_id": "analyst-42",
|
|
95
|
+
"domain": "financial",
|
|
96
|
+
"interaction": {
|
|
97
|
+
"ai_recommendation_presented": true,
|
|
98
|
+
"time_to_decision_ms": 1800,
|
|
99
|
+
"decision": "modified",
|
|
100
|
+
"modification_extent": 0.3,
|
|
101
|
+
"ai_available": true,
|
|
102
|
+
"scenario_type": "standard",
|
|
103
|
+
"outcome_correct": null,
|
|
104
|
+
"hover_events": 2,
|
|
105
|
+
"scroll_depth": 0.7,
|
|
106
|
+
"alternative_views_checked": 1
|
|
107
|
+
}
|
|
108
|
+
}'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Python
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from cohesion import Client
|
|
115
|
+
client = Client(api_key="ck_live_...your_key...")
|
|
116
|
+
resp = client.score(session_id="sess-001", operator_id="analyst-42", domain="financial", interaction={...})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### TypeScript
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { Cohesion } from "@cohesion/sdk";
|
|
123
|
+
const client = new Cohesion({ apiKey: "ck_live_...your_key..." });
|
|
124
|
+
const resp = await client.score({ session_id: "sess-001", operator_id: "analyst-42", domain: "financial", interaction: {...} });
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Client surface
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
client = Client(
|
|
131
|
+
api_key: str, # required
|
|
132
|
+
base_url: str = "https://api.cohesionauth.com",
|
|
133
|
+
timeout: float = 30.0,
|
|
134
|
+
max_retries: int = 3,
|
|
135
|
+
logger: logging.Logger | None = None,
|
|
136
|
+
enable_telemetry: bool = False,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
client.score(**kwargs) # POST /v1/score
|
|
140
|
+
client.score_batch(interactions) # POST /v1/score/batch (<= 100 per call)
|
|
141
|
+
client.operator_profile(operator_id) # GET /v1/operator/:id/profile
|
|
142
|
+
client.organization_dashboard() # GET /v1/organization/dashboard
|
|
143
|
+
client.maintenance_recommend(**kwargs) # POST /v1/maintenance/recommend
|
|
144
|
+
client.compliance_report() # GET /v1/compliance/report
|
|
145
|
+
client.admin_key_rotate() # POST /v1/admin/key/rotate
|
|
146
|
+
client.admin_key_revoke() # POST /v1/admin/key/revoke
|
|
147
|
+
client.admin_audit_log(event_type=None, since=None, until=None, limit=100)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Provider wrappers
|
|
151
|
+
|
|
152
|
+
Wrap any OpenAI, Anthropic, or Azure OpenAI client to emit oversight telemetry for free.
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from openai import OpenAI
|
|
156
|
+
from cohesion import Client, WrapContext, DecisionReport, wrap_openai
|
|
157
|
+
|
|
158
|
+
cohesion = Client(api_key="ck_live_...")
|
|
159
|
+
openai_client = OpenAI()
|
|
160
|
+
wrapped = wrap_openai(
|
|
161
|
+
openai_client,
|
|
162
|
+
cohesion,
|
|
163
|
+
WrapContext(operator_id="analyst-42", session_id="sess-001", domain="financial"),
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
completion = wrapped.chat.completions.create(model="gpt-4", messages=[...])
|
|
167
|
+
# Your app logic: analyst reviews the AI suggestion and commits a decision
|
|
168
|
+
completion.record_decision(DecisionReport(decision="modified", modification_extent=0.3))
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
LangChain users:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from cohesion import LangChainCallback
|
|
175
|
+
cb = LangChainCallback(
|
|
176
|
+
client=cohesion,
|
|
177
|
+
operator_id="analyst-42",
|
|
178
|
+
session_id="sess-001",
|
|
179
|
+
domain="financial",
|
|
180
|
+
)
|
|
181
|
+
chain.invoke(inputs, config={"callbacks": [cb]})
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## CLI
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
export COHESION_API_KEY=ck_live_...your_key...
|
|
188
|
+
cohesion score --operator-id analyst-42 --from-file payload.json
|
|
189
|
+
|
|
190
|
+
# Read payload from stdin:
|
|
191
|
+
cat payload.json | cohesion score --operator-id analyst-42 --from-file -
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Errors
|
|
195
|
+
|
|
196
|
+
Every exception carries:
|
|
197
|
+
- `request_id` (from the API response, None for local validation)
|
|
198
|
+
- `next_step` (actionable remediation; None when the SDK cannot know what to do)
|
|
199
|
+
|
|
200
|
+
| Exception | When it fires | `next_step` populated |
|
|
201
|
+
|---|---|---|
|
|
202
|
+
| `AuthenticationError` | HTTP 401 | Yes. Names the dashboard URL and rotation path. |
|
|
203
|
+
| `RateLimitError` | HTTP 429 | Yes. "Retry after N seconds." `retry_after` field also set. |
|
|
204
|
+
| `ValidationError` | HTTP 400/413/422 or local checks | Yes when `field` is known: "`field` must be one of: ..." |
|
|
205
|
+
| `ServerError` | HTTP 5xx | No (not actionable client-side) |
|
|
206
|
+
| `NetworkError` | Transport / timeout | Yes when resolvable (connectivity, TLS egress). |
|
|
207
|
+
| `CohesionError` | Base class | Depends |
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from cohesion import CohesionError, RateLimitError
|
|
211
|
+
|
|
212
|
+
try:
|
|
213
|
+
client.score(...)
|
|
214
|
+
except RateLimitError as err:
|
|
215
|
+
print(err.next_step, err.retry_after, err.request_id)
|
|
216
|
+
except CohesionError as err:
|
|
217
|
+
print(err.next_step, err.request_id)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Retry and idempotency
|
|
221
|
+
|
|
222
|
+
- Exponential backoff with full jitter, max 3 attempts by default (`max_retries`).
|
|
223
|
+
- Retries on 429 and 5xx only. Honors RFC-7231 `Retry-After` (integer seconds or HTTP-date).
|
|
224
|
+
- Every POST auto-generates an `Idempotency-Key` header (UUIDv4) so safe retries do not create duplicate records.
|
|
225
|
+
|
|
226
|
+
## Logging and redaction
|
|
227
|
+
|
|
228
|
+
The SDK logs under the `cohesion` logger at INFO by default. JSON format when `COHESION_LOG_FORMAT=json`. A deny-list filter redacts:
|
|
229
|
+
- Any string matching `ck_live_[A-Za-z0-9]+` (replaced with `ck_live_[redacted]`)
|
|
230
|
+
- Any record field whose key is one of: `api_key`, `x-api-key`, `authorization`, `operator_id`, `new_api_key`
|
|
231
|
+
|
|
232
|
+
API keys and operator_id values never reach the log sink.
|
|
233
|
+
|
|
234
|
+
## Opt-in telemetry
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
client = Client(api_key="...", enable_telemetry=True)
|
|
238
|
+
# Requires: pip install cohesion-sdk[telemetry]
|
|
239
|
+
# And set COHESION_SENTRY_DSN or SENTRY_DSN.
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Only SDK-level errors are reported. The PII scrubber strips request body, headers, and operator_id fields.
|
|
243
|
+
|
|
244
|
+
## Environment variables
|
|
245
|
+
|
|
246
|
+
| Var | Purpose |
|
|
247
|
+
|---|---|
|
|
248
|
+
| `COHESION_API_KEY` | Picked up by the CLI (not by `Client()` directly) |
|
|
249
|
+
| `COHESION_BASE_URL` | Override base URL |
|
|
250
|
+
| `COHESION_TEST_API_KEY` | Gates the `pytest -m integration` live test |
|
|
251
|
+
| `COHESION_LOG_FORMAT` | Set to `json` for JSON logs |
|
|
252
|
+
| `COHESION_SENTRY_DSN` | Overrides `SENTRY_DSN` when telemetry is enabled |
|
|
253
|
+
|
|
254
|
+
## Versioning and support
|
|
255
|
+
|
|
256
|
+
Semver. Breaking changes ship with a 12-month notice via `Deprecation` + `Sunset` response headers. See [CHANGELOG.md](./CHANGELOG.md).
|
|
257
|
+
|
|
258
|
+
Security issues: `security@cohesionauth.com`.
|
|
259
|
+
|
|
260
|
+
## License
|
|
261
|
+
|
|
262
|
+
Apache-2.0. See `LICENSE` and `NOTICE`.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Publishing cohesion-sdk to PyPI
|
|
2
|
+
|
|
3
|
+
This document describes how to manually cut a new release to PyPI. Do NOT execute any of these commands from a CI job without explicit authorization. The `publish-sdk.yml` workflow is disabled by default and gated on the repo owner.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Python 3.11+ locally.
|
|
8
|
+
- `pip install --upgrade build twine`.
|
|
9
|
+
- A PyPI account with maintainer rights on the `cohesion-sdk` project.
|
|
10
|
+
- A `~/.pypirc` configured with a scoped API token, or use `twine upload --username __token__`.
|
|
11
|
+
|
|
12
|
+
## Build
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
cd sdk/python
|
|
16
|
+
rm -rf dist build
|
|
17
|
+
python -m build
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`python -m build` produces a wheel and an sdist under `sdk/python/dist/`.
|
|
21
|
+
|
|
22
|
+
## Verify locally before upload
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
python -m pip install --force-reinstall dist/cohesion_sdk-<version>-py3-none-any.whl
|
|
26
|
+
python -c "from cohesion import Client, __version__; print(__version__)"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## SBOM
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install cyclonedx-bom
|
|
33
|
+
cyclonedx-py requirements -o sbom.json
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Commit `sbom.json` alongside the release.
|
|
37
|
+
|
|
38
|
+
## Upload to Test PyPI first
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
twine upload --repository testpypi dist/*
|
|
42
|
+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ cohesion-sdk==<version>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Smoke-test end-to-end before the real upload.
|
|
46
|
+
|
|
47
|
+
## Upload to PyPI
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
twine upload dist/*
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Post-release
|
|
54
|
+
|
|
55
|
+
1. Tag the commit: `git tag -a python-sdk-v<version> -m "cohesion-sdk Python v<version>"` then `git push origin python-sdk-v<version>`.
|
|
56
|
+
2. Cut a GitHub Release, paste the `CHANGELOG.md` entry as the release notes.
|
|
57
|
+
3. Verify `pip install cohesion-sdk==<version>` resolves within 5 minutes on a clean machine.
|
|
58
|
+
4. Update `sdk/python/CHANGELOG.md` for the next development cycle.
|
|
59
|
+
|
|
60
|
+
## Never do this from automation
|
|
61
|
+
|
|
62
|
+
- Do not store PyPI tokens in environment variables that any shared workflow can read.
|
|
63
|
+
- Do not auto-publish on tag push. The release is a manual human gate.
|