BerriAI/litellm · error · ValueError
Missing API key for DashScope. Set DASHSCOPE_API_KEY environ
Error message
Missing API key for DashScope. Set DASHSCOPE_API_KEY environment variable or pass api_key parameter.
What it means
DashScope (Alibaba) embeddings require an API key. litellm checks the api_key kwarg, litellm.api_key, then the DASHSCOPE_API_KEY environment variable; when all are unset it raises this ValueError before any request.
Source
Thrown at litellm/main.py:6893
response = base_llm_http_handler.embedding(
model=model,
input=input,
timeout=timeout,
custom_llm_provider=custom_llm_provider,
logging_obj=logging,
api_base=api_base,
optional_params=optional_params,
litellm_params={},
model_response=EmbeddingResponse(),
api_key=volcengine_key,
client=client,
aembedding=aembedding,
headers=headers,
)
elif custom_llm_provider == "dashscope":
dashscope_key: Final = api_key or litellm.api_key or get_secret_str("DASHSCOPE_API_KEY")
if dashscope_key is None:
raise ValueError(
"Missing API key for DashScope. Set DASHSCOPE_API_KEY environment variable or pass api_key parameter."
)
if extra_headers is not None and isinstance(extra_headers, dict):
headers = extra_headers
else:
headers = {}
response = base_llm_http_handler.embedding(
model=model,
input=input,
timeout=timeout,
custom_llm_provider=custom_llm_provider,
logging_obj=logging,
api_base=api_base,
optional_params=optional_params,
litellm_params={},
model_response=EmbeddingResponse(),
api_key=dashscope_key,
client=client,View on GitHub (pinned to 77b7c6c40c)
Solutions
- export DASHSCOPE_API_KEY=<key> and restart the process
- Or pass api_key=<key> to the embedding call
- Or set litellm.api_key at startup
- Confirm with python -c "import os; print(bool(os.environ.get('DASHSCOPE_API_KEY')))"
Example fix
# before resp = litellm.embedding(model="dashscope/text-embedding-v3", input=["hi"]) # after os.environ["DASHSCOPE_API_KEY"] = "sk-..." resp = litellm.embedding(model="dashscope/text-embedding-v3", input=["hi"])
Defensive patterns
Strategy: validation
Validate before calling
import os
if not (os.environ.get("DASHSCOPE_API_KEY") or litellm.api_key):
raise SystemExit("DASHSCOPE_API_KEY not set") Try / catch
try:
resp = litellm.embedding(model="dashscope/text-embedding-v3", input=["hi"])
except ValueError as e:
if "DashScope" in str(e):
raise RuntimeError("DashScope credentials missing") from e Prevention
- Use a startup credential check covering every provider your app calls
- Prefer per-call api_key over ambient globals so failures are localized
When it happens
Trigger: litellm.embedding(model='dashscope/<model>', input=[...]) with no api_key kwarg, no litellm.api_key, and DASHSCOPE_API_KEY absent from the environment.
Common situations: First-time DashScope integration; key exported in a shell but not in the service's unit file or container spec; .env loaded after litellm reads config.
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
- api_key is required for Volcengine authentication
- Voyage API key is required for multimodal embeddings. Set VO
- Missing API key for Volcengine. Set ARK_API_KEY or VOLCENGIN
- API key is required for OpenAI image variations
- API key is required for Topaz image variations
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/4bd441c92613d816.
Report an issue: GitHub.