sgl-project/sglang · error · ValueError
Crusoe API key required. Pass api_key= or set CRUSOE_API_KEY
Error message
Crusoe API key required. Pass api_key= or set CRUSOE_API_KEY.
What it means
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.
Source
Thrown at python/sglang/lang/backend/crusoe.py:33
Args:
model_name: The model to use, e.g. "meta-llama/Llama-3.1-8B-Instruct".
api_key: Crusoe API key. Defaults to CRUSOE_API_KEY env var.
base_url: Override the Crusoe endpoint. Defaults to the Crusoe API.
chat_template: Optional custom chat template.
"""
def __init__(
self,
model_name: str,
api_key: Optional[str] = None,
base_url: Optional[str] = None,
chat_template: Optional[ChatTemplate] = None,
**kwargs,
):
resolved_api_key = api_key or os.environ.get("CRUSOE_API_KEY")
if not resolved_api_key:
raise ValueError(
"Crusoe API key required. Pass api_key= or set CRUSOE_API_KEY."
)
super().__init__(
model_name=model_name,
chat_template=chat_template,
api_key=resolved_api_key,
base_url=base_url or CRUSOE_BASE_URL,
**kwargs,
)
View on GitHub (pinned to 0132848349)
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.
Example fix
# before backend = sgl.CrusoeAI(model_name="crusoe-model") # after backend = sgl.CrusoeAI(model_name="crusoe-m", api_key=os.environ["CRUSOE_API_KEY"]) # or: export CRUSOE_API_KEY=sk-... then construct as before
Defensive patterns
Strategy: validation
Validate before calling
import os
if not (os.environ.get("CRUSOE_API_KEY") or api_key):
raise SystemExit("Set CRUSOE_API_KEY or pass api_key=")
backend = sgl.CrusoeAI(model_name=..., api_key=api_key) Try / catch
try:
backend = sgl.CrusoeAI(model_name=m)
except ValueError as e:
if "CRUSOE_API_KEY" in str(e):
api_key = getpass("Crusoe API key: ")
backend = sgl.CrusoeAI(model_name=m, api_key=api_key)
else:
raise Prevention
- Load .env at app start (python-dotenv) before constructing backends.
- Fail fast on missing secrets in a startup preflight check.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- This use case is not supported if api speculative execution
- Unknown dtype: {sampling_params.dtype}
- This use case is not supported. For OpenAI chat models, sgl.
- select/choices is not supported for chat models. Please try
- Invalid dtype: {sampling_params.dtype}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/4c92d3be08d4d3d5.
Report an issue: GitHub.