MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / apply_openai_cache_hints

Function apply_openai_cache_hints

uncommon_route/cache_support.py:53–78  ·  view source on GitHub ↗
(
    body: dict[str, Any],
    *,
    model: str,
    session_id: str | None,
    step_type: str,
)

Source from the content-addressed store, hash-verified

51
52
53def apply_openai_cache_hints(
54 body: dict[str, Any],
55 *,
56 model: str,
57 session_id: str | None,
58 step_type: str,
59) -> CacheRequestPlan:
60 tools = body.get("tools") or body.get("customTools") or []
61 if not session_id and not tools and step_type == "general":
62 return CacheRequestPlan(family="openai")
63
64 key = _stable_prompt_cache_key(body, model=model, session_id=session_id, step_type=step_type)
65 if key:
66 body["prompt_cache_key"] = key
67
68 retention = ""
69 if _is_openai_cache_retention_model(model):
70 retention = "24h" if (session_id and (step_type != "general" or tools)) else "in-memory"
71 body["prompt_cache_retention"] = retention
72
73 return CacheRequestPlan(
74 family="openai",
75 mode="prompt_cache_key",
76 prompt_cache_key=key,
77 retention=retention,
78 )
79
80
81def apply_anthropic_cache_breakpoints(

Callers 1

Calls 4

CacheRequestPlanClass · 0.85
_stable_prompt_cache_keyFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected