Open the new file, delete everything in it, and paste this in. Read the comments: handle() asks for a prompt, and runModel() sends it to OpenAI.
Replace file · app/Console/Commands/ChatCommand.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;
use function Laravel\Prompts\text;
// Lesson 1: one question, one answer.
class ChatCommand extends Command
{
protected $signature = 'chat';
protected $description = 'Receive an AI response';
public function handle(): void
{
$prompt = text('What is on your mind?', required: true);
$response = spin(
fn () => $this->runModel($prompt),
'Hmm... thinking about that.'
);
// Naive: assumes the first output item is the text message.
info($response['output'][0]['content'][0]['text']);
}
protected function runModel(string $prompt): array
{
return Http::withToken(config('services.openai.key'))
->post('https://api.openai.com/v1/responses', [
'model' => config('services.openai.model'),
'instructions' => 'You are a helpful assistant.',
'input' => [
['role' => 'user', 'content' => $prompt],
],
])
->throw()
->json();
}
}

The first raw HTTP request: model, instructions and input.

Made interactive with text() and tidied into runModel().