UI disturbes in Spanish language when call Api also response time too long

When user enter question in spanish language then api returns spaceless words and also it take too much time to response, like 2 to 5 min

My codes given bellow–
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘https://api.openai.com/v1/completions’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, “{\n "model": "text-davinci-003",\n "prompt": "$request->aitopic",\n "temperature": 0.6,\n "max_tokens": 2048,\n "top_p": 1,\n "frequency_penalty": 1,\n "presence_penalty": 1\n}”);
$headers = array();
$headers = ‘Content-Type: application/json’;
$headers = ‘Authorization: Bearer sk-ZrDc’;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
/if (curl_errno($ch)) {
return response()->json();
}
/
$data = json_decode($result,true);
$ai = nl2br($data[‘choices’][0][‘text’]) ?? NULL;
curl_close($ch);