Skip to main content

chutes-e2ee

End-to-end encrypted transport for Chutes AI, designed as a drop-in httpx transport for the OpenAI Python SDK.

Requests are encrypted client-side using ML-KEM-768 + HKDF-SHA256 + ChaCha20-Poly1305 so that neither the API relay nor any intermediary can read the payload — only the GPU instance running your model sees the plaintext.

Installation

pip install chutes-e2ee

Quick Start

Synchronous (OpenAI)

import httpx
from openai import OpenAI
from chutes_e2ee import ChutesE2EETransport

API_KEY = "cpk_..."

client = OpenAI(
    api_key=API_KEY,
    base_url="https://llm.chutes.ai/v1",
    http_client=httpx.Client(
        transport=ChutesE2EETransport(api_key=API_KEY, api_base="https://llm.chutes.ai"),
    ),
)

response = client.chat.completions.create(
    model="zai-org/GLM-4.7-TEE",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

Async (AsyncOpenAI)

import httpx
from openai import AsyncOpenAI
from chutes_e2ee import AsyncChutesE2EETransport

API_KEY = "cpk_..."

client = AsyncOpenAI(
    api_key=API_KEY,
    base_url="https://llm.chutes.ai/v1",
    http_client=httpx.AsyncClient(
        transport=AsyncChutesE2EETransport(api_key=API_KEY, api_base="https://llm.chutes.ai"),
    ),
)

response = await client.chat.completions.create(
    model="zai-org/GLM-4.7-TEE",
    messages=[{"role": "user", "content": "Hello!"}],
)

Streaming

Streaming works transparently — the transport decrypts chunks on-the-fly:

stream = client.chat.completions.create(
    model="zai-org/GLM-4.7-TEE",
    messages=[{"role": "user", "content": "Count to 10"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

How It Works

The transport intercepts requests at the httpx layer — completely invisible to the OpenAI SDK:

  1. Outbound: Parses the JSON body, discovers E2EE-capable instances (caching pubkeys + nonces), performs ML-KEM encapsulation + HKDF key derivation + ChaCha20-Poly1305 encryption, and rewrites the request to POST /e2e/invoke with a binary body and E2EE headers.

  2. Inbound (non-streaming): Decrypts the response blob (ML-KEM decapsulation + HKDF + ChaCha20) and returns a normal JSON httpx.Response.

  3. Inbound (streaming): Decrypts the e2e_init key-exchange event, then decrypts each e2e chunk, yielding standard data: {...} SSE lines that the OpenAI SDK parses normally.

Nonce Management

The transport automatically:

  • Prefetches nonces from /e2e/instances/{chute_id} (10 per instance, up to 5 instances)
  • Caches them locally with expiry tracking (60s client TTL)
  • Refreshes when nonces are exhausted or expired
  • Consumes one nonce per request (single-use, replay-proof)

Model Resolution

You can use model names (e.g. zai-org/GLM-4.7-TEE) or chute IDs directly. The transport resolves model names to chute IDs via the /v1/models endpoint (cached for 5 minutes).

Configuration

Parameter Default Description
api_key required Your Chutes API key
api_base https://api.chutes.ai API base URL
inner httpx.HTTPTransport() Underlying transport for actual HTTP calls

Dependencies

  • httpx >= 0.25
  • cryptography >= 42.0
  • pqcrypto >= 0.1.0 (ML-KEM-768 implementation)

License

MIT

Metadata

Release files for chutes-e2ee 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chutes-e2ee 0.1.0
File Size Uploaded
chutes_e2ee-0.1.0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chutes-e2ee 0.1.0
File Interpreter ABI Platform
chutes_e2ee-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / chutes_e2ee-0.1.0.tar.gz

Download URL chutes_e2ee-0.1.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6ec18513f5b34573134a7f298bca3cd51a524d1263594819c31a010342004790
BLAKE2b-256 checksum
How to use checksums
62fad470e57acc0ef97e0cdd25faba8f13027bc6ec025aa5ca09fbe43f149d9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.17

Release files / chutes_e2ee-0.1.0-py3-none-any.whl

Download URL chutes_e2ee-0.1.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6916d3f28e4ec25f64ff03db566a55ab9eaaabcd1ed04235c592065c054a0ee
BLAKE2b-256 checksum
How to use checksums
01d2182aff404bb8850c47a7ed764abeaca20d97c0a5375a9876d1216f8d959e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.17

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page