apikey = $config['gemini_apikey']; } /** * Send a request to the Gemini API * * @param string $endpoint * @param array $data Payload to send * @return array API response * @throws \Exception */ protected function request($model, $endpoint, $data) { $url = sprintf( 'https://generativelanguage.googleapis.com/v1beta/models/%s:%s?key=%s', $model, $endpoint, $this->apikey ); return $this->sendAPIRequest('POST', $url, $data); } /** @inheritdoc */ protected function parseAPIResponse($response) { if (isset($response['usageMetadata'])) { $this->inputTokensUsed += $response['usageMetadata']['promptTokenCount']; $this->outputTokensUsed += $response['usageMetadata']['candidatesTokenCount'] ?? 0; } if (isset($response['error'])) { throw new \Exception('Gemini API error: ' . $response['error']['message']); } return $response; } }