AWS Function URL SSE with Laravel

I am trying to implement an OpenAI stream event using AWS Lambda on a project built using Laravel.

I have defined a function URL and set CORS headers as below but no luck as well:

Expose headers content-type, connection, cache-control Allow headers content-type, connection, cache-control, x-custom-header.

Here’s my current logic which works fine on my local.

return response()->stream(function () use ($prompt) {
    $stream = OpenAI::chat()->createStreamed([
        'model' => 'gpt-3.5-turbo',
        'messages' => $prompt['messages'],
        'presence_penalty' => 0.6,
        'frequency_penalty' => 0
    ]);

    $output = "";
    $responsedText = "";

    foreach ($stream as $response){
        if (isset($response['choices'][0]['delta']['content'])){
            $message = $response['choices'][0]['delta']['content'];
            $messageFix = str_replace(["\r\n", "\r", "\n"], "<br/>", $message);
            $output .= $messageFix;
            $responsedText .= $message;
            $string_length = Str::length($messageFix);
            $needChars = 6000-$string_length;
            $random_text = Str::random($needChars);
            echo PHP_EOL;
            echo 'data: ' . $messageFix.'/**'.$random_text."\n\n";
            ob_flush();
            flush();
            usleep(5000);
        }
        if (connection_aborted()) {
            break;
        }
    }
    echo 'data: [DONE]';
    echo "\n\n";
    ob_flush();
    flush();
    usleep(50000);
}, 200, [
    'Cache-Control' => 'no-cache',
    'X-Accel-Buffering' => 'no',
    'Content-Type' => 'text/event-stream',
]);

However, I am getting this error “EventSource’s response has a MIME
type (“application/octet-stream”) that is not “text/event-stream”. Aborting the connection”. Any idea where I could be going wrong?