{"record":{"id":"9abc20f99f47df11","repo":"Significant-Gravitas/AutoGPT","slug":"openai-api-key-not-configured","errorCode":null,"errorMessage":"OpenAI API key not configured","messagePattern":"OpenAI API key not configured","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/admin/execution_analytics_routes.py","lineNumber":354,"sourceCode":"        logger.info(\n            f\"Analytics generation completed: {successful_count} successful, {failed_count} failed, \"\n            f\"{response.skipped_executions} skipped\"\n        )\n\n        return response\n\n    except Exception as e:\n        logger.exception(f\"Error during execution analytics generation: {e}\")\n        raise HTTPException(status_code=500, detail=str(e))\n\n\nasync def _process_batch(\n    executions, request: ExecutionAnalyticsRequest, db_client\n) -> list[ExecutionAnalyticsResult]:\n    \"\"\"Process a batch of executions concurrently.\"\"\"\n\n    if not settings.secrets.openai_internal_api_key:\n        raise HTTPException(status_code=500, detail=\"OpenAI API key not configured\")\n\n    async def process_single_execution(execution) -> ExecutionAnalyticsResult:\n        try:\n            # Generate activity status and score using the specified model\n            # Convert stats to GraphExecutionStats if needed\n            if execution.stats:\n                if isinstance(execution.stats, GraphExecutionMeta.Stats):\n                    stats_for_generation = execution.stats.to_db()\n                else:\n                    # Already GraphExecutionStats\n                    stats_for_generation = execution.stats\n            else:\n                stats_for_generation = GraphExecutionStats()\n\n            activity_response = await generate_activity_status_for_execution(\n                graph_exec_id=execution.id,\n                graph_id=execution.graph_id,\n                graph_version=execution.graph_version,","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/admin/execution_analytics_routes.py#L336-L372","documentation":"HTTP 500 raised inside _process_batch of the admin execution-analytics routes before any execution is processed: settings.secrets.openai_internal_api_key is empty/None, so the OpenAI calls used to generate activity status/score cannot be made. This is a configuration error surfaced as an HTTP error to the caller.","triggerScenarios":"POST /admin/execution-analytics on a deployment where OPENAI_INTERNAL_API_KEY (the internal analytics key) is not set in the backend .env / secrets. Every analytics-generation request fails before doing work.","commonSituations":"Fresh local or staging deployment that only copied .env.default; secret rotated to empty; analytics feature enabled in UI while the ops config was never provisioned.","solutions":["Set the internal OpenAI API key in the backend secrets (backend .env / configured secret store) and restart the API.","Verify with a settings dump or health check that settings.secrets.openai_internal_api_key is non-empty.","Until configured, disable the analytics-generation UI action so admins don't hit the 500."],"exampleFix":"# backend .env\n# before\n# OPENAI_INTERNAL_API_KEY=\n\n# after\nOPENAI_INTERNAL_API_KEY=sk-...","handlingStrategy":"validation","validationCode":"// Pre-flight in a shell: poetry run python -c \"from backend.util.settings import Settings; print(bool(Settings().secrets.openai_internal_api_key))\" → must print True","typeGuard":null,"tryCatchPattern":"try { await generateAnalytics(req); } catch (e) { if (e.status === 500 && /API key/.test(e.detail)) { /* config issue: surface 'analytics not configured' to the admin, do not retry */ } }","preventionTips":["Provision OPENAI_INTERNAL_API_KEY in every environment that exposes the analytics UI.","Add a startup/health assertion for required analytics secrets.","Hide the generate-analytics action when the key is absent."],"tags":["http-500","admin-api","configuration","secrets","openai"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}