From e8b9369a9d2df36139a5055cae3ed3c15691e03e Mon Sep 17 00:00:00 2001 From: Ben Heidorn <301326+Cybourgeoisie@users.noreply.github.com> Date: Thu, 28 May 2026 11:02:28 -0400 Subject: [PATCH] feat(openrouter): pass session_id in extra_body for sticky routing OpenRouter supports a session_id field in extra_body that pins multi-turn conversations to the same provider endpoint, enabling prompt cache reuse across turns. The session_id was already threaded through to build_extra_body() but never included in the returned dict. Co-Authored-By: Claude Opus 4 (1M context) --- plugins/model-providers/openrouter/__init__.py | 2 ++ tests/providers/test_provider_profiles.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/plugins/model-providers/openrouter/__init__.py b/plugins/model-providers/openrouter/__init__.py index d1bf10de11d..1b464b42e82 100644 --- a/plugins/model-providers/openrouter/__init__.py +++ b/plugins/model-providers/openrouter/__init__.py @@ -43,6 +43,8 @@ class OpenRouterProfile(ProviderProfile): self, *, session_id: str | None = None, **context: Any ) -> dict[str, Any]: body: dict[str, Any] = {} + if session_id: + body["session_id"] = session_id prefs = context.get("provider_preferences") if prefs: body["provider"] = prefs diff --git a/tests/providers/test_provider_profiles.py b/tests/providers/test_provider_profiles.py index df96a80fd80..7a2bb081593 100644 --- a/tests/providers/test_provider_profiles.py +++ b/tests/providers/test_provider_profiles.py @@ -98,6 +98,11 @@ class TestOpenRouterProfile: body = p.build_extra_body(provider_preferences={"allow": ["anthropic"]}) assert body["provider"] == {"allow": ["anthropic"]} + def test_extra_body_session_id(self): + p = get_provider_profile("openrouter") + body = p.build_extra_body(session_id="test-session-123") + assert body["session_id"] == "test-session-123" + def test_extra_body_no_prefs(self): p = get_provider_profile("openrouter") body = p.build_extra_body()