Eric Xu commited on
Fix: use custom X-LLM headers instead of Authorization (HF proxy intercepts it)
Browse files- web/app.py +4 -12
- web/static/index.html +4 -2
web/app.py
CHANGED
|
@@ -169,18 +169,10 @@ def _check_rate_limit(ip: str):
|
|
| 169 |
|
| 170 |
@app.middleware("http")
|
| 171 |
async def inject_llm_config(request: Request, call_next):
|
| 172 |
-
"""Read LLM creds from
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
parts = auth[7:].split("|", 2)
|
| 177 |
-
request.state.api_key = parts[0] if len(parts) > 0 else ""
|
| 178 |
-
request.state.base_url = parts[1] if len(parts) > 1 else ""
|
| 179 |
-
request.state.model = parts[2] if len(parts) > 2 else ""
|
| 180 |
-
else:
|
| 181 |
-
request.state.api_key = ""
|
| 182 |
-
request.state.base_url = ""
|
| 183 |
-
request.state.model = ""
|
| 184 |
return await call_next(request)
|
| 185 |
|
| 186 |
|
|
|
|
| 169 |
|
| 170 |
@app.middleware("http")
|
| 171 |
async def inject_llm_config(request: Request, call_next):
|
| 172 |
+
"""Read LLM creds from custom headers (not Authorization — HF proxy intercepts that)."""
|
| 173 |
+
request.state.api_key = request.headers.get("x-llm-key", "")
|
| 174 |
+
request.state.base_url = request.headers.get("x-llm-base", "")
|
| 175 |
+
request.state.model = request.headers.get("x-llm-model", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
return await call_next(request)
|
| 177 |
|
| 178 |
|
web/static/index.html
CHANGED
|
@@ -724,10 +724,12 @@ let llmBaseUrl = '';
|
|
| 724 |
let llmModel = '';
|
| 725 |
|
| 726 |
function llmHeaders() {
|
| 727 |
-
// Send credentials via
|
| 728 |
const h = {'Content-Type': 'application/json'};
|
| 729 |
if (llmApiKey) {
|
| 730 |
-
h['
|
|
|
|
|
|
|
| 731 |
}
|
| 732 |
return h;
|
| 733 |
}
|
|
|
|
| 724 |
let llmModel = '';
|
| 725 |
|
| 726 |
function llmHeaders() {
|
| 727 |
+
// Send credentials via custom header (not Authorization — HF proxy intercepts that)
|
| 728 |
const h = {'Content-Type': 'application/json'};
|
| 729 |
if (llmApiKey) {
|
| 730 |
+
h['X-LLM-Key'] = llmApiKey;
|
| 731 |
+
if (llmBaseUrl) h['X-LLM-Base'] = llmBaseUrl;
|
| 732 |
+
if (llmModel) h['X-LLM-Model'] = llmModel;
|
| 733 |
}
|
| 734 |
return h;
|
| 735 |
}
|