feat: add custom headers support for LLM model pool#92
feat: add custom headers support for LLM model pool#92Cluas wants to merge 3 commits intodataelement:mainfrom
Conversation
yaojin3616
left a comment
There was a problem hiding this comment.
Summary: I’m requesting changes. The PR adds custom LLM headers + symmetric encryption, but there are two blocking issues and a couple of sharp edges.
Blocking
- Missing dependency for AES
backend/app/core/security.py imports Crypto.Cipher.AES, but backend/pyproject.toml doesn’t include pycryptodome. This will crash at import time in
environments without it.
Fix: add pycryptodome or switch to cryptography (already present). - Header override can silently break auth
backend/app/services/llm_client.py merges custom_headers over default headers, which allows overriding Authorization, Content-Type, and anthropic-
version. This is too easy to misconfigure and is a production risk.
Fix: block overriding these keys, or only allow overrides for provider=custom.
Non-blocking (but please consider)
- Editing headers UX is incomplete: existing headers aren’t visible and there’s no explicit “clear headers” action. Users can’t confidently manage
what’s already stored.
Once the dependency and header-override issues are addressed, I’m good to re-review quickly.
46fe9f7 to
5d7e33b
Compare
Thanks for the thorough review! Here's how each issue has been addressed: Blocking #1 — Missing AES dependency Switched from pycryptodome (Crypto.Cipher.AES) to the cryptography package (already a project dependency via python-jose[cryptography]), using cryptography.hazmat.primitives.ciphers.aead.AESGCM. Also removed the now-unused pycryptodome entry Blocking #2 — Header override silently breaking auth Added a module-level constant _PROTECTED_HEADER_KEYS in llm_client.py: _PROTECTED_HEADER_KEYS: frozenset[str] = frozenset( Both OpenAICompatibleClient._get_headers() and AnthropicClient._get_headers() now strip any custom header whose key (case-insensitive) matches this set before merging, so auth and protocol headers can never be overridden by user config. Non-blocking — Editing headers UX Three improvements made:
|
Summary
Closes #91
Adds support for configuring custom HTTP headers on LLM models in the model pool. This enables gateway authentication tokens, vendor-specific auth supplements, or routing headers required by self-hosted proxies.
Changes
Backend
headers_encrypted TEXTcolumn tollm_models(idempotent)encrypt_symmetric/decrypt_symmetrichelpers (AES-GCM)headers_encrypted: Mapped[str | None]headers: dict | Noneon Create/Update/Out schemasFrontend
Security
Header values are encrypted at rest using AES-GCM (same key as API keys) and never returned in API responses.