Environment Detection helper (env.py)

This helper centralizes environment-specific setup for notebooks that rely on external APIs (e.g. OpenAI, Anthropic).

The goal is to ensure that the same notebook runs unchanged in multiple contexts:

Rather than scattering environment checks throughout notebooks, all logic for detecting the execution environment and loading API keys lives here.


load_env


def load_env(
    
): # One of {"colab", "dotenv", "external"}, indicating which environment
was detected.

Load API keys in a platform-aware way.

This function attempts to populate environment variables required by downstream helpers. The strategy depends on where the notebook is running:

  • Google Colab: read keys from google.colab.userdata
  • Local development: load keys from a .env file if present
  • Hosted environments (e.g. Deepnote / Solveit): assume keys are already injected

Only SUBMIT_API_KEY is required for assignment submission. LLM keys (ANTHROPIC_API_KEY, OPENAI_API_KEY) are optional — notebooks that do not use LLMs will work fine without them.

The function does not validate keys or make API calls.