Significant-Gravitas/AutoGPT · error · HTTPException

OpenAI API key not configured

Error message

OpenAI API key not configured

What it means

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.

Source

Thrown at autogpt_platform/backend/backend/api/features/admin/execution_analytics_routes.py:354

        logger.info(
            f"Analytics generation completed: {successful_count} successful, {failed_count} failed, "
            f"{response.skipped_executions} skipped"
        )

        return response

    except Exception as e:
        logger.exception(f"Error during execution analytics generation: {e}")
        raise HTTPException(status_code=500, detail=str(e))


async def _process_batch(
    executions, request: ExecutionAnalyticsRequest, db_client
) -> list[ExecutionAnalyticsResult]:
    """Process a batch of executions concurrently."""

    if not settings.secrets.openai_internal_api_key:
        raise HTTPException(status_code=500, detail="OpenAI API key not configured")

    async def process_single_execution(execution) -> ExecutionAnalyticsResult:
        try:
            # Generate activity status and score using the specified model
            # Convert stats to GraphExecutionStats if needed
            if execution.stats:
                if isinstance(execution.stats, GraphExecutionMeta.Stats):
                    stats_for_generation = execution.stats.to_db()
                else:
                    # Already GraphExecutionStats
                    stats_for_generation = execution.stats
            else:
                stats_for_generation = GraphExecutionStats()

            activity_response = await generate_activity_status_for_execution(
                graph_exec_id=execution.id,
                graph_id=execution.graph_id,
                graph_version=execution.graph_version,

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Set the internal OpenAI API key in the backend secrets (backend .env / configured secret store) and restart the API.
  2. Verify with a settings dump or health check that settings.secrets.openai_internal_api_key is non-empty.
  3. Until configured, disable the analytics-generation UI action so admins don't hit the 500.

Example fix

# backend .env
# before
# OPENAI_INTERNAL_API_KEY=

# after
OPENAI_INTERNAL_API_KEY=sk-...
Defensive patterns

Strategy: validation

Validate before calling

// 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

Try / catch

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 */ } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/9abc20f99f47df11. Report an issue: GitHub.