Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Setting Up the DeepSeek API


Setting Up the DeepSeek API


To set up the DeepSeek API, follow these detailed steps to obtain your API key and configure your environment for making API calls.

Step 1: Create an Account and Obtain an API Key

1. Log in to the DeepSeek Open Platform: Visit the DeepSeek homepage and log in to your account. If you do not have an account, you will need to create one.

2. Access the API Keys Section:
- On the left sidebar, locate and click on the "API Keys" section.
- Click on the "Create new API Key" button.
- Optionally, assign a name to your key for easier identification later.

3. Copy Your API Key:
- After creating the key, copy it immediately and store it securely. You will not be able to view it again through the interface for security reasons[1][4].

Step 2: Set Up Your Development Environment

Using Apidog

1. Create a New Project:
- Log in to Apidog and create a new HTTP project.

2. Configure Environment Variables:
- Go to "Environment Management" in your project settings.
- Set the Service Base URL to `https://api.deepseek.com`.
- Add an environment variable named `API_KEY` with the value of your DeepSeek API key.

3. Create an Endpoint:
- Copy the cURL command for the desired API endpoint from the DeepSeek documentation.
- In Apidog, paste this command into your endpoint path.
- Modify the `Authorization` header to include your API key as follows: `Bearer `.

4. Send Requests:
- Switch to the production environment in Apidog.
- Click the "Send" button to execute your request. You can modify parameters in your request body as needed[1][2].

Using Python

1. Install Required Packages:
Ensure you have Python 3.x installed. It is advisable to set up a virtual environment:

bash
   python -m venv deepseek_env
   source deepseek_env/bin/activate  # On macOS/Linux
   deepseek_env\Scripts\activate     # On Windows
   

2. Install the DeepSeek API:
Use pip to install the Chat DeepSeek R1 API:

bash
   pip install chat-deepseek-api
   

3. Configure Environment Variables:
Create a `.env` file in your project directory with your credentials:


   DEEPSEEK_EMAIL=
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy18671 = 'y&#111;&#117;r_&#101;m&#97;&#105;l' + '&#64;';
 addy18671 = addy18671 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy18671 + suffix + '\'' + attribs + '>' );
 document.write( addy18671 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>
   DEEPSEEK_PASSWORD=your_password
   DEEPSEEK_DEVICE_ID=your_device_id
   DEEPSEEK_COOKIES=your_cookies
   DEEPSEEK_DS_POW_RESPONSE=your_ds_pow_response
   

4. Initialize and Use the API:
In your Python script, load environment variables and initialize the API:

python
   import os
   from dotenv import load_dotenv
   from deepseek_api import DeepseekAPI

   load_dotenv()  # Load environment variables from .env file

   api = DeepseekAPI.create()  # Initialize API with credentials
   session_id = api.new_chat()  # Start a new chat session
   response = api.chat(session_id, "Hello!")  # Send a message
   print(response)  # Handle response
   

By following these steps, you will successfully set up and configure the DeepSeek API for use in your applications, whether through Apidog or directly in Python. This setup allows you to begin making requests and integrating advanced search capabilities into your projects[2][3].

Citations:
[1] https://dev.to/auden/how-to-use-deepseek-api-and-enable-streaming-output-for-debugging-1ah9
[2] https://thinhdanggroup.github.io/blog-on-chat-deepseek-r1-api/
[3] https://www.youtube.com/watch?v=qbUELF9Et4s
[4] https://docs.aicontentlabs.com/articles/deepseek-api-key/
[5] https://dev.to/pavanbelagatti/run-deepseek-r1-locally-for-free-in-just-3-minutes-1e82
[6] https://api-docs.deepseek.com/api/deepseek-api
[7] https://www.youtube.com/watch?v=_IKz7sDQeVg
[8] https://www.datacamp.com/tutorial/deepseek-v3