import requests import json def test_deepseek_api_direct(): """Test DeepSeek API directly to isolate the issue""" api_key = "sk-338f965efd9e4ae79538ceb0b6b0f717" base_url = "https://api.deepseek.com/v1" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } # Test 1: Simple chat completion print("Testing DeepSeek API directly...") data = { "model": "deepseek-chat", "messages": [ {"role": "user", "content": "Hello, please respond with 'API test successful'"} ], "max_tokens": 50, "temperature": 0.7 } try: response = requests.post( f"{base_url}/chat/completions", headers=headers, json=data, timeout=30 ) print(f"Response status: {response.status_code}") print(f"Response headers: {dict(response.headers)}") if response.status_code == 200: result = response.json() print("✅ API test successful!") print(f"Response: {json.dumps(result, indent=2)}") return True else: print(f"❌ API test failed: {response.status_code}") print(f"Error response: {response.text}") # Try to get more detailed error info try: error_data = response.json() print(f"Error details: {json.dumps(error_data, indent=2)}") except: print("Could not parse error response as JSON") return False except requests.exceptions.RequestException as e: print(f"❌ Request failed: {e}") return False def test_deepseek_models(): """Test listing available models""" api_key = "sk-338f965efd9e4ae79538ceb0b6b0f717" base_url = "https://api.deepseek.com/v1" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } print("\nTesting models endpoint...") try: response = requests.get( f"{base_url}/models", headers=headers, timeout=30 ) print(f"Models response status: {response.status_code}") if response.status_code == 200: models = response.json() print("✅ Models endpoint successful!") print(f"Available models: {json.dumps(models, indent=2)}") return True else: print(f"❌ Models endpoint failed: {response.status_code}") print(f"Error: {response.text}") return False except requests.exceptions.RequestException as e: print(f"❌ Models request failed: {e}") return False if __name__ == "__main__": print("=== DeepSeek API Direct Test ===") # Test API key directly success1 = test_deepseek_api_direct() # Test models endpoint success2 = test_deepseek_models() if success1 and success2: print("\n🎉 All DeepSeek API tests passed!") else: print("\n💥 Some DeepSeek API tests failed!")