{"record":{"id":"4c92d3be08d4d3d5","repo":"sgl-project/sglang","slug":"crusoe-api-key-required-pass-api-key-or-set-crus","errorCode":null,"errorMessage":"Crusoe API key required. Pass api_key= or set CRUSOE_API_KEY.","messagePattern":"Crusoe API key required\\. Pass api_key= or set CRUSOE_API_KEY\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/lang/backend/crusoe.py","lineNumber":33,"sourceCode":"\n    Args:\n        model_name: The model to use, e.g. \"meta-llama/Llama-3.1-8B-Instruct\".\n        api_key: Crusoe API key. Defaults to CRUSOE_API_KEY env var.\n        base_url: Override the Crusoe endpoint. Defaults to the Crusoe API.\n        chat_template: Optional custom chat template.\n    \"\"\"\n\n    def __init__(\n        self,\n        model_name: str,\n        api_key: Optional[str] = None,\n        base_url: Optional[str] = None,\n        chat_template: Optional[ChatTemplate] = None,\n        **kwargs,\n    ):\n        resolved_api_key = api_key or os.environ.get(\"CRUSOE_API_KEY\")\n        if not resolved_api_key:\n            raise ValueError(\n                \"Crusoe API key required. Pass api_key= or set CRUSOE_API_KEY.\"\n            )\n\n        super().__init__(\n            model_name=model_name,\n            chat_template=chat_template,\n            api_key=resolved_api_key,\n            base_url=base_url or CRUSOE_BASE_URL,\n            **kwargs,\n        )\n","sourceCodeStart":15,"sourceCodeEnd":44,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/backend/crusoe.py#L15-L44","documentation":"The Crusoe backend (CrusoeAI) requires an API key, resolved from the api_key argument or the CRUSOE_API_KEY environment variable. If neither is present, __init__ raises ValueError immediately — fail-fast credential validation before any request is made.","triggerScenarios":"Constructing sgl.CrusoeAI(model_name=...) without api_key= on a machine where CRUSOE_API_KEY is not exported; common in fresh shells, CI, or containers.","commonSituations":"Deploying to a new environment without copying env config; shell scripts that don't source the .env file; CI secrets not wired to the CRUSOE_API_KEY variable name.","solutions":["Export CRUSOE_API_KEY in the environment: export CRUSOE_API_KEY=sk-... (add to .env/shell profile).","Or pass the key explicitly: sgl.CrusoeAI(model_name=..., api_key='sk-...').","In CI, add CRUSOE_API_KEY as a masked secret variable."],"exampleFix":"# before\nbackend = sgl.CrusoeAI(model_name=\"crusoe-model\")\n\n# after\nbackend = sgl.CrusoeAI(model_name=\"crusoe-m\", api_key=os.environ[\"CRUSOE_API_KEY\"])\n# or: export CRUSOE_API_KEY=sk-... then construct as before","handlingStrategy":"validation","validationCode":"import os\nif not (os.environ.get(\"CRUSOE_API_KEY\") or api_key):\n    raise SystemExit(\"Set CRUSOE_API_KEY or pass api_key=\")\nbackend = sgl.CrusoeAI(model_name=..., api_key=api_key)","typeGuard":null,"tryCatchPattern":"try:\n    backend = sgl.CrusoeAI(model_name=m)\nexcept ValueError as e:\n    if \"CRUSOE_API_KEY\" in str(e):\n        api_key = getpass(\"Crusoe API key: \")\n        backend = sgl.CrusoeAI(model_name=m, api_key=api_key)\n    else:\n        raise","preventionTips":["Load .env at app start (python-dotenv) before constructing backends.","Fail fast on missing secrets in a startup preflight check."],"tags":["frontend","api-key","missing-env-var","crusoe","sglang"],"backgroundTag":"missing-api-key","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}