fix(codex): skip auxiliary cache retention on Codex backend

This commit is contained in:
Israel Lot 2026-07-23 21:14:30 +00:00 committed by Teknium
parent 339be21542
commit 48049a1d31
2 changed files with 18 additions and 1 deletions

View file

@ -1067,11 +1067,20 @@ class _CodexCompletionsAdapter:
_host_src = str(getattr(self._client, "base_url", "") or "")
_is_xai = base_url_host_matches(_host_src, "x.ai") or base_url_host_matches(_host_src, "api.x.ai")
_is_github = base_url_host_matches(_host_src, "githubcopilot.com")
_is_codex_backend = (
base_url_host_matches(_host_src, "chatgpt.com")
and "/backend-api/codex" in _host_src.lower()
)
if not _is_xai and not _is_github and "prompt_cache_key" not in resp_kwargs:
_cache_key = _content_cache_key(instructions, resp_kwargs.get("tools"))
if _cache_key:
resp_kwargs["prompt_cache_key"] = _cache_key
if not _is_xai and not _is_github and "prompt_cache_retention" not in resp_kwargs:
if (
not _is_xai
and not _is_github
and not _is_codex_backend
and "prompt_cache_retention" not in resp_kwargs
):
_cache_retention = _prompt_cache_retention_for_model(model)
if _cache_retention:
resp_kwargs["prompt_cache_retention"] = _cache_retention

View file

@ -4966,6 +4966,14 @@ class TestCodexAdapterPromptCacheKey:
])
assert captured["prompt_cache_retention"] == "24h"
def test_prompt_cache_retention_skipped_for_codex_backend(self):
adapter, captured = self._build_adapter()
adapter.create(messages=[
{"role": "system", "content": "SYS"},
{"role": "user", "content": "hi"},
])
assert "prompt_cache_retention" not in captured
def test_prompt_cache_retention_skipped_for_xai_and_github_hosts(self):
adapter, captured = self._build_adapter(base_url="https://api.x.ai/v1")
adapter.create(messages=[