{"record":{"id":"4bd441c92613d816","repo":"BerriAI/litellm","slug":"missing-api-key-for-dashscope-set-dashscope-api-k","errorCode":null,"errorMessage":"Missing API key for DashScope. Set DASHSCOPE_API_KEY environment variable or pass api_key parameter.","messagePattern":"Missing API key for DashScope\\. Set DASHSCOPE_API_KEY environment variable or pass api_key parameter\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/main.py","lineNumber":6893,"sourceCode":"            response = base_llm_http_handler.embedding(\n                model=model,\n                input=input,\n                timeout=timeout,\n                custom_llm_provider=custom_llm_provider,\n                logging_obj=logging,\n                api_base=api_base,\n                optional_params=optional_params,\n                litellm_params={},\n                model_response=EmbeddingResponse(),\n                api_key=volcengine_key,\n                client=client,\n                aembedding=aembedding,\n                headers=headers,\n            )\n        elif custom_llm_provider == \"dashscope\":\n            dashscope_key: Final = api_key or litellm.api_key or get_secret_str(\"DASHSCOPE_API_KEY\")\n            if dashscope_key is None:\n                raise ValueError(\n                    \"Missing API key for DashScope. Set DASHSCOPE_API_KEY environment variable or pass api_key parameter.\"\n                )\n            if extra_headers is not None and isinstance(extra_headers, dict):\n                headers = extra_headers\n            else:\n                headers = {}\n            response = base_llm_http_handler.embedding(\n                model=model,\n                input=input,\n                timeout=timeout,\n                custom_llm_provider=custom_llm_provider,\n                logging_obj=logging,\n                api_base=api_base,\n                optional_params=optional_params,\n                litellm_params={},\n                model_response=EmbeddingResponse(),\n                api_key=dashscope_key,\n                client=client,","sourceCodeStart":6875,"sourceCodeEnd":6911,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/main.py#L6875-L6911","documentation":"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.","triggerScenarios":"litellm.embedding(model='dashscope/<model>', input=[...]) with no api_key kwarg, no litellm.api_key, and DASHSCOPE_API_KEY absent from the environment.","commonSituations":"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.","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')))\""],"exampleFix":"# before\nresp = litellm.embedding(model=\"dashscope/text-embedding-v3\", input=[\"hi\"])\n\n# after\nos.environ[\"DASHSCOPE_API_KEY\"] = \"sk-...\"\nresp = litellm.embedding(model=\"dashscope/text-embedding-v3\", input=[\"hi\"])","handlingStrategy":"validation","validationCode":"import os\n\nif not (os.environ.get(\"DASHSCOPE_API_KEY\") or litellm.api_key):\n    raise SystemExit(\"DASHSCOPE_API_KEY not set\")","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.embedding(model=\"dashscope/text-embedding-v3\", input=[\"hi\"])\nexcept ValueError as e:\n    if \"DashScope\" in str(e):\n        raise RuntimeError(\"DashScope credentials missing\") from e","preventionTips":["Use a startup credential check covering every provider your app calls","Prefer per-call api_key over ambient globals so failures are localized"],"tags":["dashscope","embedding","api-key","litellm"],"backgroundTag":"missing-api-key","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}