File size: 1,988 Bytes
2c1905d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
#!/usr/bin/env python3
"""Test script to verify ElevenLabs API key."""

import os
import httpx

# Read API key from environment
api_key = os.getenv("ELEVENLABS_API_KEY")
voice_id = os.getenv("ELEVENLABS_VOICE_ID", "21m00Tcm4TlvDq8ikWAM")

print("=" * 60)
print("ElevenLabs API Key Test")
print("=" * 60)

if not api_key:
    print("❌ ELEVENLABS_API_KEY is not set!")
    print("\nSet it with:")
    print("  export ELEVENLABS_API_KEY='your-key-here'")
    exit(1)

print(f"βœ“ API Key found: {api_key[:10]}...{api_key[-4:]}")
print(f"βœ“ Voice ID: {voice_id}")
print()

# Test API key by calling the voices endpoint (free endpoint)
print("Testing API key with /voices endpoint...")
try:
    response = httpx.get(
        "https://api.elevenlabs.io/v1/voices",
        headers={"xi-api-key": api_key},
        timeout=10.0
    )

    if response.status_code == 200:
        print("βœ… API key is VALID!")
        data = response.json()
        voices = data.get("voices", [])
        print(f"\nYou have access to {len(voices)} voices:")
        for voice in voices[:5]:  # Show first 5
            print(f"  - {voice['name']}: {voice['voice_id']}")
        if len(voices) > 5:
            print(f"  ... and {len(voices) - 5} more")
    elif response.status_code == 401:
        print("❌ API key is INVALID (401 Unauthorized)")
        print("\nPossible reasons:")
        print("  1. The API key is incorrect or has a typo")
        print("  2. The API key has been revoked or expired")
        print("  3. You're using the wrong ElevenLabs account")
        print("\nTo fix:")
        print("  1. Go to https://elevenlabs.io/app/settings/api-keys")
        print("  2. Generate a new API key")
        print("  3. Update ELEVENLABS_API_KEY in your .env or Space secrets")
    else:
        print(f"⚠️  Unexpected status code: {response.status_code}")
        print(f"Response: {response.text[:200]}")

except Exception as e:
    print(f"❌ Request failed: {e}")

print("=" * 60)