Spaces:
Sleeping
Sleeping
| """ | |
| Debug API connection and model access | |
| """ | |
| import os | |
| import sys | |
| from pathlib import Path | |
| # Add src to path | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| api_key = os.getenv("ANTHROPIC_API_KEY") | |
| print("\n" + "=" * 70) | |
| print("API Key Debug") | |
| print("=" * 70) | |
| print(f"API Key found: {bool(api_key)}") | |
| if api_key: | |
| print(f"API Key starts with: {api_key[:15]}...") | |
| print(f"API Key length: {len(api_key)}") | |
| print() | |
| # Try direct API call | |
| print("Testing direct API call...") | |
| try: | |
| from anthropic import Anthropic | |
| client = Anthropic(api_key=api_key) | |
| # Try with the simplest model name format | |
| model_names_to_try = [ | |
| "claude-3-opus-20240229", | |
| "claude-3-sonnet-20240229", | |
| "claude-3-haiku-20240307", | |
| "claude-2.1", | |
| "claude-2.0", | |
| ] | |
| for model in model_names_to_try: | |
| try: | |
| print(f"\nTrying model: {model}") | |
| message = client.messages.create( | |
| model=model, | |
| max_tokens=10, | |
| messages=[{"role": "user", "content": "Hi"}] | |
| ) | |
| print(f" ✓ SUCCESS with {model}!") | |
| print(f" Response: {message.content[0].text}") | |
| break | |
| except Exception as e: | |
| print(f" ✗ Failed: {str(e)[:100]}") | |
| except Exception as e: | |
| print(f"\n✗ Error: {e}\n") | |
| import traceback | |
| traceback.print_exc() | |