File size: 984 Bytes
0c6fb97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b34c31
0c6fb97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from openai import OpenAI
from dotenv import load_dotenv

# 1. Load the .env file
load_dotenv()

api_key = os.getenv("OPENROUTER_API_KEY")

print(f"Testing API Key: {api_key[:5]}...{api_key[-4:] if api_key else 'None'}")

if not api_key:
    print("ERROR: No API Key found in .env file!")
    exit(1)

# 2. Setup Client
client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key=api_key,
)

print("\nSending request to OpenRouter...")

try:
    # 3. Simple Test Request
    completion = client.chat.completions.create(
        model = "deepseek/deepseek-chat-v3.1",
        messages=[
            {"role": "user", "content": "Say 'Hello World' if you can hear me."}
        ],
    )
    
    # 4. Success Output
    print("\nSUCCESS! Response received:")
    print("-" * 30)
    print(completion.choices[0].message.content)
    print("-" * 30)

except Exception as e:
    # 5. detailed Error Output
    print("\nFAILED. Here is the exact error:")
    print(e)