666ghj/MiroFish · critical · ValueError
LLM_API_KEY 未配置
Error message
LLM_API_KEY 未配置
What it means
Raised in OasisProfileGenerator.__init__: the constructor takes an optional api_key but falls back to Config.LLM_API_KEY, and if both are empty it raises ValueError('LLM_API_KEY 未配置') before constructing the OpenAI client. This is a bootstrap-time configuration check — the LLM client for profile generation cannot be created without credentials.
Source
Thrown at backend/app/services/oasis_profile_generator.py:256
GROUP_ENTITY_TYPES = [
"university", "governmentagency", "organization", "ngo",
"mediaoutlet", "company", "institution", "group", "community"
]
def __init__(
self,
api_key: Optional[str] = None,
base_url: Optional[str] = None,
model_name: Optional[str] = None,
zep_api_key: Optional[str] = None,
graph_id: Optional[str] = None
):
self.api_key = api_key or Config.LLM_API_KEY
self.base_url = base_url or Config.LLM_BASE_URL
self.model_name = model_name or Config.LLM_MODEL_NAME
if not self.api_key:
raise ValueError("LLM_API_KEY 未配置")
self.client = OpenAI(
api_key=self.api_key,
base_url=self.base_url
)
# Zep客户端用于检索丰富上下文
self.zep_api_key = zep_api_key or Config.ZEP_API_KEY
self.zep_client = None
self.graph_id = graph_id
if self.zep_api_key:
try:
self.zep_client = get_zep_client(self.zep_api_key)
except Exception as e:
logger.warning(f"Zep客户端初始化失败: {e}")
def generate_profile_from_entity(View on GitHub (pinned to b5b53acc57)
Solutions
- Set LLM_API_KEY in the backend environment (.env, docker-compose environment block, or export) and restart.
- Or pass api_key explicitly when constructing OasisProfileGenerator.
- Verify the key name matches Config.LLM_API_KEY exactly and that the env file is actually loaded where the process starts.
- For tests, patch Config.LLM_API_KEY or inject a dummy key so construction succeeds.
Example fix
# before gen = OasisProfileGenerator() # ValueError: LLM_API_KEY 未配置 # after # .env LLM_API_KEY=sk-... LLM_BASE_URL=https://api.example.com/v1 gen = OasisProfileGenerator()
Defensive patterns
Strategy: validation
Validate before calling
from app.config import Config assert Config.LLM_API_KEY, 'LLM_API_KEY missing: set it in .env before starting the backend'
Try / catch
try:
gen = OasisProfileGenerator()
except ValueError as e:
if 'LLM_API_KEY' in str(e):
raise SystemExit('Configure LLM_API_KEY in the environment and restart') from e
raise Prevention
- Fail fast at process startup: validate required env vars before serving requests.
- Keep a template .env.example listing LLM_API_KEY, LLM_BASE_URL, LLM_MODEL_NAME.
- In CI/tests, patch Config.LLM_API_KEY with a dummy value.
When it happens
Trigger: Instantiating OasisProfileGenerator (directly or via the profile-generation flow) when the LLM_API_KEY environment variable is unset/empty and no api_key argument is passed. Common in fresh deployments, CI, or containers that don't load the .env file.
Common situations: Missing entry in .env / docker-compose environment; backend started without loading dotenv; typo in the variable name (LLM_APIKEY, LLM_KEY); deploying to a new environment and forgetting to port secrets; running tests that construct the service without patching Config.
Related errors
- LLM_API_KEY 未配置
- LLM_API_KEY 未配置
- 缺少 API Key 配置,请在项目根目录 .env 文件中设置 LLM_API_KEY
- 缺少 API Key 配置,请在项目根目录 .env 文件中设置 LLM_API_KEY
- 缺少 API Key 配置,请在项目根目录 .env 文件中设置 LLM_API_KEY
AI-assisted analysis of 666ghj/MiroFish@b5b53acc57 (2026-08-14).
Data as JSON: /api/errors/06f62085dbf93002.
Report an issue: GitHub.