From 5304baa424a8b0393a8ad3cec8f2c688608aad93 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 13 Jul 2026 16:12:07 -0700 Subject: [PATCH] feat(llm): change OpenRouter LLM request headers (#760) * feat(llm): attribute OpenRouter usage to Strix app Co-Authored-By: Ahmed Allam * scope OpenRouter category header to OpenRouter models; add OR_APP_CATEGORIES override Co-Authored-By: Ahmed Allam * clear stale OpenRouter category header when switching providers Co-Authored-By: Ahmed Allam * hardcode OpenRouter attribution headers; drop env overrides and docs section Co-Authored-By: Ahmed Allam * drop attribution comments Co-Authored-By: Ahmed Allam --------- Co-authored-by: Ahmed Allam --- strix/config/models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/strix/config/models.py b/strix/config/models.py index 3cca9fb3..768a8f02 100644 --- a/strix/config/models.py +++ b/strix/config/models.py @@ -65,6 +65,7 @@ def configure_sdk_model_defaults(settings: Settings) -> None: llm = settings.llm set_tracing_disabled(True) _configure_litellm_compatibility() + _configure_openrouter_attribution(llm.model) if llm.api_key: set_default_openai_key(llm.api_key, use_for_tracing=False) _configure_litellm_default("api_key", llm.api_key) @@ -111,6 +112,29 @@ def _configure_litellm_compatibility() -> None: _register_litellm_cost_callback() +_OPENROUTER_ATTRIBUTION_HEADERS = { + "HTTP-Referer": "https://strix.ai", + "X-Title": "Strix", + "X-OpenRouter-Categories": "cli-agent", +} + + +def _configure_openrouter_attribution(model_name: str | None) -> None: + import litellm + + current: object = litellm.headers + existing: dict[str, str] = current if isinstance(current, dict) else {} + if not model_name or "openrouter/" not in model_name.strip().lower(): + if any(key in existing for key in _OPENROUTER_ATTRIBUTION_HEADERS): + remaining = { + k: v for k, v in existing.items() if k not in _OPENROUTER_ATTRIBUTION_HEADERS + } + litellm.headers = remaining or None # type: ignore[assignment] + return + + litellm.headers = {**existing, **_OPENROUTER_ATTRIBUTION_HEADERS} # type: ignore[assignment] + + def _register_litellm_cost_callback() -> None: import litellm