To set up environment variables for the DeepSeek API, follow these steps:
Step 1: Obtain Your API Key
1. Log in to the DeepSeek Open Platform.2. Navigate to the API Keys section in the sidebar.
3. Click on Create a new API key and copy it immediately. Store this key securely, as it will not be displayed again[5].
Step 2: Set Environment Variables
You can set your API key as an environment variable in different ways depending on your operating system.For Windows:
1. Open the Command Prompt.2. Use the following command to set the environment variable:
bash
setx DEEPSEEK_API_KEY "your_api_key_here"
3. Restart your Command Prompt or any applications that need access to this variable.
For macOS and Linux:
1. Open your terminal.2. Add the following line to your `.bashrc`, `.bash_profile`, or `.zshrc` file:
bash
export DEEPSEEK_API_KEY="your_api_key_here"
3. After editing the file, run:
bash
source ~/.bashrc # or ~/.bash_profile or ~/.zshrc depending on where you added it
Step 3: Verify Environment Variable
To ensure that the environment variable is set correctly, you can check its value:- Windows:
bash
echo %DEEPSEEK_API_KEY%
- macOS and Linux:
bash
echo $DEEPSEEK_API_KEY
Step 4: Use the API Key in Your Application
In your application code, you can retrieve the API key using the appropriate method for your programming language. For example, in Python, you would use:python
import os
api_key = os.getenv("DEEPSEEK_API_KEY")
This allows you to access your API key securely without hardcoding it into your application[6][7].
By following these steps, you will have successfully set up environment variables for the DeepSeek API, enabling secure access to your API key during development and deployment.
Citations:
[1] https://www.reddit.com/r/homeassistant/comments/1ibwney/easiest_way_to_use_deepseek_web_api/
[2] https://www.listendata.com/2025/01/how-to-use-deepseek-in-r.html
[3] https://thinhdanggroup.github.io/blog-on-chat-deepseek-r1-api/
[4] https://relevanceai.com/llm-models/explore-deepseek-v25-for-better-data-insights
[5] https://meetcody.ai/blog/deepseek-r1-api-pricing/
[6] https://dev.to/auden/how-to-use-deepseek-api-and-enable-streaming-output-for-debugging-1ah9
[7] https://python.useinstructor.com/integrations/deepseek/
[8] https://github.com/Doriandarko/deepseek-engineer/blob/main/main.py