diff --git a/lib/Service/OpenAiAPIService.php b/lib/Service/OpenAiAPIService.php index 0c1679d5..7a9722ef 100644 --- a/lib/Service/OpenAiAPIService.php +++ b/lib/Service/OpenAiAPIService.php @@ -91,6 +91,26 @@ public function isUsingOpenAi(?string $serviceType = null): bool { return $serviceUrl === '' || $serviceUrl === Application::OPENAI_API_BASE_URL; } + /** + * @param ?string $serviceType + * @return bool + */ + public function isUsingOpenRouter(?string $serviceType = null): bool { + $serviceUrl = ''; + if ($serviceType === Application::SERVICE_TYPE_IMAGE) { + $serviceUrl = $this->openAiSettingsService->getImageServiceUrl(); + } elseif ($serviceType === Application::SERVICE_TYPE_STT) { + $serviceUrl = $this->openAiSettingsService->getSttServiceUrl(); + } elseif ($serviceType === Application::SERVICE_TYPE_TTS) { + $serviceUrl = $this->openAiSettingsService->getTtsServiceUrl(); + } + if ($serviceUrl === '') { + $serviceUrl = $this->openAiSettingsService->getServiceUrl(); + } + // Return true if the service URL references OpenRouter (e.g., openrouter.ai) + return str_starts_with(strtolower($serviceUrl), 'https://openrouter.ai'); + } + /** * @param ?string $serviceType * @@ -221,7 +241,8 @@ public function getModels(?string $userId, bool $refresh = false, ?string $servi try { $this->logger->debug('Actually getting OpenAI models with a network request'); - $modelsResponse = $this->request($userId, 'models', serviceType: $serviceType); + $params = $this->isUsingOpenRouter($serviceType) ? ['output_modalities' => 'all'] : []; + $modelsResponse = $this->request($userId, 'models', $params, serviceType: $serviceType); } catch (Exception $e) { $this->logger->warning('Error retrieving models (exc): ' . $e->getMessage()); throw $e;