๐Ÿงช Direct GPT Test

โš ๏ธ Critical Test: This will definitively show if your OpenAI API is working. If successful, you WILL see usage in your OpenAI dashboard within 1-2 hours.

๐Ÿ”‘ API Key Check

โœ… API Key Found: $keyPreview (Length: $keyLength chars)
"; if (!str_starts_with(OPENAI_API_KEY, 'sk-')) { echo "
โŒ Invalid API key format - should start with 'sk-'
"; } } else { echo "
โŒ No OpenAI API key found
"; } ?>

๐Ÿค– Direct API Test

๐Ÿ”ง GptHelper Test

'gpt-4', 'messages' => [ [ 'role' => 'user', 'content' => 'Respond with exactly: "Direct API test successful at ' . date('H:i:s') . '"' ] ], 'max_tokens' => 50, 'temperature' => 0.1 ]; $ch = curl_init('https://api.openai.com/v1/chat/completions'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($data), CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . OPENAI_API_KEY, 'Content-Type: application/json' ], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => false ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); curl_close($ch); if ($curlError) { throw new Exception("cURL Error: $curlError"); } if ($httpCode !== 200) { throw new Exception("HTTP Error $httpCode: $response"); } $result = json_decode($response, true); if (!$result || !isset($result['choices'][0]['message']['content'])) { throw new Exception("Invalid API response: $response"); } ob_clean(); echo json_encode([ 'success' => true, 'response' => $result['choices'][0]['message']['content'], 'usage' => $result['usage'] ?? ['prompt_tokens' => 0, 'completion_tokens' => 0, 'total_tokens' => 0], 'http_code' => $httpCode ]); } elseif ($_GET['action'] === 'gpt_helper') { // Test using GptHelper class if (!class_exists('GptHelper')) { require_once 'includes/GptHelper.php'; } if (!class_exists('GptHelper')) { throw new Exception('GptHelper class not found'); } $messages = [ [ 'role' => 'user', 'content' => 'Respond with exactly: "GptHelper test successful at ' . date('H:i:s') . '"' ] ]; $response = GptHelper::makeRequest($messages, 'gpt-4', 0.1); if (!$response['success']) { throw new Exception($response['error']); } ob_clean(); echo json_encode([ 'success' => true, 'response' => $response['response'], 'usage' => $response['usage'] ?? 'Not provided' ]); } } catch (Exception $e) { ob_clean(); echo json_encode([ 'success' => false, 'error' => $e->getMessage(), 'http_code' => $httpCode ?? null ]); } exit; } ?>