From a3d53b225f02994ba4969f8e2bbfb0d7c878b256 Mon Sep 17 00:00:00 2001 From: Lukas Schaefer Date: Fri, 17 Jul 2026 14:52:23 -0400 Subject: [PATCH] fix: openrouter filters out non llm models by default Signed-off-by: Lukas Schaefer --- lib/Service/OpenAiAPIService.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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;