- Changed docker-compose.yml to mount OrbStack Docker socket path (/Users/brunogao/.orbstack/run/docker.sock) - Updated GITEA_INSTANCE_URL to use 192.168.1.83:33000 instead of gitea:3000 for proper DNS resolution - Both runner-docker and runner-k8s now correctly point to OrbStack Docker daemon - This resolves the 'Cannot connect to the Docker daemon' error and DNS resolution failures
126 lines
4.2 KiB
Python
126 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Debug script to test OpenRouter API call."""
|
|
import requests
|
|
import os
|
|
import yaml
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
# Add src to path for imports
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
|
|
|
from src.utils.config import load_config, get_provider_config
|
|
from src.providers.base import OpenRouterProvider
|
|
|
|
|
|
def test_api_call():
|
|
"""Test the OpenRouter API directly."""
|
|
print("🔍 Testing OpenRouter API call...")
|
|
|
|
# Load config
|
|
config = load_config()
|
|
if not config:
|
|
print("❌ Configuration not found")
|
|
return
|
|
|
|
provider_config = get_provider_config('openrouter')
|
|
if not provider_config:
|
|
print("❌ OpenRouter provider config not found")
|
|
return
|
|
|
|
# Check API key
|
|
api_key = provider_config.get('api_key', 'sk-or-xxx')
|
|
if api_key == 'sk-or-xxx' or not api_key:
|
|
print("❌ No valid API key found in config")
|
|
print(" Please update your config.yaml file or set OPENROUTER_API_KEY environment variable")
|
|
return
|
|
|
|
print(f"✅ API key found (first 8 chars: {api_key[:8]}...)")
|
|
|
|
# Check model - environment variable takes precedence over config file
|
|
env_model = os.environ.get('OPENROUTER_MODEL')
|
|
model = env_model if env_model else config.get('default_model', 'anthropic/claude-4.5-sonnet')
|
|
print(f"✅ Using model: {model} (from {'env' if env_model else 'config'})")
|
|
|
|
# Test the API call directly
|
|
headers = {
|
|
'Authorization': f'Bearer {api_key}',
|
|
'Content-Type': 'application/json',
|
|
'HTTP-Referer': 'https://github.com/your-username/ai-cli',
|
|
'X-Title': 'AI CLI Tool'
|
|
}
|
|
|
|
# Simple test message
|
|
messages = [
|
|
{"role": "user", "content": "Hello, test message!"}
|
|
]
|
|
|
|
payload = {
|
|
'model': model,
|
|
'messages': messages,
|
|
}
|
|
|
|
print(f"📡 Sending request to: {provider_config['base_url']}")
|
|
print(f"📦 Payload: {payload}")
|
|
|
|
try:
|
|
response = requests.post(provider_config['base_url'], headers=headers, json=payload)
|
|
print(f"📥 Response Status: {response.status_code}")
|
|
print(f"📥 Response Headers: {dict(response.headers)}")
|
|
print(f"📥 Response Text: {response.text[:500]}...") # First 500 chars
|
|
|
|
if response.status_code != 200:
|
|
print("❌ API call failed with error above")
|
|
else:
|
|
print("✅ API call successful!")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Exception during API call: {str(e)}")
|
|
|
|
|
|
def check_model_availability():
|
|
"""Check if the model exists on OpenRouter."""
|
|
print("\n🔍 Checking model availability...")
|
|
|
|
config = load_config()
|
|
model = config.get('default_model', 'anthropic/claude-4.5-sonnet')
|
|
|
|
provider_config = get_provider_config('openrouter')
|
|
api_key = provider_config.get('api_key', 'sk-or-xxx')
|
|
|
|
if api_key == 'sk-or-xxx' or not api_key:
|
|
print("❌ Cannot check model - no valid API key")
|
|
return
|
|
|
|
headers = {
|
|
'Authorization': f'Bearer {api_key}',
|
|
'Content-Type': 'application/json'
|
|
}
|
|
|
|
try:
|
|
# Check model endpoint
|
|
response = requests.get('https://openrouter.ai/api/v1/models', headers=headers)
|
|
if response.status_code == 200:
|
|
models_data = response.json()
|
|
available_models = [m['id'] for m in models_data.get('data', [])]
|
|
|
|
print(f"📊 Found {len(available_models)} available models")
|
|
|
|
# Check if our model is available
|
|
if model in available_models:
|
|
print(f"✅ Model {model} is available")
|
|
else:
|
|
print(f"❌ Model {model} is NOT available")
|
|
print(" Available Claude models might include:")
|
|
claude_models = [m for m in available_models if 'claude' in m.lower()]
|
|
for m in claude_models[:5]: # Show first 5
|
|
print(f" - {m}")
|
|
else:
|
|
print(f"❌ Could not fetch models list: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"❌ Error checking model availability: {str(e)}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
test_api_call()
|
|
check_model_availability() |