diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index a84ba93a1bc..05dee5b342b 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -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 diff --git a/tests/agent/test_auxiliary_client.py b/tests/agent/test_auxiliary_client.py index 3058f2e9c3c..b047b0d2a5e 100644 --- a/tests/agent/test_auxiliary_client.py +++ b/tests/agent/test_auxiliary_client.py @@ -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=[