Installation
- Create an account on OpenAI
- Create your API key from the dashboard from API Keys
- Add your API key to your
.envfile asOPENAI_KEY=your-api-key
Usage
To use OpenAI API completion, you can use the instance ofOpenAIService.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
OpenAI API integration for Laravel
.env file as OPENAI_KEY=your-api-keyOpenAIService.
use App\Services\OpenAIService;
$openai = app(OpenAIService::class);
$response = $openai->completion('Write recipe based on the given ingredients: 1 cup of flour, 2 eggs, 1 cup of sugar');
// You can also pass the model name
$response = $openai->completion('Write recipe based on the given ingredients: 1 cup of flour, 2 eggs, 1 cup of sugar', 'davinci');
// See the list of pre-defined model names in config/services.php -> openai.models
// To get the response
echo $response['choices'][0]['message']['content'];
use App\Services\OpenAIService;
$openai = app(OpenAIService::class);
$response = $openai->image('A beautiful sunset over the mountains');
use App\Services\OpenAIService;
$openai = app(OpenAIService::class);
$response = $openai->textToSpeech('Hello, how are you?');
