From ff781f9824973cb86b0aaabfc31053b272dcf4a1 Mon Sep 17 00:00:00 2001 From: ClaudioDrews Date: Wed, 3 Jun 2026 09:37:38 -0300 Subject: [PATCH] feat: add EMBEDDING_API_KEY for authenticated non-OpenRouter endpoints (fixes #8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit embedding.py: - Add EMBEDDING_API_KEY env var (no fallback — explicit per-branch) - OpenRouter branch: uses OPENROUTER_API_KEY + vendor headers - Generic branch: sends Authorization: Bearer if set - Unauth fallback: no header (localhost, no auth needed) - Credential isolation: no cross-branch key leakage .env.example + setup/install.md: - Document EMBEDDING_API_KEY as optional for non-OpenRouter authenticated endpoints (vLLM --api-key, custom hosted services) --- .env.example | 5 +++++ docker/worker/services/embedding.py | 4 ++++ setup/install.md | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/.env.example b/.env.example index ce8e222..bc4a9eb 100644 --- a/.env.example +++ b/.env.example @@ -58,6 +58,11 @@ MAA_ENV_PATH=/home/your-user/.env # EMBEDDING_API_BASE=https://openrouter.ai/api/v1 # EMBEDDING_MODEL=qwen/qwen3-embedding-8b +# API key for non-OpenRouter authenticated endpoints (vLLM with --api-key, +# custom hosted embedding services). Not needed for OpenRouter (uses +# OPENROUTER_API_KEY) or local unauthenticated providers. +# EMBEDDING_API_KEY=your-key-here + # ── Strongly Recommended ────────────────────────────── # LLM extraction token limit — 1024 is too small, causes fabric truncation diff --git a/docker/worker/services/embedding.py b/docker/worker/services/embedding.py index b9d6ee6..450d746 100644 --- a/docker/worker/services/embedding.py +++ b/docker/worker/services/embedding.py @@ -11,6 +11,7 @@ import httpx logger = logging.getLogger("cognitive-worker.embedding") OPENROUTER_API_KEY = os.environ.get("OPENROUTER_API_KEY", "") +EMBEDDING_API_KEY = os.environ.get("EMBEDDING_API_KEY") # no fallback — explicit per-branch EMBEDDING_DIMS = int(os.environ.get("EMBEDDING_DIMS", "4096")) EMBEDDING_API_BASE = os.environ.get( "EMBEDDING_API_BASE", "https://openrouter.ai/api/v1" @@ -33,6 +34,9 @@ async def get_embedding(text: str) -> list[float]: headers["Authorization"] = f"Bearer {OPENROUTER_API_KEY}" headers["HTTP-Referer"] = "https://localhost" headers["X-Title"] = "Cognitive-Agent-MaaS" + elif EMBEDDING_API_KEY: + headers["Authorization"] = f"Bearer {EMBEDDING_API_KEY}" + # else: no auth header — localhost or unauthenticated endpoint payload = { "model": EMBEDDING_MODEL, diff --git a/setup/install.md b/setup/install.md index 948da5c..b148e9d 100644 --- a/setup/install.md +++ b/setup/install.md @@ -95,6 +95,11 @@ EMBEDDING_DIMS=4096 # EMBEDDING_API_BASE=https://openrouter.ai/api/v1 # EMBEDDING_MODEL=qwen/qwen3-embedding-8b +# Optional — API key for non-OpenRouter authenticated embedding endpoints +# (vLLM with --api-key, custom hosted services). Not needed for OpenRouter +# or local unauthenticated providers. +# EMBEDDING_API_KEY=your-key-here + # Optional ICARUS_OBSIDIAN=1 ICARUS_RESULT_MAX_CHARS=500