HTTP client for the CounterAudit audit ingest API
Project description
counteraudit
Python client for the CounterAudit API. Requires Python 3.8+.
Install
pip install counteraudit
Usage
import os
from counteraudit import CounterAuditClient, CounterAuditError
# Initialize client
client = CounterAuditClient(
base_url="https://api.counteraudit.io",
api_key=os.environ["COUNTERAUDIT_API_KEY"],
timeout=30, # optional (seconds)
max_retries=2 # optional (transient 429/5xx retry budget)
)
# Health check
print(client.health())
# {'ok': True, 'service': 'counteraudit-api', 'version': '0.8.0'}
# Ingest an event
result = client.ingest(
connector_id="langchain-v0.3",
raw_event={
"run_id": "run-1",
"model_id": "gpt-4o",
"input": "hello"
}
)
print(result["packet_id"], result["entry_hash"])
# Verify a packet
verification = client.verify(result["packet_id"])
print(verification["valid"]) # True
print(verification["rfc3161_verified"])
# Get agentic debt metrics
debt = client.dashboard_debt(days=30)
print(debt["agentic_debt_index"])
print(debt["by_connector"])
# List packets (paginated)
page = client.list_packets(limit=20)
print(len(page["packets"]))
if page["next_cursor"]:
next_page = client.list_packets(cursor=page["next_cursor"])
# Proof-first wrappers (v1 naming)
record = client.proof.record(
connector_id="langchain-v0.3",
raw_event={"run_id": "run-2", "model_id": "gpt-4o", "input": "proof wrapper"}
)
verified = client.proof.verify(record["packet_id"])
chain = client.proof.chain_verify(org_id=os.environ.get("COUNTERAUDIT_ORG_ID", "00000000-0000-4000-8000-000000000001"))
exported = client.proof.export(limit=10)
print(verified["valid"], chain["valid"], exported["count"])
Context manager
with CounterAuditClient(base_url="...", api_key="...") as client:
health = client.health()
print(health)
# Session automatically closed
Error handling
try:
client.verify("invalid-packet-id")
except CounterAuditError as e:
print(f"Error {e.status_code}: {e.message}")
print(f"Code: {e.error_code}, Request-ID: {e.request_id}")
print(e.body) # Full error response
Reliability behavior
- configurable request timeout (
timeout) - transient retry policy (
max_retries) on429/5xx - richer error fields on
CounterAuditError:status_codeerror_coderequest_idbody
API Reference
| Method | Maps to | Returns |
|---|---|---|
health() |
GET /health |
Health dict |
ingest(connector_id, raw_event, org_id=None) |
POST /v1/audit/ingest |
Ingest result |
verify(packet_id) |
GET /v1/audit/verify/:id |
Verification result |
chain(org_id) |
GET /v1/audit/chain/:org_id |
Chain summary |
list_packets(limit=None, cursor=None) |
GET /v1/audit/packets |
Paginated list |
proof.record(connector_id, raw_event, org_id=None) |
POST /v1/audit/ingest |
Ingest result |
proof.verify(packet_id) |
GET /v1/audit/verify/:id |
Verification result |
proof.chain_verify(org_id) |
GET /v1/audit/chain/:org_id |
Chain summary |
proof.export(limit=None, cursor=None) |
GET /v1/audit/packets |
Paginated list |
list_connectors() |
GET /v1/connectors |
Connectors list |
register_connector(...) |
POST /v1/connectors/register |
Created connector |
update_connector(id, field_map=None, risk_defaults=None) |
PATCH /v1/connectors/:id |
Updated connector |
delete_connector(connector_id) |
DELETE /v1/connectors/:id |
None |
list_keys() |
GET /v1/keys |
Keys list (masked) |
create_key(label=None) |
POST /v1/keys |
Created key (plaintext once) |
delete_key(key_id) |
DELETE /v1/keys/:id |
None |
dashboard_debt(days=None) |
GET /v1/dashboard/debt |
Debt summary |
Development
From the monorepo:
cd packages/counteraudit-py
pip install -e .
License
MIT — see LICENSE in the repository root.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
counteraudit-0.1.1.tar.gz
(8.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file counteraudit-0.1.1.tar.gz.
File metadata
- Download URL: counteraudit-0.1.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53496f8f54900055399d0006de17e795d8a35379cb67d8fe195b862221d5f6d1
|
|
| MD5 |
290461cc69b8cb07d2b6534b2cec7a26
|
|
| BLAKE2b-256 |
0249f7f0bd27f8e256da0efdb4ba024e7ccf6445dabe0790925fdf0c3d73a5ae
|
File details
Details for the file counteraudit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: counteraudit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48e7840a97e981e55fd803418d8e80e9945f08f4b0945ccaf93740e53b0bbd9b
|
|
| MD5 |
2256af484a38bbb2d9ba432659fd22f6
|
|
| BLAKE2b-256 |
f410046ada274cf657f36a60d158ba16819a59431adcc8ebe520a9a5280d2f6e
|