File size: 1,438 Bytes
76c6f71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
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()