Remove API key env vars — keys come from DB via request payload
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 <noreply@anthropic.com>
This commit is contained in:
@@ -42,13 +42,8 @@ import litellm
|
|||||||
|
|
||||||
# --- Config ---
|
# --- Config ---
|
||||||
API_KEY = os.getenv("AGENT_INFERENCE_KEY", "agent-inference-dev-key")
|
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"))
|
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)
|
logging.basicConfig(level=logging.INFO)
|
||||||
log = logging.getLogger("agent-inference")
|
log = logging.getLogger("agent-inference")
|
||||||
|
|
||||||
@@ -529,7 +524,7 @@ app = FastAPI(title="Agent Inference Service", version="1.2.0")
|
|||||||
|
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
async def 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)
|
@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)
|
return await handle_agent0_mcp(req, agent, model, valid_poses)
|
||||||
|
|
||||||
# ── Route: standard LLM via litellm ──────────────────────────────────────
|
# ── Route: standard LLM via litellm ──────────────────────────────────────
|
||||||
model_id = model.model_id if model else FALLBACK_MODEL
|
if not model or not model.model_id:
|
||||||
api_base = model.endpoint if model else None
|
log.error(f"[{agent.name}] No inference endpoint configured for this agent")
|
||||||
api_key = model.api_key if model else None
|
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 = model.model_id
|
||||||
model_id = FALLBACK_MODEL
|
api_base = model.endpoint
|
||||||
|
api_key = model.api_key
|
||||||
|
|
||||||
total_messages = len(req.history) + 1
|
total_messages = len(req.history) + 1
|
||||||
system_prompt = build_system_prompt(agent, message_count=total_messages)
|
system_prompt = build_system_prompt(agent, message_count=total_messages)
|
||||||
|
|||||||
Reference in New Issue
Block a user