resume-optimizer-api / test_key.py
JermaineAI's picture
Switched to Deepseek
2b34c31
raw
history blame contribute delete
984 Bytes
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)