Settings to provide the same.', 'aiscribe')); } $headers = array( 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $open_ai_key ); $options = array( 'headers' => $headers, 'method' => 'POST', 'timeout' => 200, 'redirection' => 5, 'body' => json_encode($params), 'sslverify' => false ); $response = wp_remote_post($url, $options); if (is_wp_error($response)) { throw new \Exception($response->get_error_message()); } $response_decoded = json_decode(wp_remote_retrieve_body($response), true); if (isset($response_decoded['error'])) { $message = $response_decoded['error']['message']; // If the message contains "Incorrect API key provided: THE_KEY.", replace the key by "----". if (preg_match('/API key provided(: .*)\./', $message, $matches)) { $message = str_replace($matches[1], '', $message); } throw new \Exception($message); } return $response_decoded; } } endif; // End if class_exists check