Error 500 Timeout Laravel app

Hello everyone!, I’m trying to write an application using gps 3.5 turbo 16k, but there is a problem and it lies in the fact that when writing a 2000 tokens, the server constantly goes into timeout
The code of my controller is given below: (If there is anything else you need, then be sure to write) :

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Request;

class ChatController extends Controller
    private $openAIRequest;

    public function __construct()
        $this->openAIRequest = Http::withoutVerifying()
            ->withOptions(['timeout' => 120])
                'Authorization' => 'Bearer ' . config('openai.api_key'),
                'Content-Type' => 'application/json',

    public function messeges(Request $request)
        $prompt = $request->input('prompt');
        $proglang = $request->input('proglang');
        $framework = $request->input('framework');
        $size = $request->input('size');
        $lang = $request->input('lang');
        $message = $proglang . $framework . $size . $lang . $prompt ;

        return $this->askToChatGPT($message);

    private function askToChatGPT($message)
        $response = $this->openAIRequest->post('', [
            "model" => "gpt-3.5-turbo-16k",
            "messages" => [
                    "role" => "user",
                    "content" => $message
            "max_tokens" => 5000,
        return $response->json()['choices'][0]['message']['content'];
"message": "Maximum execution time of 60 seconds exceeded",
"exception": "Symfony\\Component\\ErrorHandler\\Error\\Fatal error

And also here are the laravel logs:

[previous exception] [object] (PDOException(code: 2002): SQLSTATE[HY000] [2002] Disconnection is not set, because the conjugator has disabled access to the connection in C:\\Users\\crash\\OneDrive\\Рабочий stol\\ANGELS-iT DOCUMENTARIAN\\Application\\provider\\laravel\\framework\\src\\Illuminate\\Database\\Connectors\\Connector.php:65)
[stack tracking] 
[2023-10-13 08:08:13] local.mistake: Exceeded the maximum execution time by 60 seconds {"userId":1,"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Exceeded the maximum execution time by 60 seconds when C:\\Users\\crash\\OneDrive\\Рабочий table\\ANGELS is A DOCUMENTARIAN\\Application\\provider\\guzzlehttp\\guzzle\\src\\Handler\\CurlHandler.php:45)
[stack tracking]
#0 {main}
1 Like

Hi and welcome to the Developer Forum!

You have hit a potentially difficult set of circumstances, long generations will take more than 60 seconds, so that is the primary issue.

You can get around this by using streaming, this will send small delta update packets containing the next token or tokens via SSE (Server Side Events) so your server environment needs to to support SSE and you will need to implement a call with stream=true set as an option.

There is a video guide here


Thank you so much for prompting . Do you know if there is something like this video but in the context of laravel

I don’t unfortunately, my only advice would be to have a bing/google search for anything related, AI is so new that it might not have been done before! I wish you luck.

1 Like