[ 'Content-Type' => 'application/json', 'Accept' => 'text/event-stream', 'Cache-Control' => 'no-cache', 'Authorization' => 'Bearer '.config('services.dashscope.api_key'), ], ]); $url = config('services.dashscope.api_base').'/compatible-mode/v1/chat/completions'; $messages = [ [ 'role' => 'user', 'content' => '你好', ], ]; $jsonBody = json_encode([ 'model' => $this->model, 'messages' => $messages, 'stream' => true, ]); $response = $client->request('POST', $url, [ 'body' => $jsonBody, 'stream' => true, ]); $body = $response->getBody(); // while (!$body->eof()) { // echo $body->read(1024); // } while (! $body->eof()) { // $body->read(1); echo $body->read(1); } } }