To set up custom headers in the DeepSeek API, follow these steps:
1. Obtain Your API Key: First, ensure you have your API key from the DeepSeek Developer Portal. This key is essential for authentication when making API requests.
2. Set Up Your Development Environment: Make sure you have the necessary libraries installed, such as `requests` for Python or relevant libraries for other programming languages.
3. Define Custom Headers: When making a request to the DeepSeek API, you can include custom headers in your request. Below is an example of how to do this in Python:
python
import requests
API_KEY = "your_api_key"
BASE_URL = "https://api.deepseek.com/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
"Custom-Header": "YourCustomValue" # Example of a custom header
}
data = {
"model": "deepseek-reasoner",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum entanglement."}
],
"stream": False
}
response = requests.post(BASE_URL, json=data, headers=headers)
print(response.json())
4. Using Custom Headers in Other Languages: If you're using JavaScript with the DeepSeek SDK, you can set custom headers when creating a provider instance:
javascript
import { createDeepSeek } from '@ai-sdk/deepseek';
const deepseek = createDeepSeek({
apiKey: process.env.DEEPSEEK_API_KEY ?? '',
headers: {
'Custom-Header': 'YourCustomValue' // Example of a custom header
}
});
5. Testing Your Setup: After implementing your code with the custom headers, test the setup by sending requests to ensure that the headers are correctly included and that you receive the expected responses from the API.
By following these steps, you can effectively set up and use custom headers in your requests to the DeepSeek API, allowing for enhanced customization and functionality.
Citations:
[1] https://apidog.com/blog/deepseek-r1-review-api/
[2] https://qdrant.tech/documentation/rag-deepseek/
[3] https://www.listendata.com/2025/01/how-to-use-deepseek-in-r.html
[4] https://stackoverflow.com/questions/79338442/a-call-to-deepseek-api-in-r-returns-401-error-despite-correct-api-key
[5] https://sdk.vercel.ai/providers/ai-sdk-providers/deepseek
[6] https://www.essamamdani.me/deepseek-api-a-comprehensive-guide-to-models-and-pricing
[7] https://docs.typingmind.com/chat-models-settings/use-with-deepseek-ai
[8] https://www.datacamp.com/tutorial/deepseek-v3