[Bug]: prompt_cache_key is rejected for custom OpenAI-compatible Responses providers
QwenPaw Version
2.2.2b4
Description
Since #7899, request parameters pass through cache_request() in src/qwenpaw/providers/adapters/cache_policy.py. It raises ValueError: Unsupported cache control: prompt_cache_key unless the provider's cache capabilities include openai or openai_explicit.
OpenAIProvider.cache_capabilities() returns these capabilities only when the base URL host is api.openai.com. Custom providers inherit an empty cache_modes. As a result, setting prompt_cache_key (or prompt_cache_retention) in a model's advanced JSON (generate_kwargs) makes every request fail before it is sent. Moving it into extra_body gives the same error, because cache_request() moves it out of extra_body and validates it again.
Users cannot declare the capability in the configuration. cache_modes is a class attribute. When "cache_modes": ["openai"] is added to the provider JSON, it is ignored and removed on the next save.
Before we upgraded to a version with #7899, the same prompt_cache_key setting was sent to our OpenAI-compatible Responses gateway. For long agent sessions this parameter matters: OpenAI documents prompt_cache_key as a way to improve cache hit rates for requests that share a long prefix. Without it, our cache hit rate drops significantly.
We would like one of these options:
- Add a per-provider option in the custom provider settings, for example "Supports OpenAI prompt cache parameters (
prompt_cache_key/prompt_cache_retention)", which addsopenaito that provider's cache capabilities. - Or forward
prompt_cache_key/prompt_cache_retentionfor custom providers when the user sets them explicitly. These are not common parameters. Users who configure them understand what they do, so accidental misconfiguration is unlikely. If an upstream does not support them, the user sees the upstream error and can remove the setting.
The explicit caching controls (prompt_cache_options, enable_prompt_cache_breakpoint) can stay gated. This request covers only prompt_cache_key and prompt_cache_retention.
Related PR(s): #7899 (added cache_policy.py). Related issue: #6649.
Security considerations: prompt_cache_key is an opaque cache routing value chosen by the user. Forwarding it does not expose credentials or other configuration.
Component(s) Affected
- Core / Backend (app, agents, config, providers, utils, local_models)
- Console (frontend web UI)
- Channels (DingTalk, Feishu, QQ, Discord, iMessage, etc.)
- Skills
- CLI
- Documentation (website)
- Tests
- CI/CD
- Scripts / Deploy
Environment
- QwenPaw version: 2.2.2b4
- OS: Windows 11
- Install method: pip
- Python version (if applicable): 3.12.10
Steps to Reproduce
- Add a custom provider that uses the OpenAI Responses protocol (
OpenAIResponseModel) with a base URL other thanapi.openai.com, for examplehttps://gateway.example.com/v1. - In a model's advanced JSON (
generate_kwargs), add"prompt_cache_key": "my-stable-key". - Send a chat message with this model.
Actual vs Expected
- Actual: The request fails locally with
ValueError: Unsupported cache control: prompt_cache_key. Nothing is sent upstream. - Expected:
prompt_cache_keyis included in the Responses request body, either after the user enables a capability option or by default for custom providers.
Logs / Screenshots
Traceback from qwenpaw.log (paths shortened, middleware frames omitted):
File "site-packages/qwenpaw/providers/openai_response_provider.py", line 130, in _call_api
merged = self._request_policy(model_name, f"responses", merged)
File "site-packages/qwenpaw/providers/provider.py", line 386, in prepare_request
result = cache_request(
File "site-packages/qwenpaw/providers/adapters/cache_policy.py", line 75, in cache_request
raise ValueError(f"Unsupported cache control: {name}")
ValueError: Unsupported cache control: prompt_cache_keyMinimal offline reproduction with the installed package (no network request):
from qwenpaw.providers.openai_response_provider import OpenAIResponseProvider
provider = OpenAIResponseProvider(
id="my-gateway",
name="demo",
chat_model="OpenAIResponseModel",
base_url="https://gateway.example.com/v1",
)
print(provider.cache_capabilities("gpt-x"))
for kwargs in (
{"prompt_cache_key": "my-stable-key"},
{"extra_body": {"prompt_cache_key": "my-stable-key"}},
):
try:
provider.prepare_request("gpt-x", "responses", kwargs)
except ValueError as exc:
print(f"ValueError: {exc}")Output:
frozenset()
ValueError: Unsupported cache control: prompt_cache_key
ValueError: Unsupported cache control: prompt_cache_keyAdditional Notes
Current workaround: patch OpenAIProvider.cache_capabilities() locally so it returns frozenset({"implicit", "openai"}) for the affected provider ID. The patch has to be applied again after every upgrade.
The installed OpenAI SDK (2.33.0) accepts prompt_cache_key as a native responses.create() parameter, so forwarding it needs no special request handling.
Source: agentscope-ai/QwenPaw