lebrel-encrypted 0.4.0__tar.gz → 0.4.2__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.
- lebrel_encrypted-0.4.2/CHANGELOG.md +34 -0
- lebrel_encrypted-0.4.0/README.md → lebrel_encrypted-0.4.2/PKG-INFO +87 -17
- lebrel_encrypted-0.4.0/PKG-INFO → lebrel_encrypted-0.4.2/README.md +53 -44
- lebrel_encrypted-0.4.2/VENDORED_SHA256.json +17 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/pyproject.toml +10 -3
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/__init__.py +1 -1
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/cli.py +9 -2
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/client.py +6 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/proxy.py +25 -1
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/tests/test_client.py +16 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/tests/test_proxy.py +16 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/.gitignore +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/LICENSE +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/THIRD_PARTY_NOTICES.md +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/examples/chat.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/examples/stream.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/__main__.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/__init__.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/LICENSE +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/__init__.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/_http.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/client.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/derive.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/errors.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/identity.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/protocol.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/py.typed +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/session.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/transport.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/anthropic_messages.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/openai_responses.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/proof.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/tests/interop/go.mod +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/tests/interop/go.sum +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/tests/interop/main.go +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/tests/test_cli.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/tests/test_proof.py +0 -0
- {lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/tests/test_proxy_formats.py +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `lebrel-encrypted`. Versions follow [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## 0.4.2 — 2026-10-29
|
|
6
|
+
|
|
7
|
+
- The local proxy and the command line answer with the platform's own reason when a request cannot be
|
|
8
|
+
served (`error.code` and a plain message): in line and the wait ran out, line full, place in line lapsed,
|
|
9
|
+
model paused, too many requests at once, not enough balance, platform or node unreachable. A generic
|
|
10
|
+
failure message is no longer the only thing an application sees.
|
|
11
|
+
- `service_tier="priority"` on `create()` sends `X-Lebrel-Service-Tier: priority`; the proxy forwards the
|
|
12
|
+
OpenAI `service_tier` parameter the same way. Priority is an account setting (Dashboard → Billing); the
|
|
13
|
+
parameter is accepted as well.
|
|
14
|
+
|
|
15
|
+
## 0.4.1 — 2026-10-26
|
|
16
|
+
|
|
17
|
+
- README: where hardware attestation stands, and what the runtime signature proves until then.
|
|
18
|
+
|
|
19
|
+
## 0.4.0 — 2026-10-15
|
|
20
|
+
|
|
21
|
+
- The local proxy speaks OpenAI Responses (`/v1/responses`) and Anthropic Messages (`/v1/messages`,
|
|
22
|
+
`/v1/messages/count_tokens`) beside OpenAI chat completions, every format ending as the same encrypted
|
|
23
|
+
completion. Function tools reach the model; hosted and namespaced tools are refused.
|
|
24
|
+
- `--max-output-tokens` on the proxy caps what clients ask for; read from the public catalog when omitted.
|
|
25
|
+
|
|
26
|
+
## 0.3.0 — 2026-10-08
|
|
27
|
+
|
|
28
|
+
- The client serves DeepSeek V4.1 Flash · Lebrel Uncensored (`lebrel/deepseek-v4.1-flash-uncensored`).
|
|
29
|
+
|
|
30
|
+
## 0.2.0 — 2026-09-26
|
|
31
|
+
|
|
32
|
+
- First release on PyPI: encrypted chat completions, streaming with authenticated completion, the signed
|
|
33
|
+
receipt of every answer fetched and checked, the local proxy for OpenAI-compatible applications, the
|
|
34
|
+
`lebrel-encrypted infer` command.
|
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lebrel-encrypted
|
|
3
|
+
Version: 0.4.2
|
|
4
|
+
Summary: Encrypted, verifiable Python client for DeepSeek V4.1 Flash · Lebrel Uncensored
|
|
5
|
+
Project-URL: Homepage, https://lebrel.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/LEBREL-AI/lebrel-encrypted-python
|
|
7
|
+
Project-URL: Documentation, https://lebrel.ai/docs
|
|
8
|
+
Project-URL: Changelog, https://github.com/LEBREL-AI/lebrel-encrypted-python/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/LEBREL-AI/lebrel-encrypted-python/issues
|
|
10
|
+
Author: Lebrel
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: encrypted,hpke,lebrel,llm,openai-compatible,proof-of-edition,receipts
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Security :: Cryptography
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Requires-Dist: cryptography==46.0.7
|
|
29
|
+
Requires-Dist: httpx==0.28.1
|
|
30
|
+
Requires-Dist: pyhpke==0.6.3
|
|
31
|
+
Provides-Extra: test
|
|
32
|
+
Requires-Dist: pytest==8.4.2; extra == 'test'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
1
35
|
# Lebrel encrypted Python client
|
|
2
36
|
|
|
3
37
|
Questions are encrypted locally for the verified runtime. Answers are decrypted
|
|
@@ -49,10 +83,10 @@ Configure your application with:
|
|
|
49
83
|
|
|
50
84
|
The adapter receives normal OpenAI JSON and SSE on loopback, then uses this SDK
|
|
51
85
|
to encrypt requests to the public API and decrypt responses. It binds only to
|
|
52
|
-
`127.0.0.1`; there is no network-bind option. The
|
|
53
|
-
|
|
54
|
-
boundary. Requests require `Authorization: Bearer ...` and
|
|
55
|
-
`Content-Length`. Browser-origin requests are rejected.
|
|
86
|
+
`127.0.0.1`; there is no network-bind option. The hop between your application and
|
|
87
|
+
the adapter is plaintext on loopback: any process on your computer that can reach
|
|
88
|
+
it is inside your trust boundary. Requests require `Authorization: Bearer ...` and
|
|
89
|
+
JSON bodies with `Content-Length`. Browser-origin requests are rejected.
|
|
56
90
|
|
|
57
91
|
The adapter does not persist API keys or conversations. By default the key comes
|
|
58
92
|
from each application's request. Optional standalone use can read the key from
|
|
@@ -81,8 +115,8 @@ lebrel-encrypted infer < request.json
|
|
|
81
115
|
|
|
82
116
|
Equivalent: `python -m lebrel_encrypted infer < request.json`. The command reads
|
|
83
117
|
JSON from stdin and the key from the environment. It writes a JSON response, or
|
|
84
|
-
SSE when the input sets `"stream": true`.
|
|
85
|
-
|
|
118
|
+
SSE when the input sets `"stream": true`. On failure it exits nonzero and prints a
|
|
119
|
+
JSON error to stderr with the platform's reason when there is one (see below).
|
|
86
120
|
|
|
87
121
|
## Streaming and cancellation
|
|
88
122
|
|
|
@@ -102,7 +136,7 @@ with Lebrel() as client:
|
|
|
102
136
|
assert stream.completed
|
|
103
137
|
```
|
|
104
138
|
|
|
105
|
-
|
|
139
|
+
Read the stream to its end to verify completion. It requires a final
|
|
106
140
|
`finish_reason` for every observed choice, then an authenticated `[DONE]`, and
|
|
107
141
|
rejects subsequent data or truncated encrypted frames. Partial output may have
|
|
108
142
|
been displayed before a later error: do not treat it as a completed answer.
|
|
@@ -155,12 +189,42 @@ except (EncryptionError, StreamError, TransportError) as error:
|
|
|
155
189
|
print(str(error))
|
|
156
190
|
```
|
|
157
191
|
|
|
158
|
-
The client never
|
|
159
|
-
after execution has begun, so a fresh application
|
|
160
|
-
Each
|
|
161
|
-
encapsulation.
|
|
162
|
-
|
|
163
|
-
untrusted plaintext error bodies.
|
|
192
|
+
The client never retries inference on its own. A connection failure may occur
|
|
193
|
+
after execution has begun, so a fresh retry by your application can incur a new
|
|
194
|
+
charge. Each request gets a new UUID in `X-Lebrel-Request-Id` and a fresh HPKE
|
|
195
|
+
encapsulation. The client never follows redirects, never accepts a plaintext
|
|
196
|
+
success response and never falls back to the unencrypted API. Error messages omit
|
|
197
|
+
conversation content and ignore untrusted plaintext error bodies.
|
|
198
|
+
|
|
199
|
+
### When a request cannot be served
|
|
200
|
+
|
|
201
|
+
`APIError.code` carries the platform's reason, and the proxy and the command line
|
|
202
|
+
put the same code and a plain message in the JSON error they answer with:
|
|
203
|
+
|
|
204
|
+
| `code` | What it means |
|
|
205
|
+
| --- | --- |
|
|
206
|
+
| `queue_wait_timeout` | You were in line for the model and the wait ran out (two minutes). Retry; the line moves as answers finish. |
|
|
207
|
+
| `queue_full` | The line for the model is full right now. Try again in a minute. |
|
|
208
|
+
| `queue_lapsed` | Your place in line lapsed. Send the request again. |
|
|
209
|
+
| `model_paused` | The model is paused until the next drop. |
|
|
210
|
+
| `rate_limit_exceeded` | Too many requests at once for this account. |
|
|
211
|
+
| `insufficient_quota` | Not enough balance for this request. |
|
|
212
|
+
| `priority_unavailable` | Priority is not available for this key. |
|
|
213
|
+
| `context_length_exceeded` | The prompt and the output limit exceed the model's context window. |
|
|
214
|
+
| `inference_unavailable`, `billing_unavailable`, `authentication_unavailable`, `database_unavailable`, `encrypted_inference_unavailable` | The platform or the model's node could not be reached just now. Try again in a moment. |
|
|
215
|
+
|
|
216
|
+
## Priority
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
answer = client.create(messages=[...], service_tier="priority")
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Priority is a setting of your account (Dashboard → Billing): with it on, every
|
|
223
|
+
request goes ahead of the line at the priority price. The OpenAI `service_tier`
|
|
224
|
+
parameter is accepted as well, in Python and through the proxy, and sends
|
|
225
|
+
`X-Lebrel-Service-Tier: priority`. The response header `X-Lebrel-Price-Multiplier`
|
|
226
|
+
names the price the request was admitted at, as a percentage of the list price,
|
|
227
|
+
and `X-Lebrel-Queue-Wait-Ms` the time it waited in line.
|
|
164
228
|
|
|
165
229
|
The default timeout is 900 seconds for cold starts; configure `Lebrel(timeout=...)`
|
|
166
230
|
when needed. Environment HTTP proxy settings are disabled. HTTPS certificate
|
|
@@ -187,10 +251,10 @@ SHA-256:
|
|
|
187
251
|
8f72beb9680a0f1911dce59d1fc103a0a89039998003715d35422d3020e5292d
|
|
188
252
|
```
|
|
189
253
|
|
|
190
|
-
The runtime signature authenticates Lebrel's encryption key.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
254
|
+
The runtime signature authenticates Lebrel's encryption key. Hardware attestation,
|
|
255
|
+
which proves that the operator cannot access the model process's memory, is the
|
|
256
|
+
layer that arrives with the public launch. Until then, questions and answers are
|
|
257
|
+
decrypted inside an inference runtime administered by Lebrel.
|
|
194
258
|
|
|
195
259
|
## Reused implementation and dependencies
|
|
196
260
|
|
|
@@ -222,3 +286,9 @@ upstream revision (`GOTOOLCHAIN=go1.26.0`) and verifies real Python-to-Go encryp
|
|
|
222
286
|
requests, JSON responses, streaming, truncation and failure handling. No GPU,
|
|
223
287
|
production credentials or production API calls are used. Dependency and Go
|
|
224
288
|
toolchain downloads are needed once unless already cached.
|
|
289
|
+
|
|
290
|
+
## Changelog and license
|
|
291
|
+
|
|
292
|
+
Changes by version are in [CHANGELOG.md](CHANGELOG.md). The package is released
|
|
293
|
+
under the MIT license; the vendored EHBP module keeps its own MIT license (see
|
|
294
|
+
`THIRD_PARTY_NOTICES.md`). Questions and security reports: contact@lebrel.ai.
|
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: lebrel-encrypted
|
|
3
|
-
Version: 0.4.0
|
|
4
|
-
Summary: Verified encrypted Python client for DeepSeek V4.1 Flash · Lebrel Uncensored
|
|
5
|
-
Project-URL: Homepage, https://lebrel.ai
|
|
6
|
-
Project-URL: Repository, https://github.com/LEBREL-AI/lebrel-encrypted-python
|
|
7
|
-
Project-URL: Documentation, https://lebrel.ai/docs
|
|
8
|
-
Author: Lebrel
|
|
9
|
-
License-Expression: MIT
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Keywords: encrypted,hpke,lebrel,llm,openai-compatible,proof-of-edition,receipts
|
|
12
|
-
Classifier: Development Status :: 4 - Beta
|
|
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: Topic :: Security :: Cryptography
|
|
18
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
-
Classifier: Typing :: Typed
|
|
20
|
-
Requires-Python: >=3.9
|
|
21
|
-
Requires-Dist: cryptography==46.0.7
|
|
22
|
-
Requires-Dist: httpx==0.28.1
|
|
23
|
-
Requires-Dist: pyhpke==0.6.3
|
|
24
|
-
Provides-Extra: test
|
|
25
|
-
Requires-Dist: pytest==8.4.2; extra == 'test'
|
|
26
|
-
Description-Content-Type: text/markdown
|
|
27
|
-
|
|
28
1
|
# Lebrel encrypted Python client
|
|
29
2
|
|
|
30
3
|
Questions are encrypted locally for the verified runtime. Answers are decrypted
|
|
@@ -76,10 +49,10 @@ Configure your application with:
|
|
|
76
49
|
|
|
77
50
|
The adapter receives normal OpenAI JSON and SSE on loopback, then uses this SDK
|
|
78
51
|
to encrypt requests to the public API and decrypt responses. It binds only to
|
|
79
|
-
`127.0.0.1`; there is no network-bind option. The
|
|
80
|
-
|
|
81
|
-
boundary. Requests require `Authorization: Bearer ...` and
|
|
82
|
-
`Content-Length`. Browser-origin requests are rejected.
|
|
52
|
+
`127.0.0.1`; there is no network-bind option. The hop between your application and
|
|
53
|
+
the adapter is plaintext on loopback: any process on your computer that can reach
|
|
54
|
+
it is inside your trust boundary. Requests require `Authorization: Bearer ...` and
|
|
55
|
+
JSON bodies with `Content-Length`. Browser-origin requests are rejected.
|
|
83
56
|
|
|
84
57
|
The adapter does not persist API keys or conversations. By default the key comes
|
|
85
58
|
from each application's request. Optional standalone use can read the key from
|
|
@@ -108,8 +81,8 @@ lebrel-encrypted infer < request.json
|
|
|
108
81
|
|
|
109
82
|
Equivalent: `python -m lebrel_encrypted infer < request.json`. The command reads
|
|
110
83
|
JSON from stdin and the key from the environment. It writes a JSON response, or
|
|
111
|
-
SSE when the input sets `"stream": true`.
|
|
112
|
-
|
|
84
|
+
SSE when the input sets `"stream": true`. On failure it exits nonzero and prints a
|
|
85
|
+
JSON error to stderr with the platform's reason when there is one (see below).
|
|
113
86
|
|
|
114
87
|
## Streaming and cancellation
|
|
115
88
|
|
|
@@ -129,7 +102,7 @@ with Lebrel() as client:
|
|
|
129
102
|
assert stream.completed
|
|
130
103
|
```
|
|
131
104
|
|
|
132
|
-
|
|
105
|
+
Read the stream to its end to verify completion. It requires a final
|
|
133
106
|
`finish_reason` for every observed choice, then an authenticated `[DONE]`, and
|
|
134
107
|
rejects subsequent data or truncated encrypted frames. Partial output may have
|
|
135
108
|
been displayed before a later error: do not treat it as a completed answer.
|
|
@@ -182,12 +155,42 @@ except (EncryptionError, StreamError, TransportError) as error:
|
|
|
182
155
|
print(str(error))
|
|
183
156
|
```
|
|
184
157
|
|
|
185
|
-
The client never
|
|
186
|
-
after execution has begun, so a fresh application
|
|
187
|
-
Each
|
|
188
|
-
encapsulation.
|
|
189
|
-
|
|
190
|
-
untrusted plaintext error bodies.
|
|
158
|
+
The client never retries inference on its own. A connection failure may occur
|
|
159
|
+
after execution has begun, so a fresh retry by your application can incur a new
|
|
160
|
+
charge. Each request gets a new UUID in `X-Lebrel-Request-Id` and a fresh HPKE
|
|
161
|
+
encapsulation. The client never follows redirects, never accepts a plaintext
|
|
162
|
+
success response and never falls back to the unencrypted API. Error messages omit
|
|
163
|
+
conversation content and ignore untrusted plaintext error bodies.
|
|
164
|
+
|
|
165
|
+
### When a request cannot be served
|
|
166
|
+
|
|
167
|
+
`APIError.code` carries the platform's reason, and the proxy and the command line
|
|
168
|
+
put the same code and a plain message in the JSON error they answer with:
|
|
169
|
+
|
|
170
|
+
| `code` | What it means |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| `queue_wait_timeout` | You were in line for the model and the wait ran out (two minutes). Retry; the line moves as answers finish. |
|
|
173
|
+
| `queue_full` | The line for the model is full right now. Try again in a minute. |
|
|
174
|
+
| `queue_lapsed` | Your place in line lapsed. Send the request again. |
|
|
175
|
+
| `model_paused` | The model is paused until the next drop. |
|
|
176
|
+
| `rate_limit_exceeded` | Too many requests at once for this account. |
|
|
177
|
+
| `insufficient_quota` | Not enough balance for this request. |
|
|
178
|
+
| `priority_unavailable` | Priority is not available for this key. |
|
|
179
|
+
| `context_length_exceeded` | The prompt and the output limit exceed the model's context window. |
|
|
180
|
+
| `inference_unavailable`, `billing_unavailable`, `authentication_unavailable`, `database_unavailable`, `encrypted_inference_unavailable` | The platform or the model's node could not be reached just now. Try again in a moment. |
|
|
181
|
+
|
|
182
|
+
## Priority
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
answer = client.create(messages=[...], service_tier="priority")
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Priority is a setting of your account (Dashboard → Billing): with it on, every
|
|
189
|
+
request goes ahead of the line at the priority price. The OpenAI `service_tier`
|
|
190
|
+
parameter is accepted as well, in Python and through the proxy, and sends
|
|
191
|
+
`X-Lebrel-Service-Tier: priority`. The response header `X-Lebrel-Price-Multiplier`
|
|
192
|
+
names the price the request was admitted at, as a percentage of the list price,
|
|
193
|
+
and `X-Lebrel-Queue-Wait-Ms` the time it waited in line.
|
|
191
194
|
|
|
192
195
|
The default timeout is 900 seconds for cold starts; configure `Lebrel(timeout=...)`
|
|
193
196
|
when needed. Environment HTTP proxy settings are disabled. HTTPS certificate
|
|
@@ -214,10 +217,10 @@ SHA-256:
|
|
|
214
217
|
8f72beb9680a0f1911dce59d1fc103a0a89039998003715d35422d3020e5292d
|
|
215
218
|
```
|
|
216
219
|
|
|
217
|
-
The runtime signature authenticates Lebrel's encryption key.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
220
|
+
The runtime signature authenticates Lebrel's encryption key. Hardware attestation,
|
|
221
|
+
which proves that the operator cannot access the model process's memory, is the
|
|
222
|
+
layer that arrives with the public launch. Until then, questions and answers are
|
|
223
|
+
decrypted inside an inference runtime administered by Lebrel.
|
|
221
224
|
|
|
222
225
|
## Reused implementation and dependencies
|
|
223
226
|
|
|
@@ -249,3 +252,9 @@ upstream revision (`GOTOOLCHAIN=go1.26.0`) and verifies real Python-to-Go encryp
|
|
|
249
252
|
requests, JSON responses, streaming, truncation and failure handling. No GPU,
|
|
250
253
|
production credentials or production API calls are used. Dependency and Go
|
|
251
254
|
toolchain downloads are needed once unless already cached.
|
|
255
|
+
|
|
256
|
+
## Changelog and license
|
|
257
|
+
|
|
258
|
+
Changes by version are in [CHANGELOG.md](CHANGELOG.md). The package is released
|
|
259
|
+
under the MIT license; the vendored EHBP module keeps its own MIT license (see
|
|
260
|
+
`THIRD_PARTY_NOTICES.md`). Questions and security reports: contact@lebrel.ai.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"source": "https://github.com/tinfoilsh/encrypted-http-body-protocol",
|
|
3
|
+
"revision": "6ae53f8b6270834ca1cb8c29f8d2a79e372bc4b0",
|
|
4
|
+
"directory": "python/src/ehbp",
|
|
5
|
+
"files": {
|
|
6
|
+
"__init__.py": "fa119ca7351e66c11959ba11f1e14cb845888a4947109ee45ba40b4679254797",
|
|
7
|
+
"_http.py": "b3673e9998dfbc2bb7bb23ac37a0519e990c5cf24fafd24da55068d4af303476",
|
|
8
|
+
"client.py": "084859bf4ee9330a6108f94e248570707ccbc3974cdf5946dd2c6894a20c1dfc",
|
|
9
|
+
"derive.py": "6a757686a62de420cdc36f9728fa6782b173cee80c06f407579403a3b7564569",
|
|
10
|
+
"errors.py": "ae0aeb6a5d314d34797eefcc984c156385fd3def5b2ad24018f66e692d7125e0",
|
|
11
|
+
"identity.py": "586d38654d9f658ce79e8fd7ca630daf3feef40c0afa9fefb1ff44d16e14d3cd",
|
|
12
|
+
"protocol.py": "cfa74c8f4f5238d9aaa5ec19ea7ab7d4d10df8030c48ae5754ac09cd8d219a54",
|
|
13
|
+
"py.typed": "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b",
|
|
14
|
+
"session.py": "1f655b1c27a8070d2ca1d79ba5394e2b15405f88c4259890af304bb11d0b7bb4",
|
|
15
|
+
"transport.py": "e48b0cbc08a471d739aa0749ca7840bbaf692b245a6499834e9db00f56d9b9a8"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -4,9 +4,9 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "lebrel-encrypted"
|
|
7
|
-
version = "0.4.
|
|
7
|
+
version = "0.4.2"
|
|
8
8
|
authors = [{ name = "Lebrel" }]
|
|
9
|
-
description = "
|
|
9
|
+
description = "Encrypted, verifiable Python client for DeepSeek V4.1 Flash · Lebrel Uncensored"
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
license = "MIT"
|
|
12
12
|
requires-python = ">=3.9"
|
|
@@ -17,6 +17,11 @@ classifiers = [
|
|
|
17
17
|
"Operating System :: OS Independent",
|
|
18
18
|
"Programming Language :: Python :: 3",
|
|
19
19
|
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
20
25
|
"Topic :: Security :: Cryptography",
|
|
21
26
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
22
27
|
"Typing :: Typed",
|
|
@@ -31,6 +36,8 @@ dependencies = [
|
|
|
31
36
|
Homepage = "https://lebrel.ai"
|
|
32
37
|
Repository = "https://github.com/LEBREL-AI/lebrel-encrypted-python"
|
|
33
38
|
Documentation = "https://lebrel.ai/docs"
|
|
39
|
+
Changelog = "https://github.com/LEBREL-AI/lebrel-encrypted-python/blob/main/CHANGELOG.md"
|
|
40
|
+
Issues = "https://github.com/LEBREL-AI/lebrel-encrypted-python/issues"
|
|
34
41
|
|
|
35
42
|
[project.scripts]
|
|
36
43
|
lebrel-encrypted = "lebrel_encrypted.cli:main"
|
|
@@ -42,7 +49,7 @@ test = ["pytest==8.4.2"]
|
|
|
42
49
|
packages = ["src/lebrel_encrypted"]
|
|
43
50
|
|
|
44
51
|
[tool.hatch.build.targets.sdist]
|
|
45
|
-
include = ["src", "examples", "tests", "README.md", "LICENSE", "THIRD_PARTY_NOTICES.md", "pyproject.toml"]
|
|
52
|
+
include = ["src", "examples", "tests", "README.md", "CHANGELOG.md", "LICENSE", "THIRD_PARTY_NOTICES.md", "VENDORED_SHA256.json", "pyproject.toml"]
|
|
46
53
|
|
|
47
54
|
[tool.pytest.ini_options]
|
|
48
55
|
testpaths = ["tests"]
|
|
@@ -13,5 +13,5 @@ from .client import (
|
|
|
13
13
|
)
|
|
14
14
|
from .proof import Check, Manifest, Receipt
|
|
15
15
|
|
|
16
|
-
__version__ = "0.4.
|
|
16
|
+
__version__ = "0.4.2"
|
|
17
17
|
__all__ = ["Lebrel", "MODEL_ID", "Completion", "CompletionStream", "Receipt", "Manifest", "Check", "LebrelError", "EncryptionError", "TransportError", "APIError", "StreamError"]
|
|
@@ -4,7 +4,7 @@ import argparse
|
|
|
4
4
|
import json
|
|
5
5
|
import sys
|
|
6
6
|
|
|
7
|
-
from .client import Lebrel, LebrelError, MAX_REQUEST_BYTES, _json
|
|
7
|
+
from .client import APIError, Lebrel, LebrelError, MAX_REQUEST_BYTES, _json
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def main(argv=None):
|
|
@@ -34,8 +34,15 @@ def main(argv=None):
|
|
|
34
34
|
else:
|
|
35
35
|
print(json.dumps(result, ensure_ascii=False, separators=(",", ":"), allow_nan=False))
|
|
36
36
|
return 0
|
|
37
|
+
except APIError as error:
|
|
38
|
+
# The platform's reason, in its words (the same table the proxy answers with); never the response body.
|
|
39
|
+
from .proxy import ERROR_MESSAGES
|
|
40
|
+
code = error.code if isinstance(error.code, str) and error.code else "api_error"
|
|
41
|
+
message = ERROR_MESSAGES.get(code, "The encrypted request did not complete")
|
|
42
|
+
print(json.dumps({"error": {"type": "encrypted_inference_failed", "code": code, "message": message}}, ensure_ascii=False), file=sys.stderr)
|
|
43
|
+
return 1
|
|
37
44
|
except (LebrelError, ValueError, TypeError, UnicodeError):
|
|
38
|
-
print('{"error":{"code":"encrypted_inference_failed","message":"The encrypted request did not complete"}}', file=sys.stderr)
|
|
45
|
+
print('{"error":{"type":"encrypted_inference_failed","code":"encrypted_inference_failed","message":"The encrypted request did not complete"}}', file=sys.stderr)
|
|
39
46
|
return 1
|
|
40
47
|
except (BrokenPipeError, KeyboardInterrupt):
|
|
41
48
|
return 130
|
|
@@ -407,6 +407,11 @@ class Lebrel:
|
|
|
407
407
|
raise ValueError("This encrypted endpoint serves only DeepSeek V4.1 Flash Uncensored")
|
|
408
408
|
if not isinstance(messages, list) or not messages or type(stream) is not bool:
|
|
409
409
|
raise ValueError("messages must be a nonempty list and stream must be boolean")
|
|
410
|
+
# `service_tier` (the OpenAI parameter): "priority" asks for Lebrel's priority tier, ahead of the line at its
|
|
411
|
+
# fixed price; it travels in a header, since the body is encrypted. Other values mean the default tier.
|
|
412
|
+
service_tier = parameters.pop("service_tier", None)
|
|
413
|
+
if service_tier is not None and not isinstance(service_tier, str):
|
|
414
|
+
raise ValueError("service_tier must be a string")
|
|
410
415
|
try:
|
|
411
416
|
plaintext = json.dumps(dict(parameters, model=model, messages=messages, stream=stream), ensure_ascii=False, separators=(",", ":"), allow_nan=False).encode("utf-8")
|
|
412
417
|
except (ValueError, TypeError, UnicodeError):
|
|
@@ -430,6 +435,7 @@ class Lebrel:
|
|
|
430
435
|
"Ehbp-Encapsulated-Key": encrypted.encapsulated_key.hex(),
|
|
431
436
|
"X-Lebrel-Encryption-Key-Id": verified.key_id,
|
|
432
437
|
"X-Lebrel-Request-Id": request_id,
|
|
438
|
+
**({"X-Lebrel-Service-Tier": "priority"} if service_tier == "priority" else {}),
|
|
433
439
|
}, content=encrypted.body)
|
|
434
440
|
try:
|
|
435
441
|
response = self._http.send(request, stream=True)
|
|
@@ -28,6 +28,30 @@ from .client import APIError, Lebrel, LebrelError, MAX_REQUEST_BYTES, MODEL_ID,
|
|
|
28
28
|
REQUEST_ID_HEADER = "X-Lebrel-Request-Id"
|
|
29
29
|
RECEIPT_CHECK_HEADER = "X-Lebrel-Receipt-Check"
|
|
30
30
|
PUBLIC_CATALOG_URL = "https://lebrel.ai/api/models"
|
|
31
|
+
|
|
32
|
+
# What a tool shows its user for the platform's answers, by code (the client keeps the code, never the
|
|
33
|
+
# server's own text): in line and the wait ran out, the line full, busy, the platform unreachable.
|
|
34
|
+
ERROR_MESSAGES = {
|
|
35
|
+
"queue_wait_timeout": "You were in line for the model and the wait ran out (two minutes). Your client can retry; the line moves as answers finish.",
|
|
36
|
+
"queue_full": "The line for the model is full right now. Try again in a minute.",
|
|
37
|
+
"queue_lapsed": "Your place in line lapsed. Send the request again.",
|
|
38
|
+
"model_paused": "The model is paused until the next drop.",
|
|
39
|
+
"model_not_released": "The model is not available right now.",
|
|
40
|
+
"rate_limit_exceeded": "Too many requests at once for this account. Try again in a few seconds.",
|
|
41
|
+
"insufficient_quota": "Not enough balance for this request. Add funds and try again.",
|
|
42
|
+
"invalid_api_key": "The API key was refused.",
|
|
43
|
+
"database_unavailable": "The platform's database could not be reached just now. Try again in a moment.",
|
|
44
|
+
"authentication_unavailable": "The platform could not check the key just now. Try again in a moment.",
|
|
45
|
+
"billing_unavailable": "The platform could not open the hold for this request just now. Try again in a moment.",
|
|
46
|
+
"encrypted_inference_unavailable": "The model's node could not be reached just now. Try again in a moment.",
|
|
47
|
+
"inference_unavailable": "The model could not be reached just now. Try again in a moment.",
|
|
48
|
+
"queue_unavailable": "The line for the model could not be reached just now. Try again in a moment.",
|
|
49
|
+
"priority_unavailable": "Priority is not available for this key.",
|
|
50
|
+
"context_length_exceeded": "The prompt and the output limit exceed the model's context window.",
|
|
51
|
+
"max_output_tokens_exceeded": "The output limit asked for is above the model's.",
|
|
52
|
+
"model_not_found": "The model is not available for this key.",
|
|
53
|
+
"request_too_large": "The request is larger than the API accepts.",
|
|
54
|
+
}
|
|
31
55
|
_RECEIPT_PATH = re.compile(r"^/v1/receipts/([A-Za-z0-9_-]{8,128})$")
|
|
32
56
|
# The request format each path speaks; every one ends as the same encrypted chat completion.
|
|
33
57
|
_FORMATS = {"/v1/chat/completions": "openai", "/v1/responses": "responses", "/v1/messages": "anthropic", "/v1/messages/count_tokens": "anthropic"}
|
|
@@ -115,7 +139,7 @@ class ProxyHandler(BaseHTTPRequestHandler):
|
|
|
115
139
|
elif fmt == "responses":
|
|
116
140
|
body = openai_responses.error_body(status, code)
|
|
117
141
|
else:
|
|
118
|
-
body = {"error": {"type": "proxy_error", "code": code, "message": "Encrypted inference could not be completed"}}
|
|
142
|
+
body = {"error": {"type": "proxy_error", "code": code, "message": ERROR_MESSAGES.get(code, "Encrypted inference could not be completed")}}
|
|
119
143
|
data = json.dumps(body, separators=(",", ":")).encode()
|
|
120
144
|
try:
|
|
121
145
|
self.send_response(status)
|
|
@@ -78,6 +78,22 @@ class BytesStream(httpx.SyncByteStream):
|
|
|
78
78
|
yield self.data[offset:offset + 7]
|
|
79
79
|
|
|
80
80
|
|
|
81
|
+
def test_service_tier_priority_travels_as_a_header():
|
|
82
|
+
tiers = []
|
|
83
|
+
def handler(request):
|
|
84
|
+
if request.method == "GET":
|
|
85
|
+
return httpx.Response(200, stream=BytesStream(metadata()))
|
|
86
|
+
tiers.append(request.headers.get("x-lebrel-service-tier"))
|
|
87
|
+
return httpx.Response(422, stream=BytesStream(b"refused"))
|
|
88
|
+
with Lebrel("leb_live_test", _transport=httpx.MockTransport(handler), _clock=lambda: 1010, signing_public_key=base64.b64encode(PUBLIC_KEY).decode()) as client:
|
|
89
|
+
for tier in ("priority", "default", None):
|
|
90
|
+
with pytest.raises(APIError):
|
|
91
|
+
client.create(messages=[{"role": "user", "content": "hello"}], **({"service_tier": tier} if tier is not None else {}))
|
|
92
|
+
with pytest.raises(ValueError):
|
|
93
|
+
client.create(messages=[{"role": "user", "content": "hello"}], service_tier=3)
|
|
94
|
+
assert tiers == ["priority", None, None], "only the priority tier asks for anything; the body never carries service_tier"
|
|
95
|
+
|
|
96
|
+
|
|
81
97
|
def test_request_headers_encryption_and_no_retry():
|
|
82
98
|
calls = []
|
|
83
99
|
def handler(request):
|
|
@@ -50,6 +50,9 @@ class MockClient:
|
|
|
50
50
|
self.close()
|
|
51
51
|
def create(self, **request):
|
|
52
52
|
self.request = request
|
|
53
|
+
# A message that names a platform code is answered with that code, as the platform would.
|
|
54
|
+
if request["messages"][0]["content"] in ("queue_wait_timeout", "database_unavailable", "api_error"):
|
|
55
|
+
raise APIError(503, request["messages"][0]["content"])
|
|
53
56
|
if request.get("stream"):
|
|
54
57
|
self.stream = MockStream(request["messages"][0]["content"])
|
|
55
58
|
return self.stream
|
|
@@ -87,6 +90,19 @@ def body(mode="normal", stream=False):
|
|
|
87
90
|
return {"model": MODEL_ID, "messages": [{"role": "user", "content": mode}], "stream": stream}
|
|
88
91
|
|
|
89
92
|
|
|
93
|
+
def test_proxy_error_messages_name_the_cause(proxy):
|
|
94
|
+
_, url = proxy
|
|
95
|
+
headers = {"Authorization": "Bearer local-key"}
|
|
96
|
+
with httpx.Client() as client:
|
|
97
|
+
waited = client.post(url + "/v1/chat/completions", json=body("queue_wait_timeout"), headers=headers)
|
|
98
|
+
assert waited.status_code == 503 and waited.json()["error"]["code"] == "queue_wait_timeout"
|
|
99
|
+
assert waited.json()["error"]["message"].startswith("You were in line for the model and the wait ran out")
|
|
100
|
+
database = client.post(url + "/v1/chat/completions", json=body("database_unavailable"), headers=headers)
|
|
101
|
+
assert database.json()["error"]["message"].startswith("The platform's database could not be reached")
|
|
102
|
+
unknown = client.post(url + "/v1/chat/completions", json=body("api_error"), headers=headers)
|
|
103
|
+
assert unknown.json()["error"] == {"type": "proxy_error", "code": "api_error", "message": "Encrypted inference could not be completed"}
|
|
104
|
+
|
|
105
|
+
|
|
90
106
|
def test_proxy_health_and_required_authorization(proxy):
|
|
91
107
|
server, url = proxy
|
|
92
108
|
assert server.server_address[0] == "127.0.0.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/__init__.py
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/_http.py
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/client.py
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/derive.py
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/errors.py
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/identity.py
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/protocol.py
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/py.typed
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/session.py
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/_vendor/ehbp/transport.py
RENAMED
|
File without changes
|
{lebrel_encrypted-0.4.0 → lebrel_encrypted-0.4.2}/src/lebrel_encrypted/anthropic_messages.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|