blockrun-litellm 0.1.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.
- blockrun_litellm-0.1.0/.gitignore +49 -0
- blockrun_litellm-0.1.0/CHANGELOG.md +19 -0
- blockrun_litellm-0.1.0/LICENSE +21 -0
- blockrun_litellm-0.1.0/PKG-INFO +475 -0
- blockrun_litellm-0.1.0/README.md +442 -0
- blockrun_litellm-0.1.0/blockrun_litellm/__init__.py +28 -0
- blockrun_litellm-0.1.0/blockrun_litellm/_adapter.py +168 -0
- blockrun_litellm-0.1.0/blockrun_litellm/provider.py +152 -0
- blockrun_litellm-0.1.0/blockrun_litellm/proxy.py +184 -0
- blockrun_litellm-0.1.0/examples/litellm_config.yaml +69 -0
- blockrun_litellm-0.1.0/examples/python_lib.py +75 -0
- blockrun_litellm-0.1.0/examples/raw_openai_sdk.py +37 -0
- blockrun_litellm-0.1.0/pyproject.toml +62 -0
- blockrun_litellm-0.1.0/tests/__init__.py +0 -0
- blockrun_litellm-0.1.0/tests/conftest.py +92 -0
- blockrun_litellm-0.1.0/tests/test_adapter.py +97 -0
- blockrun_litellm-0.1.0/tests/test_provider.py +67 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
MANIFEST
|
|
23
|
+
|
|
24
|
+
# Virtual envs
|
|
25
|
+
venv/
|
|
26
|
+
.venv/
|
|
27
|
+
env/
|
|
28
|
+
ENV/
|
|
29
|
+
|
|
30
|
+
# Test / lint
|
|
31
|
+
.pytest_cache/
|
|
32
|
+
.ruff_cache/
|
|
33
|
+
.mypy_cache/
|
|
34
|
+
.tox/
|
|
35
|
+
.coverage
|
|
36
|
+
.coverage.*
|
|
37
|
+
htmlcov/
|
|
38
|
+
|
|
39
|
+
# Editor
|
|
40
|
+
.vscode/
|
|
41
|
+
.idea/
|
|
42
|
+
*.swp
|
|
43
|
+
*.swo
|
|
44
|
+
.DS_Store
|
|
45
|
+
|
|
46
|
+
# Secrets — never commit a wallet
|
|
47
|
+
.env
|
|
48
|
+
.env.*
|
|
49
|
+
~/.blockrun/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-05-11
|
|
4
|
+
|
|
5
|
+
Initial release.
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- `BlockRunLLM` — LiteLLM `CustomLLM` handler routing through the BlockRun gateway.
|
|
9
|
+
- `register()` — idempotent registration of the `blockrun` provider in `litellm.custom_provider_map`.
|
|
10
|
+
- `blockrun-litellm-proxy` — local OpenAI-compatible FastAPI proxy (`pip install 'blockrun-litellm[proxy]'`).
|
|
11
|
+
- Endpoints on the proxy: `POST /v1/chat/completions`, `GET /v1/models`, `GET /healthz`, `GET /docs`.
|
|
12
|
+
- Optional shared-secret guard via `BLOCKRUN_PROXY_TOKEN`.
|
|
13
|
+
- Examples: `python_lib.py`, `raw_openai_sdk.py`, `litellm_config.yaml`.
|
|
14
|
+
- Bilingual README (English + 中文).
|
|
15
|
+
|
|
16
|
+
### Known limitations
|
|
17
|
+
- **Streaming (`stream=True`) is not supported** — surfaces as HTTP 400. SSE support tracks the upstream `blockrun-llm` SDK.
|
|
18
|
+
- **Solana wallet path not wired** — Base only for v0.1. Solana support will land alongside `SolanaLLMClient` integration.
|
|
19
|
+
- Image / video / music generation endpoints are not exposed by the proxy yet; only `/v1/chat/completions`.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BlockRun
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: blockrun-litellm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LiteLLM adapter for BlockRun — call x402-paid AI models via LiteLLM (custom provider or local OpenAI-compatible proxy)
|
|
5
|
+
Project-URL: Homepage, https://blockrun.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/BlockRunAI/blockrun-litellm
|
|
7
|
+
Project-URL: Documentation, https://github.com/BlockRunAI/blockrun-litellm#readme
|
|
8
|
+
Author-email: BlockRun <hello@blockrun.ai>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai-gateway,blockrun,litellm,llm-proxy,openai,openrouter,x402
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: blockrun-llm>=0.19.0
|
|
23
|
+
Requires-Dist: litellm>=1.40.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
29
|
+
Provides-Extra: proxy
|
|
30
|
+
Requires-Dist: fastapi>=0.110.0; extra == 'proxy'
|
|
31
|
+
Requires-Dist: uvicorn[standard]>=0.27.0; extra == 'proxy'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# blockrun-litellm
|
|
35
|
+
|
|
36
|
+
LiteLLM adapter for [BlockRun](https://blockrun.ai) — call x402-paid AI models through [LiteLLM](https://github.com/BerriAI/litellm) with zero changes to your existing code.
|
|
37
|
+
|
|
38
|
+
> **TL;DR** — BlockRun's `/v1/chat/completions` is already OpenAI-compatible at the protocol level. The only thing that differs is *authentication*: BlockRun uses per-request x402 wallet signatures (non-custodial USDC micropayments on Base / Solana), not a Bearer API key. This package bridges that gap.
|
|
39
|
+
|
|
40
|
+
[中文文档见底部 / Chinese docs at the bottom](#中文文档)
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Two ways to integrate
|
|
45
|
+
|
|
46
|
+
| Mode | Best for | What it looks like |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| **1. Custom provider** (in-process) | Apps using the LiteLLM **Python library** | `litellm.completion(model="blockrun/openai/gpt-5.5", ...)` |
|
|
49
|
+
| **2. Local proxy** (sidecar) | Apps using the LiteLLM **Proxy Server** (or any OpenAI client) | `api_base="http://localhost:4001/v1"` |
|
|
50
|
+
|
|
51
|
+
Both modes share the same underlying wallet/signing flow (via the [`blockrun-llm`](https://github.com/BlockRunAI/blockrun-llm) SDK), so they behave identically. Pick whichever fits your deployment.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Custom provider only (no proxy server)
|
|
59
|
+
pip install blockrun-litellm
|
|
60
|
+
|
|
61
|
+
# Custom provider + local proxy (includes FastAPI/uvicorn)
|
|
62
|
+
pip install 'blockrun-litellm[proxy]'
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Requires Python ≥ 3.9.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Configure your wallet (one-time)
|
|
70
|
+
|
|
71
|
+
The `blockrun-llm` SDK signs each request locally with an EVM (Base chain) private key. **The key never leaves your machine.** Three ways to provide it:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Option A — environment variable (recommended for servers)
|
|
75
|
+
export BLOCKRUN_WALLET_KEY=0xYOUR_BASE_CHAIN_PRIVATE_KEY
|
|
76
|
+
|
|
77
|
+
# Option B — auto-create + fund a new wallet (interactive, shows QR for funding)
|
|
78
|
+
python -c "from blockrun_llm import setup_agent_wallet; setup_agent_wallet()"
|
|
79
|
+
|
|
80
|
+
# Option C — pass per-call (Python lib mode), see examples below
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> 💡 To validate without spending real USDC, use a free model like `nvidia/deepseek-v4-flash` — same code path, same wallet flow, $0 settlement.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Mode 1 — Custom provider (Python library)
|
|
88
|
+
|
|
89
|
+
The shortest path if your app already calls `litellm.completion()` directly.
|
|
90
|
+
|
|
91
|
+
### 1a. Register once at startup
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import litellm
|
|
95
|
+
from blockrun_litellm import register
|
|
96
|
+
|
|
97
|
+
register() # idempotent; adds "blockrun" to litellm.custom_provider_map
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 1b. Call with a `blockrun/` model prefix
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
response = litellm.completion(
|
|
104
|
+
model="blockrun/openai/gpt-5.5", # blockrun/<provider>/<model>
|
|
105
|
+
messages=[{"role": "user", "content": "What is the capital of France?"}],
|
|
106
|
+
max_tokens=128,
|
|
107
|
+
temperature=0.7,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
print(response.choices[0].message.content)
|
|
111
|
+
print(response.usage) # prompt_tokens / completion_tokens / total_tokens
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The `blockrun/` prefix is stripped before being sent to the BlockRun gateway, so `openai/gpt-5.5`, `anthropic/claude-opus-4-5`, `google/gemini-3-pro`, etc. all work — anything in BlockRun's catalog.
|
|
115
|
+
|
|
116
|
+
### 1c. Override the wallet per-call (optional)
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
response = litellm.completion(
|
|
120
|
+
model="blockrun/openai/gpt-5.5",
|
|
121
|
+
messages=[...],
|
|
122
|
+
api_key="0xANOTHER_PRIVATE_KEY", # passed to blockrun-llm as wallet
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 1d. Async
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
import asyncio
|
|
130
|
+
|
|
131
|
+
async def main():
|
|
132
|
+
response = await litellm.acompletion(
|
|
133
|
+
model="blockrun/openai/gpt-5.5",
|
|
134
|
+
messages=[{"role": "user", "content": "Hi"}],
|
|
135
|
+
)
|
|
136
|
+
print(response.choices[0].message.content)
|
|
137
|
+
|
|
138
|
+
asyncio.run(main())
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Mode 2 — Local proxy (LiteLLM Proxy Server, langchain, raw curl, …)
|
|
144
|
+
|
|
145
|
+
If you're running the **LiteLLM Proxy Server** (`litellm --config config.yaml`), or any client that just speaks OpenAI HTTP, run our proxy as a sidecar.
|
|
146
|
+
|
|
147
|
+
### 2a. Start the proxy
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
export BLOCKRUN_WALLET_KEY=0xYOUR_KEY
|
|
151
|
+
blockrun-litellm-proxy --port 4001
|
|
152
|
+
# → uvicorn running at http://127.0.0.1:4001
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Flags:
|
|
156
|
+
|
|
157
|
+
| Flag | Default | Purpose |
|
|
158
|
+
|---|---|---|
|
|
159
|
+
| `--host` | `127.0.0.1` | Bind interface. **Keep loopback** unless you set `BLOCKRUN_PROXY_TOKEN`. |
|
|
160
|
+
| `--port` | `4001` | Bind port |
|
|
161
|
+
| `--api-url` | `https://blockrun.ai/api` | Override BlockRun gateway endpoint |
|
|
162
|
+
| `--log-level` | `info` | `critical`/`error`/`warning`/`info`/`debug`/`trace` |
|
|
163
|
+
|
|
164
|
+
Optional shared-secret guard:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
export BLOCKRUN_PROXY_TOKEN=$(openssl rand -hex 32)
|
|
168
|
+
# clients must now send: Authorization: Bearer $BLOCKRUN_PROXY_TOKEN
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 2b. Point LiteLLM Proxy at it
|
|
172
|
+
|
|
173
|
+
Drop this into your `config.yaml`:
|
|
174
|
+
|
|
175
|
+
```yaml
|
|
176
|
+
model_list:
|
|
177
|
+
- model_name: gpt-5.5
|
|
178
|
+
litellm_params:
|
|
179
|
+
model: openai/openai/gpt-5.5 # first 'openai/' = LiteLLM provider; rest = BlockRun model id
|
|
180
|
+
api_base: http://localhost:4001/v1
|
|
181
|
+
api_key: "dummy" # ignored if BLOCKRUN_PROXY_TOKEN is unset
|
|
182
|
+
|
|
183
|
+
- model_name: claude-opus-4-5
|
|
184
|
+
litellm_params:
|
|
185
|
+
model: openai/anthropic/claude-opus-4-5
|
|
186
|
+
api_base: http://localhost:4001/v1
|
|
187
|
+
api_key: "dummy"
|
|
188
|
+
|
|
189
|
+
litellm_settings:
|
|
190
|
+
drop_params: True # silently drop OpenAI params BlockRun doesn't support
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Run LiteLLM Proxy as usual:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
litellm --config config.yaml --port 4000
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Then call it like any OpenAI endpoint:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
curl http://localhost:4000/v1/chat/completions \
|
|
203
|
+
-H "Content-Type: application/json" \
|
|
204
|
+
-d '{
|
|
205
|
+
"model": "gpt-5.5",
|
|
206
|
+
"messages": [{"role": "user", "content": "Hello"}]
|
|
207
|
+
}'
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### 2c. Or skip LiteLLM entirely
|
|
211
|
+
|
|
212
|
+
The proxy speaks OpenAI HTTP, so anything that takes an `api_base` works:
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
# OpenAI Python SDK pointed straight at the BlockRun proxy
|
|
216
|
+
from openai import OpenAI
|
|
217
|
+
|
|
218
|
+
client = OpenAI(api_key="dummy", base_url="http://localhost:4001/v1")
|
|
219
|
+
resp = client.chat.completions.create(
|
|
220
|
+
model="openai/gpt-5.5",
|
|
221
|
+
messages=[{"role": "user", "content": "Hi"}],
|
|
222
|
+
)
|
|
223
|
+
print(resp.choices[0].message.content)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
# Plain curl
|
|
228
|
+
curl http://localhost:4001/v1/chat/completions \
|
|
229
|
+
-H "Content-Type: application/json" \
|
|
230
|
+
-d '{"model": "openai/gpt-5.5", "messages": [{"role":"user","content":"Hi"}]}'
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### 2d. Endpoints exposed
|
|
234
|
+
|
|
235
|
+
| Method | Path | Notes |
|
|
236
|
+
|---|---|---|
|
|
237
|
+
| `POST` | `/v1/chat/completions` | OpenAI Chat Completions (non-streaming) |
|
|
238
|
+
| `GET` | `/v1/models` | BlockRun model catalog |
|
|
239
|
+
| `GET` | `/healthz` | Liveness probe (no upstream call) |
|
|
240
|
+
| `GET` | `/docs` | Auto-generated Swagger UI |
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Supported parameters
|
|
245
|
+
|
|
246
|
+
All of these are forwarded to BlockRun unchanged:
|
|
247
|
+
|
|
248
|
+
| OpenAI param | Supported | Notes |
|
|
249
|
+
|---|---|---|
|
|
250
|
+
| `model` | ✅ | Any BlockRun model id, e.g. `openai/gpt-5.5` |
|
|
251
|
+
| `messages` | ✅ | Full role/content/tool_calls schema |
|
|
252
|
+
| `max_tokens` | ✅ | Defaults to 1024 if omitted |
|
|
253
|
+
| `temperature` | ✅ | 0–2 |
|
|
254
|
+
| `top_p` | ✅ | |
|
|
255
|
+
| `tools` / `tool_choice` | ✅ | Function calling |
|
|
256
|
+
| `stream` | ❌ | **Not yet supported** — fails fast with HTTP 400. Track [blockrun-llm](https://github.com/BlockRunAI/blockrun-llm) for SSE support. |
|
|
257
|
+
| `frequency_penalty` / `presence_penalty` / `logprobs` / `n` | ⚠️ | Silently dropped — enable `litellm_settings.drop_params: True` to suppress LiteLLM warnings |
|
|
258
|
+
|
|
259
|
+
BlockRun-specific extras (also accepted):
|
|
260
|
+
|
|
261
|
+
| Param | Purpose |
|
|
262
|
+
|---|---|
|
|
263
|
+
| `search: True` | Enable xAI Live Search (for search-enabled models) |
|
|
264
|
+
| `search_parameters: {...}` | Full Live Search config |
|
|
265
|
+
| `fallback_models: ["..."]` | Auto-retry on transient upstream errors |
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Examples
|
|
270
|
+
|
|
271
|
+
The `examples/` directory has copy-paste-ready snippets:
|
|
272
|
+
|
|
273
|
+
- [`examples/python_lib.py`](examples/python_lib.py) — full LiteLLM Python library usage
|
|
274
|
+
- [`examples/litellm_config.yaml`](examples/litellm_config.yaml) — LiteLLM Proxy Server config
|
|
275
|
+
- [`examples/raw_openai_sdk.py`](examples/raw_openai_sdk.py) — pointing the OpenAI SDK at the proxy
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## How it works (under the hood)
|
|
280
|
+
|
|
281
|
+
```
|
|
282
|
+
┌─────────────────┐ OpenAI dict ┌──────────────────────┐ POST /v1/chat/completions ┌────────────────┐
|
|
283
|
+
│ Your app / │ ─────────────────▶ │ blockrun-litellm │ ────────────────────────────▶ │ blockrun.ai │
|
|
284
|
+
│ LiteLLM / │ │ (provider OR proxy) │ ◀──── 402 + payment-required ─│ gateway │
|
|
285
|
+
│ OpenAI SDK │ │ ↓ │ │ │
|
|
286
|
+
└─────────────────┘ │ blockrun-llm SDK │ ───── EIP-712 signed retry ──▶│ │
|
|
287
|
+
│ (local signing) │ ◀──── 200 + chat response ────│ │
|
|
288
|
+
└──────────────────────┘ └────────────────┘
|
|
289
|
+
▲
|
|
290
|
+
│ private key (stays local, signs only)
|
|
291
|
+
┌──────────────────────┐
|
|
292
|
+
│ BLOCKRUN_WALLET_KEY │
|
|
293
|
+
│ or ~/.blockrun/ │
|
|
294
|
+
└──────────────────────┘
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
1. Caller sends an OpenAI Chat Completions dict.
|
|
298
|
+
2. `blockrun-litellm` whitelists the params and dispatches through `blockrun-llm`.
|
|
299
|
+
3. `blockrun-llm` posts to BlockRun, receives a 402 with payment requirements, signs an EIP-712 payment locally with your wallet, and retries.
|
|
300
|
+
4. BlockRun verifies the signature on-chain, settles the USDC micropayment, runs the inference, and returns the response.
|
|
301
|
+
5. `blockrun-litellm` returns the dumped pydantic model as a plain OpenAI dict (or `litellm.ModelResponse` in provider mode).
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## FAQ
|
|
306
|
+
|
|
307
|
+
**Q: Does this support streaming?**
|
|
308
|
+
Not yet. BlockRun's x402 settlement is per-request; SSE support is on the `blockrun-llm` roadmap. Set `stream=False` (or omit it) for now.
|
|
309
|
+
|
|
310
|
+
**Q: Where does my private key live?**
|
|
311
|
+
On your machine only — `BLOCKRUN_WALLET_KEY` env var, or `~/.blockrun/.session` if you used `setup_agent_wallet()`. The proxy and provider both read from those sources via `blockrun-llm`. Only EIP-712 signatures are transmitted.
|
|
312
|
+
|
|
313
|
+
**Q: How do I switch between Base and Solana?**
|
|
314
|
+
Today this adapter wires to BlockRun's Base gateway (USDC on Base). Solana support tracks the `blockrun-llm` `SolanaLLMClient` and will be added in a follow-up release.
|
|
315
|
+
|
|
316
|
+
**Q: Can I run the proxy in Docker / k8s?**
|
|
317
|
+
Yes — it's a vanilla FastAPI app. Pass the wallet key via secret (env var), bind to `0.0.0.0` only inside a private network, and set `BLOCKRUN_PROXY_TOKEN` for an additional auth layer.
|
|
318
|
+
|
|
319
|
+
**Q: Is this affiliated with LiteLLM (BerriAI)?**
|
|
320
|
+
No — this is an independent adapter built by the BlockRun team. LiteLLM is a great project; we're just plugging into its custom-provider hooks.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## Development
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
git clone https://github.com/BlockRunAI/blockrun-litellm
|
|
328
|
+
cd blockrun-litellm
|
|
329
|
+
pip install -e '.[proxy,dev]'
|
|
330
|
+
pytest
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## License
|
|
336
|
+
|
|
337
|
+
MIT. See [LICENSE](LICENSE).
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
# 中文文档
|
|
342
|
+
|
|
343
|
+
[BlockRun](https://blockrun.ai) 的 [LiteLLM](https://github.com/BerriAI/litellm) 适配层 —— 用 LiteLLM 调用 BlockRun 上的 AI 模型,**完全零改动**。
|
|
344
|
+
|
|
345
|
+
> **一句话:** BlockRun 的 `/v1/chat/completions` 协议层就是 OpenAI 兼容的,唯一区别是认证方式 —— BlockRun 用 x402 钱包签名(按次 USDC 微支付,非托管),不是 Bearer API Key。这个包就是把这层差异填平。
|
|
346
|
+
|
|
347
|
+
## 两种对接方式
|
|
348
|
+
|
|
349
|
+
| 模式 | 适用 | 写法 |
|
|
350
|
+
|---|---|---|
|
|
351
|
+
| **1. 自定义 Provider**(进程内) | 用 LiteLLM **Python 库**的应用 | `litellm.completion(model="blockrun/openai/gpt-5.5", ...)` |
|
|
352
|
+
| **2. 本地代理**(sidecar) | 用 LiteLLM **Proxy Server** 的、或任何 OpenAI 客户端 | `api_base="http://localhost:4001/v1"` |
|
|
353
|
+
|
|
354
|
+
底层都走 [`blockrun-llm`](https://github.com/BlockRunAI/blockrun-llm) SDK 做签名和 x402 支付,两种模式行为一致。按你的部署方式选一种就行。
|
|
355
|
+
|
|
356
|
+
## 快速上手
|
|
357
|
+
|
|
358
|
+
### 安装
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
# 只装自定义 provider
|
|
362
|
+
pip install blockrun-litellm
|
|
363
|
+
|
|
364
|
+
# 同时装本地代理(带 FastAPI/uvicorn)
|
|
365
|
+
pip install 'blockrun-litellm[proxy]'
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### 配钱包(一次性)
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
# 方式 A — 环境变量(服务端推荐)
|
|
372
|
+
export BLOCKRUN_WALLET_KEY=0xYOUR_BASE_CHAIN_PRIVATE_KEY
|
|
373
|
+
|
|
374
|
+
# 方式 B — 自动创建并扫码充值(交互式)
|
|
375
|
+
python -c "from blockrun_llm import setup_agent_wallet; setup_agent_wallet()"
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
私钥**只在本地用于 EIP-712 签名**,永远不会离开你的机器。
|
|
379
|
+
|
|
380
|
+
> 💡 想零成本试一遍?用免费模型 `nvidia/deepseek-v4-flash` —— 代码完全一样,钱包流程一样,结算 $0。
|
|
381
|
+
|
|
382
|
+
### 模式 1:自定义 Provider
|
|
383
|
+
|
|
384
|
+
```python
|
|
385
|
+
import litellm
|
|
386
|
+
from blockrun_litellm import register
|
|
387
|
+
|
|
388
|
+
register() # 启动时调一次即可
|
|
389
|
+
|
|
390
|
+
response = litellm.completion(
|
|
391
|
+
model="blockrun/openai/gpt-5.5", # blockrun/<provider>/<model>
|
|
392
|
+
messages=[{"role": "user", "content": "你好"}],
|
|
393
|
+
max_tokens=128,
|
|
394
|
+
)
|
|
395
|
+
print(response.choices[0].message.content)
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
异步版本:`await litellm.acompletion(...)` 同理。
|
|
399
|
+
|
|
400
|
+
### 模式 2:本地代理
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
# 1) 启动 sidecar
|
|
404
|
+
export BLOCKRUN_WALLET_KEY=0xYOUR_KEY
|
|
405
|
+
blockrun-litellm-proxy --port 4001
|
|
406
|
+
|
|
407
|
+
# 2) LiteLLM Proxy 配置 (config.yaml)
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
```yaml
|
|
411
|
+
model_list:
|
|
412
|
+
- model_name: gpt-5.5
|
|
413
|
+
litellm_params:
|
|
414
|
+
model: openai/openai/gpt-5.5
|
|
415
|
+
api_base: http://localhost:4001/v1
|
|
416
|
+
api_key: "dummy"
|
|
417
|
+
|
|
418
|
+
litellm_settings:
|
|
419
|
+
drop_params: True
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
或者直接拿任何 OpenAI 客户端用:
|
|
423
|
+
|
|
424
|
+
```python
|
|
425
|
+
from openai import OpenAI
|
|
426
|
+
client = OpenAI(api_key="dummy", base_url="http://localhost:4001/v1")
|
|
427
|
+
resp = client.chat.completions.create(
|
|
428
|
+
model="openai/gpt-5.5",
|
|
429
|
+
messages=[{"role": "user", "content": "你好"}],
|
|
430
|
+
)
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
## 支持的参数
|
|
434
|
+
|
|
435
|
+
| OpenAI 参数 | 支持 | 备注 |
|
|
436
|
+
|---|---|---|
|
|
437
|
+
| `model` / `messages` / `max_tokens` / `temperature` / `top_p` | ✅ | |
|
|
438
|
+
| `tools` / `tool_choice` | ✅ | 函数调用 |
|
|
439
|
+
| `stream` | ❌ | **暂未支持**,请求会直接 400。SSE 支持跟随 [blockrun-llm](https://github.com/BlockRunAI/blockrun-llm) 路线图。 |
|
|
440
|
+
| `frequency_penalty` / `presence_penalty` / `logprobs` / `n` | ⚠️ | 静默丢弃 —— 建议 LiteLLM 配 `drop_params: True` 抑制告警 |
|
|
441
|
+
|
|
442
|
+
BlockRun 额外参数:
|
|
443
|
+
|
|
444
|
+
| 参数 | 作用 |
|
|
445
|
+
|---|---|
|
|
446
|
+
| `search: True` | 启用 xAI Live Search(搜索类模型) |
|
|
447
|
+
| `search_parameters: {...}` | 完整 Live Search 配置 |
|
|
448
|
+
| `fallback_models: ["..."]` | 上游抖动自动重试列表 |
|
|
449
|
+
|
|
450
|
+
## 常见问题
|
|
451
|
+
|
|
452
|
+
**Q:支持流式吗?**
|
|
453
|
+
暂时不支持。BlockRun 是按次结算的,SSE 在 `blockrun-llm` 路线图上。先用 `stream=False`。
|
|
454
|
+
|
|
455
|
+
**Q:私钥放哪?**
|
|
456
|
+
只在本地 —— `BLOCKRUN_WALLET_KEY` 环境变量,或 `setup_agent_wallet()` 创建的 `~/.blockrun/.session`。Provider 和 Proxy 都通过 `blockrun-llm` 读取。链上只看到签名,看不到私钥。
|
|
457
|
+
|
|
458
|
+
**Q:Docker / k8s 部署?**
|
|
459
|
+
代理是普通的 FastAPI 应用。密钥用 secret 注入,对外只暴露内网,可选 `BLOCKRUN_PROXY_TOKEN` 加一层 Bearer 鉴权。
|
|
460
|
+
|
|
461
|
+
**Q:和 BerriAI 是什么关系?**
|
|
462
|
+
没关系。这是 BlockRun 团队独立维护的适配层,挂在 LiteLLM 的 custom provider 接口上。
|
|
463
|
+
|
|
464
|
+
## 开发
|
|
465
|
+
|
|
466
|
+
```bash
|
|
467
|
+
git clone https://github.com/BlockRunAI/blockrun-litellm
|
|
468
|
+
cd blockrun-litellm
|
|
469
|
+
pip install -e '.[proxy,dev]'
|
|
470
|
+
pytest
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
## License
|
|
474
|
+
|
|
475
|
+
MIT
|