#!/usr/bin/env python3 """ Quick test script to verify OpenAI API key works """ import os from dotenv import load_dotenv # Load environment variables load_dotenv() def test_openai_key(): try: # Get API key api_key = os.getenv("OPENAI_API_KEY") if not api_key: print("āŒ No OPENAI_API_KEY found in environment variables") return False print(f"āœ… Found API key: {api_key[:20]}...") # Test with OpenAI v1.0+ syntax from openai import OpenAI client = OpenAI(api_key=api_key) print("šŸ”„ Testing API connection...") # Simple test call response = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ {"role": "user", "content": "Say 'Hello, API is working!'"} ], max_tokens=20 ) print("āœ… OpenAI API test successful!") print(f"Response: {response.choices[0].message.content}") return True except Exception as e: print(f"āŒ OpenAI API test failed: {e}") return False if __name__ == "__main__": print("Testing OpenAI API key...") success = test_openai_key() if success: print("\nšŸŽ‰ Your OpenAI API key is working correctly!") else: print("\nšŸ’” Please check your API key and try again.")