File size: 1,281 Bytes
1c29d49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import requests

# Load the API key from environment
api_key = os.getenv("TRANSLATION_API_KEY", "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")
model = os.getenv("TRANSLATION_MODEL", "allenai/olmo-3.1-32b-think:free")

print(f"Testing API key: {api_key[:10]}...")  # Only show first 10 chars for security
print(f"Testing model: {model}")

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json",
}

payload = {
    "model": model,
    "messages": [
        {"role": "user", "content": "Hello, how are you?"}
    ]
}

try:
    response = requests.post(
        "https://openrouter.ai/api/v1/chat/completions",
        json=payload,
        headers=headers,
        timeout=30
    )
    
    print(f"Status Code: {response.status_code}")
    print(f"Response: {response.text}")
    
    if response.status_code == 200:
        print("\n✅ API key is working correctly!")
    else:
        print(f"\n❌ API returned error: {response.status_code}")
        print("This might indicate:")
        print("1. API key has reached daily limit")
        print("2. Model is not available")
        print("3. API key is invalid")
        
except Exception as e:
    print(f"\n❌ Error making API request: {str(e)}")