i need to know if this happen to me or is global problem becuse im just create new account and in frist test i got this issue
First single request
: You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.
$API_KEY = 'sk-proj-MdHgLxm5iGUL_........';
$url = 'https://api.openai.com/v1/completions';
$model = "gpt-3.5-turbo"; // Updated model
$chat = "";
// Read and decode input data
$data = json_decode(file_get_contents('php://input'), true);
if ($data) {
$character_name = $data["character_name"];
$continuous_chat = $data["continuous_chat"];
if (!$continuous_chat) {
$myLastElement = end($data["array_chat"]);
$chat = $myLastElement["message"];
} else {
foreach ($data["array_chat"] as $msg) {
$chat .= $msg["name"] . ': ' . $msg["message"] . "\n";
}
}
$header = array(
'Authorization: Bearer ' . $API_KEY,
'Content-type: application/json',
);
$params = json_encode(array(
'prompt' => $chat,
'model' => $model,
'temperature' => 1,
'max_tokens' => 1500,
'top_p' => 1,
'frequency_penalty' => 0,
'presence_penalty' => 0
));
// Initialize cURL
$curl = curl_init($url);
curl_setopt_array($curl, array(
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2
));
$retryCount = 0;
$maxRetries = 5;
$waitTime = 1; // Start with 1 second
while ($retryCount < $maxRetries) {
$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
if ($response === false) {
echo json_encode(array(
'status' => 0,
'message' => 'An error occurred: ' . curl_error($curl)
));
curl_close($curl);
die();
}
if ($httpcode == 429) {
// Rate limit exceeded
$retryCount++;
sleep($waitTime); // Wait before retrying
$waitTime *= 2; // Exponential backoff
} else {
curl_close($curl);
if ($httpcode == 401) {
$r = json_decode($response);
echo json_encode(array(
'status' => 0,
'message' => $r->error->message
));
die();
} elseif ($httpcode == 404) {
echo json_encode(array(
'status' => 0,
'message' => 'An error occurred: HTTP code 404 - Endpoint not found'
));
die();
}
if ($httpcode == 200) {
$json_array = json_decode($response, true);
$choices = $json_array['choices'] ?? [];
if (!empty($choices)) {
$responseText = trim(str_replace($character_name . ":", "", $choices[0]['text']));
echo json_encode(array(
'status' => 1,
'message' => $responseText
));
} else {
echo json_encode(array(
'status' => 0,
'message' => 'No choices returned from API.'
));
}
} else {
echo json_encode(array(
'status' => 0,
'message' => 'An error occurred: HTTP code ' . $httpcode
));
}
die();
}
}
// If max retries reached
echo json_encode(array(
'status' => 0,
'message' => 'Rate limit exceeded after multiple retries.'
));
}