File size: 1,674 Bytes
93fe96e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
"""
Test DeepSeek API key
"""

import os
import requests
import json

def test_deepseek():
    """Test DeepSeek API key"""
    try:
        # Get API key
        api_key = os.environ.get("DEEPSEEK_API_KEY")
        if not api_key:
            print("❌ DEEPSEEK_API_KEY not found in environment variables")
            return False
        
        print(f"βœ… API key found: {api_key[:20]}...")
        
        # Test API call
        url = "https://api.deepseek.com/v1/chat/completions"
        headers = {
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json"
        }
        
        data = {
            "model": "deepseek-chat",
            "messages": [{"role": "user", "content": "Say hello!"}],
            "max_tokens": 100,
            "temperature": 0.7
        }
        
        print("πŸ” Testing DeepSeek API...")
        response = requests.post(url, headers=headers, json=data)
        
        if response.status_code == 401:
            print("❌ API key is invalid or expired")
            print("Please get a new API key from https://platform.deepseek.com/")
            return False
        elif response.status_code == 200:
            result = response.json()
            message = result["choices"][0]["message"]["content"]
            print(f"βœ… API test successful: {message}")
            return True
        else:
            print(f"❌ API error: {response.status_code} - {response.text}")
            return False
            
    except Exception as e:
        print(f"❌ Error testing API: {e}")
        return False

if __name__ == "__main__":
    test_deepseek()