{"record":{"id":"187cd908d2baac8c","repo":"HKUDS/DeepTutor","slug":"openai-api-key-is-not-configured-set-it-in-settin-187cd9","errorCode":null,"errorMessage":"OpenAI API key is not configured. Set it in Settings > Catalog, or select a local provider such as Ollama.","messagePattern":"OpenAI API key is not configured\\. Set it in Settings > Catalog, or select a local provider such as Ollama\\.","errorType":"validation","errorClass":"LLMConfigError","httpStatus":null,"severity":"error","filePath":"deeptutor/services/llm/provider_core/openai_compat_provider.py","lineNumber":150,"sourceCode":"        self.extra_headers = extra_headers or {}\n        self._spec = spec\n        self._provider_name = provider_name\n\n        if primary_key and spec and spec.env_key:\n            self._setup_env(primary_key, api_base)\n\n        effective_base = api_base or (spec.default_api_base if spec else None) or None\n        self._effective_base = effective_base\n        endpoint = (effective_base or \"\").rstrip(\"/\")\n        # api_key may be a list (key pool); only the resolved primary key\n        # counts for the configured-key check.\n        placeholder_key = primary_key in {None, \"\", \"no-key\", \"sk-no-key-required\"}\n        if (\n            provider_name == \"openai\"\n            and (not endpoint or endpoint == \"https://api.openai.com/v1\")\n            and placeholder_key\n        ):\n            raise LLMConfigError(\n                \"OpenAI API key is not configured. Set it in Settings > Catalog, \"\n                \"or select a local provider such as Ollama.\"\n            )\n        default_headers: dict[str, str] = {\"x-session-affinity\": uuid.uuid4().hex}\n        if _uses_openrouter(spec, effective_base):\n            default_headers.update(_DEFAULT_OPENROUTER_HEADERS)\n        if extra_headers:\n            default_headers.update(extra_headers)\n\n        self._client = AsyncOpenAI(\n            api_key=primary_key or \"no-key\",\n            base_url=effective_base,\n            default_headers=default_headers,\n            max_retries=0,\n            **openai_client_kwargs(),\n        )\n        self._responses_failures: dict[str, int] = {}\n        self._responses_tripped_at: dict[str, float] = {}","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/services/llm/provider_core/openai_compat_provider.py#L132-L168","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nspec = {'provider': 'openai', 'api_key': 'no-key'}\n# after\nspec = {'provider': 'openai', 'api_key': os.environ['OPENAI_API_KEY']}","handlingStrategy":"validation","validationCode":"PLACEHOLDERS = {None, '', 'no-key', 'sk-no-key-required'}\n\ndef openai_provider_instantiable(spec: dict) -> bool:\n    if spec.get('provider') != 'openai':\n        return True\n    custom = spec.get('endpoint') not in (None, '', 'https://api.openai.com/v1')\n    return custom or spec.get('api_key') not in PLACEHOLDERS","typeGuard":null,"tryCatchPattern":"try:\n    prov = build_openai_compat_provider(spec)\nexcept LLMConfigError as e:\n    if 'API key is not configured' in str(e):\n        spec['api_key'] = os.environ['OPENAI_API_KEY']; prov = build_openai_compat_provider(spec)\n    else:\n        raise","preventionTips":["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"],"tags":["config","openai","missing-api-key"],"backgroundTag":"missing-api-key","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}