<?php
require_once __DIR__ . '/includes/config.php';

echo "Key gesetzt: " . (empty(ANTHROPIC_API_KEY) ? 'NEIN ✗' : 'JA ✓') . "<br>";
echo "Key Länge: " . strlen(ANTHROPIC_API_KEY) . " Zeichen<br>";
echo "Key Anfang: " . substr(ANTHROPIC_API_KEY, 0, 15) . "...<br>";

// API Test
$ch = curl_init('https://api.anthropic.com/v1/messages');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode([
        'model' => 'claude-sonnet-4-20250514',
        'max_tokens' => 10,
        'messages' => [['role'=>'user','content'=>'Hi']]
    ]),
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'x-api-key: ' . ANTHROPIC_API_KEY,
        'anthropic-version: 2023-06-01',
    ],
]);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "API Status: $code<br>";
if ($code === 200) echo "✓ API funktioniert!";
else echo "✗ API Fehler: " . htmlspecialchars($response);