How to fix error `operation aborted by callback` with OpenAI PHP SDK

iamkirillart

Kirill

Posted on December 15, 2023

How to fix error `operation aborted by callback` with OpenAI PHP SDK

During uploading a file to OpenAI API you can receive an error:

Fatal error: Uncaught Exception: operation aborted by callback in /var/www/html/vendor/orhanerday/open-ai/src/OpenAi.php on line 962
Enter fullscreen mode Exit fullscreen mode

Here is my code which produces this error:

require 'vendor/autoload.php';
use Orhanerday\OpenAi\OpenAi;
$openAi = new OpenAi($_SERVER['OPEN_AI_KEY']);
$pricesFile = curl_file_create(__DIR__ . '/../data/file.json');
$file = $openAi->uploadFile([
    'file' => $pricesFile,
    'purpose' => 'assistants',
]);
Enter fullscreen mode Exit fullscreen mode

Solution

The problem is that I didn't have the file on the provided path: __DIR__ . '/../data/file.json. You need to check and fix the path and then run your script again.

Follow me on X (prev Twitter)

💖 💪 🙅 🚩
iamkirillart
Kirill

Posted on December 15, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related