Eric Xu commited on
Commit
dff6d17
·
unverified ·
1 Parent(s): 5c12db7

Fix: use custom X-LLM headers instead of Authorization (HF proxy intercepts it)

Browse files
Files changed (2) hide show
  1. web/app.py +4 -12
  2. 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 Authorization header (not query params those get logged)."""
173
- # Authorization: Bearer <api_key>|<base_url>|<model> (pipe-separated)
174
- auth = request.headers.get("authorization", "")
175
- if auth.startswith("Bearer "):
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 AuthorizationHF 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 Authorization header (never in URL/query params)
728
  const h = {'Content-Type': 'application/json'};
729
  if (llmApiKey) {
730
- h['Authorization'] = `Bearer ${llmApiKey}|${llmBaseUrl}|${llmModel}`;
 
 
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
  }