{"record":{"id":"7993e3578a7e57a7","repo":"huggingface/open-r1","slug":"morph-api-key-environment-variable-is-required","errorCode":null,"errorMessage":"MORPH_API_KEY environment variable is required","messagePattern":"MORPH_API_KEY environment variable is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/open_r1/utils/competitive_programming/morph_client.py","lineNumber":737,"sourceCode":"    Environment variables:\n        MORPH_API_KEY: API key for MorphCloud\n\n    Args:\n        session: Optional aiohttp.ClientSession to use for HTTP requests\n\n    Returns:\n        MorphCloudExecutionClient: A configured MorphCloud execution client\n    \"\"\"\n    if not is_morph_available():\n        raise ImportError(\n            \"MorphCloud is not available and required for this function. Please install MorphCloud with \"\n            \"`pip install morphcloud` and add an API key to a `.env` file.\"\n        )\n\n    load_dotenv()\n    api_key = os.environ.get(\"MORPH_API_KEY\")\n    if not api_key:\n        raise ValueError(\"MORPH_API_KEY environment variable is required\")\n\n    return MorphCloudExecutionClient(api_key=api_key)\n\n\n# noqa: W293\n","sourceCodeStart":719,"sourceCodeEnd":743,"githubUrl":"https://github.com/huggingface/open-r1/blob/1416fa0cf21595d2083b399a2a0bbddd7f6e9563/src/open_r1/utils/competitive_programming/morph_client.py#L719-L743","documentation":"After confirming MorphCloud is importable, get_morph_client_from_env loads .env and reads MORPH_API_KEY. If the variable is unset or empty it raises ValueError, because constructing MorphCloudExecutionClient requires a valid API key for MorphCloud's API.","triggerScenarios":"Calling get_morph_client_from_env (via ioi_code_reward with the morph backend) when the MORPH_API_KEY environment variable is not set — no .env file present, .env not in the process working directory, or the variable named incorrectly (e.g. MORPH_TOKEN).","commonSituations":"Forgot to create .env; .env exists but in a different directory than where the script runs; exporting the variable in a shell session that didn't propagate (e.g. systemd, CI secrets not injected); typo in variable name.","solutions":["Add MORPH_API_KEY=<your key> to a .env file in the working directory where the script is launched.","Or export MORPH_API_KEY in the shell/environment running the reward pipeline.","Verify with python -c \"import os; from dotenv import load_dotenv; load_dotenv(); print(os.environ.get('MORPH_API_KEY'))\".","In CI, ensure the secret is injected into the job environment under the exact name MORPH_API_KEY."],"exampleFix":"// before\n$ python reward.py  # ValueError: MORPH_API_KEY required\n// after\n$ echo 'MORPH_API_KEY=morph_...' >> .env && python reward.py","handlingStrategy":"validation","validationCode":"import os\nfrom dotenv import load_dotenv\nload_dotenv()\nassert os.environ.get('MORPH_API_KEY'), 'MORPH_API_KEY missing: add it to .env or export it'","typeGuard":"def morph_key_present() -> bool:\n    return bool(os.environ.get('MORPH_API_KEY'))","tryCatchPattern":"try:\n    client = get_morph_client_from_env()\nexcept ValueError as e:\n    if 'MORPH_API_KEY' in str(e):\n        raise SystemExit('Set MORPH_API_KEY in .env before running IOI rewards') from e\n    raise","preventionTips":["Keep a .env.example with MORPH_API_KEY documented","Load .env from the script's launch directory (cwd matters for load_dotenv)","Inject the secret by its exact name in CI/cluster environments","Validate required env vars in an entrypoint script before starting training"],"tags":["morphcloud","missing-env-var","authentication"],"backgroundTag":"missing-env-var","analyzedSha":"1416fa0cf21595d2083b399a2a0bbddd7f6e9563","analyzedAt":"2026-08-30T08:56:53.400Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}