> $tasks * @return array> */ public function runTasks(array $tasks): array { $response = Http::withToken($this->apiKey) ->timeout(120) ->post($this->baseUrl, $tasks); if ($response->failed()) { throw new RuntimeException('Runware API request failed: '.$response->body()); } $data = $response->json('data'); if (! is_array($data)) { throw new RuntimeException('Unexpected Runware response shape: '.$response->body()); } foreach ($data as $result) { if (isset($result['error']) || ($result['status'] ?? null) === 'error') { throw new RuntimeException('Runware task failed: '.json_encode($result)); } } return $data; } public function pollTask(string $taskUUID): array { $results = $this->runTasks([[ 'taskType' => 'getResponse', 'taskUUID' => $taskUUID, ]]); return $results[0] ?? throw new RuntimeException("No poll result for task {$taskUUID}"); } /** * @param array $payload * @return array */ public function chatCompletion(array $payload): array { $response = Http::withToken($this->apiKey) ->timeout(120) ->post(rtrim($this->baseUrl, '/').'/chat/completions', $payload); if ($response->failed()) { throw new RuntimeException('Runware chat completion failed: '.$response->body()); } return $response->json(); } }