<?php

$apiKey = trim((string)(getenv('OPENAI_API_KEY') ?: ''));
if ($apiKey === '') {
    http_response_code(500);
    echo "OPENAI_API_KEY tanimli degil.";
    exit;
}

$data = [
    "model" => "gpt-4o-mini",
    "input" => "merhaba"
];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/responses");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "Authorization: Bearer " . $apiKey
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

$response = curl_exec($ch);
curl_close($ch);

$result = json_decode((string)$response, true);

echo $result["output"][0]["content"][0]["text"] ?? "Yanit alinamadi.";

?>




