From 604df52247d8ae893e82c044548b38aba63b9ac3 Mon Sep 17 00:00:00 2001 From: jenstandstad Date: Sun, 26 Apr 2026 17:53:07 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20API=20key=20env=20vars=20=E2=80=94=20k?= =?UTF-8?q?eys=20come=20from=20DB=20via=20request=20payload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit API keys (Anthropic, OpenAI etc.) are stored in the inference_endpoints table and passed through the request from gnommoweb. Removed the API_KEY_ANTHROPIC / AGENT_INFERENCE_MODEL env var fallbacks entirely. Missing endpoint config now returns a clear error instead of silently falling back to a hardcoded model. Co-Authored-By: Claude Sonnet 4.6 --- server.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/server.py b/server.py index f2e6dd8..c5f85fa 100644 --- a/server.py +++ b/server.py @@ -42,13 +42,8 @@ import litellm # --- Config --- API_KEY = os.getenv("AGENT_INFERENCE_KEY", "agent-inference-dev-key") -FALLBACK_MODEL = os.getenv("AGENT_INFERENCE_MODEL", "anthropic/claude-sonnet-4-20250514") -ANTHROPIC_KEY = os.getenv("API_KEY_ANTHROPIC", "") AGENT_MAX_MESSAGES = int(os.getenv("AGENT_INFERENCE_MAX_MESSAGES", "10")) -if ANTHROPIC_KEY: - os.environ["ANTHROPIC_API_KEY"] = ANTHROPIC_KEY - logging.basicConfig(level=logging.INFO) log = logging.getLogger("agent-inference") @@ -529,7 +524,7 @@ app = FastAPI(title="Agent Inference Service", version="1.2.0") @app.get("/health") async def health(): - return {"status": "ok", "service": "agent-inference", "fallback_model": FALLBACK_MODEL} + return {"status": "ok", "service": "agent-inference"} @app.post("/v1/agent/chat", response_model=ChatResponse) @@ -559,12 +554,19 @@ async def agent_chat(req: ChatRequest, authorization: str = Header(default="")): return await handle_agent0_mcp(req, agent, model, valid_poses) # ── Route: standard LLM via litellm ────────────────────────────────────── - model_id = model.model_id if model else FALLBACK_MODEL - api_base = model.endpoint if model else None - api_key = model.api_key if model else None + if not model or not model.model_id: + log.error(f"[{agent.name}] No inference endpoint configured for this agent") + return ChatResponse( + letter_id=0, + timestamp=int(time.time()), + message="*configuration error* No inference endpoint configured for this agent.", + pose=valid_poses[0], + conversation_id=req.conversation_id, + ) - if not model_id: - model_id = FALLBACK_MODEL + model_id = model.model_id + api_base = model.endpoint + api_key = model.api_key total_messages = len(req.history) + 1 system_prompt = build_system_prompt(agent, message_count=total_messages)