#!/usr/bin/env python3
"""Test different ElevenLabs API endpoints to find what's available."""
import os
import sys
import asyncio
import json
import httpx
# Add the src directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
async def test_api_endpoints():
"""Test various ElevenLabs API endpoints."""
print("๐ Testing ElevenLabs API Endpoints")
print("=" * 50)
# Get API key from environment
api_key = os.environ.get('ELEVENLABS_API_KEY')
if not api_key:
print("โ ELEVENLABS_API_KEY not found in environment")
return False
print(f"โ
API Key: {api_key[:8]}...{api_key[-4:]}")
# Test different base URLs and endpoints
test_cases = [
{
"name": "User Info",
"base_url": "https://api.elevenlabs.io/v1",
"endpoint": "/user",
"description": "Get user information"
},
{
"name": "Voices",
"base_url": "https://api.elevenlabs.io/v1",
"endpoint": "/voices",
"description": "List available voices"
},
{
"name": "Conversational AI Agents",
"base_url": "https://api.elevenlabs.io/v1",
"endpoint": "/convai/agents",
"description": "List conversational AI agents"
},
{
"name": "Conversational AI Tools",
"base_url": "https://api.elevenlabs.io/v1",
"endpoint": "/convai/tools",
"description": "List conversational AI tools"
},
{
"name": "Knowledge Base",
"base_url": "https://api.elevenlabs.io/v1",
"endpoint": "/convai/knowledge-base",
"description": "List knowledge base documents"
},
{
"name": "Models",
"base_url": "https://api.elevenlabs.io/v1",
"endpoint": "/models",
"description": "List available models"
}
]
headers = {
"xi-api-key": api_key,
"Content-Type": "application/json"
}
results = []
async with httpx.AsyncClient() as client:
for test_case in test_cases:
print(f"\n๐งช Testing: {test_case['name']}")
print(f" URL: {test_case['base_url']}{test_case['endpoint']}")
print(f" Description: {test_case['description']}")
try:
response = await client.get(
f"{test_case['base_url']}{test_case['endpoint']}",
headers=headers,
timeout=10
)
if response.status_code == 200:
print(" โ
SUCCESS")
try:
data = response.json()
if isinstance(data, dict):
if "agents" in data:
print(f" ๐ Found {len(data['agents'])} agents")
elif "voices" in data:
print(f" ๐ Found {len(data['voices'])} voices")
elif "tools" in data:
print(f" ๐ Found {len(data['tools'])} tools")
elif "documents" in data:
print(f" ๐ Found {len(data['documents'])} documents")
elif "models" in data:
print(f" ๐ Found {len(data['models'])} models")
else:
print(f" ๐ Response keys: {list(data.keys())}")
else:
print(f" ๐ Response type: {type(data)}")
results.append({
"name": test_case['name'],
"endpoint": test_case['endpoint'],
"status": "success",
"data": data
})
except Exception as e:
print(f" โ ๏ธ JSON parse error: {e}")
print(f" ๐ Raw response: {response.text[:200]}...")
elif response.status_code == 401:
print(" โ UNAUTHORIZED - Check API key")
results.append({
"name": test_case['name'],
"endpoint": test_case['endpoint'],
"status": "unauthorized",
"error": "Invalid API key"
})
elif response.status_code == 404:
print(" โ NOT FOUND - Endpoint may not exist")
results.append({
"name": test_case['name'],
"endpoint": test_case['endpoint'],
"status": "not_found",
"error": "Endpoint not found"
})
elif response.status_code == 403:
print(" โ FORBIDDEN - No access to this endpoint")
results.append({
"name": test_case['name'],
"endpoint": test_case['endpoint'],
"status": "forbidden",
"error": "No access to endpoint"
})
else:
print(f" โ HTTP {response.status_code}: {response.text[:100]}...")
results.append({
"name": test_case['name'],
"endpoint": test_case['endpoint'],
"status": "error",
"error": f"HTTP {response.status_code}"
})
except Exception as e:
print(f" โ REQUEST ERROR: {e}")
results.append({
"name": test_case['name'],
"endpoint": test_case['endpoint'],
"status": "error",
"error": str(e)
})
# Summary
print("\n" + "=" * 50)
print("๐ SUMMARY")
print("=" * 50)
successful = [r for r in results if r['status'] == 'success']
unauthorized = [r for r in results if r['status'] == 'unauthorized']
not_found = [r for r in results if r['status'] == 'not_found']
forbidden = [r for r in results if r['status'] == 'forbidden']
errors = [r for r in results if r['status'] == 'error']
print(f"โ
Successful: {len(successful)}")
print(f"โ Unauthorized: {len(unauthorized)}")
print(f"โ Not Found: {len(not_found)}")
print(f"โ Forbidden: {len(forbidden)}")
print(f"โ Errors: {len(errors)}")
if successful:
print(f"\n๐ Working endpoints:")
for result in successful:
print(f" โ
{result['name']}: {result['endpoint']}")
if not_found:
print(f"\nโ ๏ธ Not found endpoints (may not exist or require different path):")
for result in not_found:
print(f" โ {result['name']}: {result['endpoint']}")
if unauthorized:
print(f"\n๐ Unauthorized endpoints (check API key):")
for result in unauthorized:
print(f" โ {result['name']}: {result['endpoint']}")
if forbidden:
print(f"\n๐ซ Forbidden endpoints (no access):")
for result in forbidden:
print(f" โ {result['name']}: {result['endpoint']}")
# Show data from successful calls
for result in successful:
if result['name'] == 'Conversational AI Agents' and 'data' in result:
print(f"\n๐ค Your ElevenLabs Agents:")
data = result['data']
if 'agents' in data and data['agents']:
for i, agent in enumerate(data['agents'], 1):
print(f" Agent {i}:")
print(f" ID: {agent.get('agent_id', 'N/A')}")
print(f" Name: {agent.get('name', 'N/A')}")
print(f" Created: {agent.get('metadata', {}).get('created_at', 'N/A')}")
else:
print(" ๐ No agents found")
return len(successful) > 0
async def main():
"""Main test function."""
print("๐งช ElevenLabs API Endpoint Discovery")
print("=" * 60)
# Check environment
api_key = os.environ.get('ELEVENLABS_API_KEY')
if not api_key:
print("โ ELEVENLABS_API_KEY not set")
print("\n๐ก To set it:")
print(" export ELEVENLABS_API_KEY='your_api_key_here'")
return
success = await test_api_endpoints()
if success:
print("\nโ
Some endpoints are working!")
print("๐ง Update the MCP server to use the working endpoints")
else:
print("\nโ No endpoints are working")
print("๐ง Check your API key and ElevenLabs account permissions")
if __name__ == "__main__":
asyncio.run(main())