$metadata * @return array */ public function createResponse(AgentProfile $profile, string $input, array $metadata = []): array { $response = $this->request($profile)->post($this->url($profile), [ 'model' => 'default', 'input' => $input, 'metadata' => $metadata, ]); $response->throw(); $payload = $response->json(); return is_array($payload) ? $payload : []; } private function request(AgentProfile $profile): PendingRequest { return Http::withToken((string) $profile->api_key_cipher) ->acceptJson() ->asJson() ->timeout(60); } private function url(AgentProfile $profile): string { return rtrim($profile->gateway_url, '/').'/v1/responses'; } }