conseel 0.5.0__py3-none-any.whl

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.
conseel/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from conseel.transport import Transport, AsyncTransport
2
+
3
+ __all__ = ["Transport", "AsyncTransport"]
conseel/transport.py ADDED
@@ -0,0 +1,84 @@
1
+ """Encrypted httpx transports for AI APIs.
2
+
3
+ Extends tng.Transport with Cohere-specific defaults (ITA attestation,
4
+ header forwarding) and automatic model-name header promotion from JSON
5
+ request bodies.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import copy
11
+ import json
12
+ from typing import Optional
13
+
14
+ import httpx
15
+
16
+ import cohere_tng as tng
17
+
18
+ _MODEL_HEADER = "x-gateway-model-name"
19
+
20
+ _DEFAULT_FORWARD_HEADERS: list = ["authorization", _MODEL_HEADER]
21
+
22
+ _DEFAULT_VERIFY: dict = {
23
+ "model": "passport",
24
+ "as_provider": "ita",
25
+ "ita_jwks_addr": "https://portal.trustauthority.intel.com",
26
+ "policy_ids": ["cbeedffa-e224-4664-b6b4-573fcd4133d3"],
27
+ }
28
+
29
+ _UNSET = object()
30
+
31
+
32
+ def _should_extract_model(request: httpx.Request) -> bool:
33
+ if _MODEL_HEADER in request.headers:
34
+ return False
35
+ return "json" in request.headers.get("content-type", "")
36
+
37
+
38
+ def _promote_model_from_body(request: httpx.Request, body: bytes) -> None:
39
+ if not body:
40
+ return
41
+ try:
42
+ model = json.loads(body).get("model")
43
+ if model:
44
+ request.headers[_MODEL_HEADER] = str(model)
45
+ except (json.JSONDecodeError, AttributeError):
46
+ pass
47
+
48
+
49
+ class Transport(tng.Transport):
50
+ def __init__(
51
+ self,
52
+ *,
53
+ verify: Optional[dict] = _UNSET,
54
+ ohttp: Optional[dict] = None,
55
+ ):
56
+ if verify is _UNSET:
57
+ verify = copy.deepcopy(_DEFAULT_VERIFY)
58
+ ohttp = dict(ohttp) if ohttp else {}
59
+ ohttp.setdefault("forward_headers", list(_DEFAULT_FORWARD_HEADERS))
60
+ super().__init__(verify=verify, ohttp=ohttp)
61
+
62
+ def handle_request(self, request: httpx.Request) -> httpx.Response:
63
+ if _should_extract_model(request):
64
+ _promote_model_from_body(request, request.read())
65
+ return super().handle_request(request)
66
+
67
+
68
+ class AsyncTransport(tng.AsyncTransport):
69
+ def __init__(
70
+ self,
71
+ *,
72
+ verify: Optional[dict] = _UNSET,
73
+ ohttp: Optional[dict] = None,
74
+ ):
75
+ if verify is _UNSET:
76
+ verify = copy.deepcopy(_DEFAULT_VERIFY)
77
+ ohttp = dict(ohttp) if ohttp else {}
78
+ ohttp.setdefault("forward_headers", list(_DEFAULT_FORWARD_HEADERS))
79
+ super().__init__(verify=verify, ohttp=ohttp)
80
+
81
+ async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
82
+ if _should_extract_model(request):
83
+ _promote_model_from_body(request, await request.aread())
84
+ return await super().handle_async_request(request)
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: conseel
3
+ Version: 0.5.0
4
+ Summary: Drop-in encrypted transport for AI SDKs
5
+ Author-email: Cohere <support@cohere.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/cohere-ai/tng
8
+ Project-URL: Repository, https://github.com/cohere-ai/tng
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: cohere-tng
12
+ Requires-Dist: httpx>=0.23.0
13
+
14
+ # conseel
15
+
16
+ Drop-in encrypted transport for AI SDKs. Wraps [cohere-tng](https://pypi.org/project/cohere-tng/) to route
17
+ requests through OHTTP encryption with TEE attestation verification, and
18
+ automatically promotes the `model` field from JSON request bodies into an
19
+ `x-gateway-model-name` header for backend routing.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pip install conseel
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Cohere
30
+
31
+ ```python
32
+ import cohere
33
+ import httpx
34
+ from conseel import Transport
35
+
36
+ co = cohere.ClientV2(
37
+ api_key="...",
38
+ httpx_client=httpx.Client(transport=Transport()),
39
+ )
40
+ co.chat(model="command-a-plus-05-2026", messages=[...])
41
+ ```
42
+
43
+ ### OpenAI
44
+
45
+ ```python
46
+ from openai import OpenAI
47
+ import httpx
48
+ from conseel import Transport
49
+
50
+ client = OpenAI(
51
+ http_client=httpx.Client(transport=Transport()),
52
+ )
53
+ client.chat.completions.create(model="gpt-4", messages=[...])
54
+ ```
55
+
56
+ ### Async
57
+
58
+ ```python
59
+ import httpx
60
+ from conseel import AsyncTransport
61
+
62
+ async with httpx.AsyncClient(transport=AsyncTransport()) as client:
63
+ resp = await client.post(url, json={"model": "command-a-plus-05-2026", ...})
64
+ ```
65
+
66
+ ## What it does
67
+
68
+ 1. **Encrypts** all traffic via OHTTP so that even the network infrastructure
69
+ cannot inspect request or response payloads.
70
+ 2. **Verifies** the remote TEE via Intel Trust Authority attestation before
71
+ sending any data (configurable via the `verify` parameter).
72
+ 3. **Extracts** the `model` field from JSON request bodies and sets it as the
73
+ `x-gateway-model-name` HTTP header for gateway routing. Non-JSON requests
74
+ (e.g. multipart audio uploads) are streamed through without inspection.
75
+ 4. **Forwards** `authorization` and `x-gateway-model-name` headers through the
76
+ OHTTP layer to the backend.
77
+
78
+ ## Configuration
79
+
80
+ `Transport` and `AsyncTransport` accept the same `verify` and `ohttp` keyword
81
+ arguments as `cohere_tng.Transport` (see [TNG configuration docs](https://github.com/cohere-ai/tng/blob/cohere/docs/configuration.md)
82
+ for the full schema). The only difference is that `conseel` provides sensible
83
+ defaults:
84
+
85
+ - **`verify`** — Defaults to Intel Trust Authority attestation. Pass `None` to
86
+ disable verification (not recommended for production).
87
+ - **`ohttp`** — Defaults include forwarding `authorization` and
88
+ `x-gateway-model-name` headers.
@@ -0,0 +1,8 @@
1
+ conseel/__init__.py,sha256=DJFz3rj-oNVxfguDgIARmS7Kkj2Cu8u2_H8Pxx2ubFQ,99
2
+ conseel/transport.py,sha256=tQarLnevZvTXeX01ODrMEWSnTw0buTnGYwjyp3Z5pu0,2477
3
+ conseel-0.5.0.dist-info/METADATA,sha256=uLF8qHfsXFWhEvH-rRofY_7FJE-TVyS848xgReIM71A,2640
4
+ conseel-0.5.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ conseel-0.5.0.dist-info/scm_file_list.json,sha256=DQdOFCU3IrJWc_osNpHdnKLm799WLQ0lU7SJS7hIezw,122
6
+ conseel-0.5.0.dist-info/scm_version.json,sha256=jKeuu9N9hw_EVL0ide7BofACcmszToN6BYZ52yJ-UKw,160
7
+ conseel-0.5.0.dist-info/top_level.txt,sha256=ls9yohhlR0r4eY70dV7sWwj5ivFpVK6wpLIjoNnhJZw,8
8
+ conseel-0.5.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,8 @@
1
+ {
2
+ "files": [
3
+ "README.md",
4
+ "pyproject.toml",
5
+ "src/conseel/__init__.py",
6
+ "src/conseel/transport.py"
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "0.5.0",
3
+ "distance": 0,
4
+ "node": "g1d6b24e94444392b42ad3732b12b6c182bee69b6",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-07-03"
8
+ }
@@ -0,0 +1 @@
1
+ conseel