feat: add EMBEDDING_API_KEY for authenticated non-OpenRouter endpoints (fixes #8)
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 <EMBEDDING_API_KEY> 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)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user