API - Service unavailable on my website

My API stopped, I created another one but it is not working on my website, what happened, in my import log it was signaling a Service Unavailable error.

How do I resolve this? I already created another API but it didn’t work again.

And credit still has I haven’t used even 1/3 of the amount

Hi and welcome to the Developer Forum!

Can you please include an error log and also a code snippet of the API call and any support code it relies upon.

This is the code, other people use it normally, only mine stopped.
Thank you for your help

log:

<?php
// Hook de AJAX para receber os dados do formulário
add_action('wp_ajax_gerador_chat_gpt', 'gerador_chat_gpt_ajax');
add_action('wp_ajax_nopriv_gerador_chat_gpt', 'gerador_chat_gpt_ajax');

function gerador_chat_gpt_ajax() {
    // Verifica se a requisição é segura
    global $wpdb;
    $table_name = $wpdb->prefix . 'chat_gpt_glossarios';
    // Inicializa um array vazio
    $form_array = array();
    // Converte a string em um array usando parse_str()
    parse_str($data, $form_array);
    // Agora você pode usar o array $form_array para acessar os valores do formulário
    // Exemplo de acesso aos valores:
    $modelo = sanitize_text_field($_POST['modelo']);
    $idioma = sanitize_text_field($_POST['idioma']);
    $estilo = sanitize_text_field($_POST['estilo']);
    $tokens = sanitize_text_field($_POST['tokens']);
    $prompt_chat = sanitize_text_field($_POST['prompt_chat_gpt']);
    $error_log = "";
    if ($prompt_chat == "") {
        $prompt_chat = "";
    }
    // Verifica se os campos obrigatórios estão preenchidos
    if (empty($modelo) || empty($idioma) || empty($estilo) || empty($tokens)) {
        // Retorna uma resposta de erro informando que os campos devem ser preenchidos
        wp_send_json_success(array('message' => '<div class="msg_erro">Todos os campos são Obrigatórios</div>'));
        return;
    }

    if (isset($_FILES['csv_file'])) {
        $file = $_FILES['csv_file']['tmp_name'];

        $data = array();

        if (($handle = fopen($file, 'r')) !== false) {
            // Ignorar a primeira linha (cabeçalho)
            fgets($handle);

            while (($row = fgetcsv($handle)) !== false) {
                $titulo = $row[0];
                $letra = $row[1];

                // Adicionar os dados ao array
                $data[] = array(
                    'titulo_glossario' => $titulo,
                    'cat_glossario' => $letra,
                    'modelo_chat_gpt' => $modelo,
                    'idioma' => $idioma,
                    'estilo' => $estilo,
                    'prompt_gpt' => $prompt_chat,
                    'error_log' => $error_log,
                    'quantidade_tokens' => $tokens,
                    'status' => 'pendente'
                );
            }

            fclose($handle);
        }

        // Remover títulos duplicados do array $data
        $titulos = array_column($data, 'titulo_glossario');
        $titulos_exclusivos = array_unique($titulos);
        $data_exclusiva = array();
        foreach ($data as $item) {
            if (in_array($item['titulo_glossario'], $titulos_exclusivos)) {
                $data_exclusiva[] = $item;
                // Remove o título da lista de exclusivos para evitar duplicações caso existam títulos repetidos
                $titulos_exclusivos = array_diff($titulos_exclusivos, array($item['titulo_glossario']));
            }
        }

        // Agora $data_exclusiva contém os elementos com títulos exclusivos e sem duplicatas
        foreach ($data_exclusiva as $key => $item) {
            $result = $wpdb->insert($table_name, $item);

            if ($result === false) {
                // Ocorreu um erro ao inserir os dados
                $error_message = $wpdb->last_error;
                wp_send_json_success(array('message' => '<div class="msg_erro">Houve um erro</div>'));

                // Faça algo com a mensagem de erro, se necessário
            }
        }
        // Se o loop terminar sem encontrar erros, envie a resposta de sucesso fora do loop
        wp_send_json_success(array('message' => '<div class="msg_sucesso">Glossário cadastrado com sucesso. Agora só aguardar.</div>'));
    }
    // Importante: Certifique-se de finalizar a execução após enviar a resposta
    wp_die();
}```

That snippet does not contain any calls to OpenAI services, I’m not sure what you are requesting here, is this to do with OpenAI or are you just asking for general help with your site and need ChatGPT?