fix(openrouter): force store false for responses api (#30868)

This commit is contained in:
Saicharan Ramineni 2026-06-23 09:21:33 -04:00 • committed by Sameer Kankute
parent 7c18d9cd4f
commit de7d22283e
No known key found for this signature in database
2 changed files with 49 additions and 1 deletions

View file

@ -13,6 +13,7 @@ from typing import Optional
import litellm
from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig
from litellm.secret_managers.main import get_secret_str
from litellm.types.llms.openai import ResponseInputParam
from litellm.types.router import GenericLiteLLMParams
from litellm.types.utils import LlmProviders
@ -72,6 +73,23 @@ class OpenRouterResponsesAPIConfig(OpenAIResponsesAPIConfig):
return f"{api_base}/responses"
def transform_responses_api_request(
self,
model: str,
input: str | ResponseInputParam,
response_api_optional_request_params: dict,
litellm_params: GenericLiteLLMParams,
headers: dict,
) -> dict:
response_api_optional_request_params["store"] = False
return super().transform_responses_api_request(
model=model,
input=input,
response_api_optional_request_params=response_api_optional_request_params,
litellm_params=litellm_params,
headers=headers,
)
def supports_native_websocket(self) -> bool:
"""OpenRouter does not support native WebSocket for Responses API"""
return False

View file

@ -13,6 +13,7 @@ import litellm
from litellm.llms.openrouter.responses.transformation import (
OpenRouterResponsesAPIConfig,
)
from litellm.types.router import GenericLiteLLMParams
from litellm.types.utils import LlmProviders
from litellm.utils import ProviderConfigManager
@ -63,7 +64,6 @@ class TestOpenRouterResponsesAPIConfig:
def test_validate_environment_raises_without_key(self, monkeypatch):
"""validate_environment should raise when no API key is available."""
config = OpenRouterResponsesAPIConfig()
from litellm.types.router import GenericLiteLLMParams
# Clear any globally set API keys so the validation correctly raises
monkeypatch.setattr(litellm, "api_key", None)
@ -80,6 +80,36 @@ class TestOpenRouterResponsesAPIConfig:
except ValueError as e:
assert "OpenRouter API key is required" in str(e)
def test_transform_responses_api_request_forces_store_false_when_true(self):
"""OpenRouter only accepts store=false for Responses API requests."""
config = OpenRouterResponsesAPIConfig()
request_params = {"store": True, "temperature": 0.2}
transformed = config.transform_responses_api_request(
model="openai/o4-mini",
input="hello",
response_api_optional_request_params=request_params,
litellm_params=GenericLiteLLMParams(),
headers={},
)
assert transformed["store"] is False
assert transformed["temperature"] == 0.2
def test_transform_responses_api_request_forces_store_false_when_omitted(self):
"""Omitted store should be sent as false instead of null/true."""
config = OpenRouterResponsesAPIConfig()
transformed = config.transform_responses_api_request(
model="openai/o4-mini",
input="hello",
response_api_optional_request_params={},
litellm_params=GenericLiteLLMParams(),
headers={},
)
assert transformed["store"] is False
class TestOpenRouterResponsesAPIRegistration:
"""Test that OpenRouter is properly registered as a native Responses API provider."""