On Twitter Nuno said, “OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API, with this integration, developers can now easily use OpenAI’s powerful natural language processing capabilities in their Laravel applications.”
Getting started with the package is pretty straightforward and you can see the guide here:
First, install OpenAI:
1composer require openai-php/laravel
Next, publish the configuration file:
1php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"
This will create a
config/openai.php configuration file in your project, which you can modify to your needs
using environment variables:
Finally, you may use the
OpenAI facade to access the OpenAI API:
3$result = OpenAI::completions()->create([
4 'model' => 'text-davinci-003',
5 'prompt' => 'PHP is',
8echo $result['choices']['text']; // an open-source, widely-used, server-side scripting language.