Skip to content

πŸ™Œ OpenHands: AI-Driven Development

[llm] Add app name for OpenRouter (#4010)

Xingyao Wang8ea2d61ff22c
diff --git a/openhands/core/config/llm_config.py b/openhands/core/config/llm_config.py
index af766045ea..cf60184251 100644
--- a/openhands/core/config/llm_config.py
+++ b/openhands/core/config/llm_config.py
@@ -50,6 +50,8 @@ class LLMConfig:
aws_access_key_id: str | None = None
aws_secret_access_key: str | None = None
aws_region_name: str | None = None
+ openrouter_site_url: str = 'https://docs.all-hands.dev/'
+ openrouter_app_name: str = 'OpenHands'
num_retries: int = 8
retry_multiplier: float = 2
retry_min_wait: int = 15
diff --git a/openhands/llm/llm.py b/openhands/llm/llm.py
index 9e4c00399f..022ec0f6dd 100644
--- a/openhands/llm/llm.py
+++ b/openhands/llm/llm.py
@@ -1,5 +1,6 @@
import asyncio
import copy
+import os
import time
import warnings
from functools import partial
@@ -75,6 +76,9 @@ class LLM:
self.cost_metric_supported = True
self.config = copy.deepcopy(config)
+ os.environ['OR_SITE_URL'] = self.config.openrouter_site_url
+ os.environ['OR_APP_NAME'] = self.config.openrouter_app_name
+
# list of LLM completions (for logging purposes). Each completion is a dict with the following keys:
# - 'messages': list of messages
# - 'response': response from the LLM