Skip to main content
Larafast provides a simple way to integrate OpenAI API with Laravel.

Installation

  1. Create an account on OpenAI
  2. Create your API key from the dashboard from API Keys
  3. Add your API key to your .env file as OPENAI_KEY=your-api-key
That’s it, your project is ready to use OpenAI API.

Usage

To use OpenAI API completion, you can use the instance of OpenAIService.
To create images using OpenAI API, you can use:
You can adjust the number of generating images and the size in the OpenAIService@image method. To create an audio from text using OpenAI API, you can use:
The text-to-speech will return the audio content instead of the URL as for the image. You can save the audio content to a file or return it as a response.
For more information, you can check the OpenAI API documentation to add new features to your service or adjust existing ones.