HKUDS/DeepTutor · error · LLMConfigError
OpenAI API key is not configured. Set it in Settings > Catal
Error message
OpenAI API key is not configured. Set it in Settings > Catalog, or select a local provider such as Ollama.
What it means
The OpenAI-compatible provider refuses to instantiate for provider_name='openai' targeting the official api.openai.com endpoint with a placeholder key (None, '', 'no-key', 'sk-no-key-required'), since real API calls would just fail with 401 later. LLMConfigError is raised at construction time with actionable copy.
Source
Thrown at deeptutor/services/llm/provider_core/openai_compat_provider.py:150
self.extra_headers = extra_headers or {}
self._spec = spec
self._provider_name = provider_name
if primary_key and spec and spec.env_key:
self._setup_env(primary_key, api_base)
effective_base = api_base or (spec.default_api_base if spec else None) or None
self._effective_base = effective_base
endpoint = (effective_base or "").rstrip("/")
# api_key may be a list (key pool); only the resolved primary key
# counts for the configured-key check.
placeholder_key = primary_key in {None, "", "no-key", "sk-no-key-required"}
if (
provider_name == "openai"
and (not endpoint or endpoint == "https://api.openai.com/v1")
and placeholder_key
):
raise LLMConfigError(
"OpenAI API key is not configured. Set it in Settings > Catalog, "
"or select a local provider such as Ollama."
)
default_headers: dict[str, str] = {"x-session-affinity": uuid.uuid4().hex}
if _uses_openrouter(spec, effective_base):
default_headers.update(_DEFAULT_OPENROUTER_HEADERS)
if extra_headers:
default_headers.update(extra_headers)
self._client = AsyncOpenAI(
api_key=primary_key or "no-key",
base_url=effective_base,
default_headers=default_headers,
max_retries=0,
**openai_client_kwargs(),
)
self._responses_failures: dict[str, int] = {}
self._responses_tripped_at: dict[str, float] = {}View on GitHub (pinned to 3e82f13042)
Solutions
- Set a real OpenAI API key in Settings > Catalog (or OPENAI_API_KEY env var).
- Or switch the provider to a local one (Ollama) that doesn't need a key.
- If using a custom OpenAI-compatible gateway, set its endpoint so this guard doesn't apply.
Example fix
# before
spec = {'provider': 'openai', 'api_key': 'no-key'}
# after
spec = {'provider': 'openai', 'api_key': os.environ['OPENAI_API_KEY']} Defensive patterns
Strategy: validation
Validate before calling
PLACEHOLDERS = {None, '', 'no-key', 'sk-no-key-required'}
def openai_provider_instantiable(spec: dict) -> bool:
if spec.get('provider') != 'openai':
return True
custom = spec.get('endpoint') not in (None, '', 'https://api.openai.com/v1')
return custom or spec.get('api_key') not in PLACEHOLDERS Try / catch
try:
prov = build_openai_compat_provider(spec)
except LLMConfigError as e:
if 'API key is not configured' in str(e):
spec['api_key'] = os.environ['OPENAI_API_KEY']; prov = build_openai_compat_provider(spec)
else:
raise Prevention
- Export OPENAI_API_KEY in the environment or settings before building providers
- Fail startup fast when the active provider is OpenAI without a key
- Default new setups to a local provider like Ollama when no key exists
When it happens
Trigger: Building the provider with spec for 'openai' with no custom endpoint (or the default https://api.openai.com/v1) and a placeholder key — typical when a local-style keyless config is reused for OpenAI.
Common situations: Switching a local/Ollama setup to OpenAI without adding a key; a UI/settings template that pre-fills 'no-key'; env var OPENAI_API_KEY unset so the pool falls back to a placeholder.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- PageIndex API key is not configured. Add it under Knowledge
- Azure OpenAI api_key is required
- Model not configured for OpenAI provider
- mcp.configure_command_or_url
- mcp.server_error
AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27).
Data as JSON: /api/errors/187cd908d2baac8c.
Report an issue: GitHub.