Skip to content

Commit 7ceddb7

Browse files
committed
feat: add user agent format
1 parent 65215bd commit 7ceddb7

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

runpod/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import logging
5+
import platform
56

67
from . import serverless
78
from .serverless.modules.rp_logger import RunPodLogger
@@ -35,6 +36,13 @@
3536
endpoint_url_base = "https://api.runpod.ai/v2" # pylint: disable=invalid-name
3637

3738

39+
# ----------------------------- Config User Agent ---------------------------- #
40+
os_info = f"{platform.system()} {platform.release()}; {platform.machine()}"
41+
USER_AGENT = f"RunPod-Python-SDK/{__version__} ({os_info}) Language/Python{platform.python_version()}" # pylint: disable=line-too-long
42+
43+
if os.environ.get('RUNPOD_UA_INTEGRATION') is not None:
44+
USER_AGENT += f" {os.environ.get('RUNPOD_UA_INTEGRATION')}"
45+
3846
# --------------------------- Force Logging Levels --------------------------- #
3947
logging.getLogger("urllib3").setLevel(logging.WARNING)
4048
logging.getLogger("paramiko").setLevel(logging.WARNING)

runpod/api/graphql.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@
77

88
import requests
99

10-
from runpod import error
10+
from runpod import error, USER_AGENT
1111

1212
HTTP_STATUS_UNAUTHORIZED = 401
1313

14+
1415
def run_graphql_query(query: str) -> Dict[str, Any]:
1516
'''
1617
Run a GraphQL query
1718
'''
1819
from runpod import api_key # pylint: disable=import-outside-toplevel, cyclic-import
1920
url = f"https://api.runpod.io/graphql?api_key={api_key}"
21+
2022
headers = {
2123
"Content-Type": "application/json",
24+
"User-Agent": USER_AGENT,
2225
}
26+
2327
data = json.dumps({"query": query})
2428
response = requests.post(url, headers=headers, data=data, timeout=30)
2529

runpod/serverless/worker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import aiohttp
1010

11+
from runpod import USER_AGENT
1112
from runpod.serverless.modules import (
1213
rp_logger, rp_local, rp_handler, rp_ping,
1314
rp_scale
@@ -24,7 +25,10 @@
2425

2526
def _get_auth_header() -> Dict[str, str]:
2627
""" Returns the authorization header with the API key. """
27-
return {"Authorization": f"{os.environ.get('RUNPOD_AI_API_KEY')}"}
28+
return {
29+
"Authorization": f"{os.environ.get('RUNPOD_AI_API_KEY')}",
30+
"User-Agent": USER_AGENT
31+
}
2832

2933

3034
def _is_local(config) -> bool:

0 commit comments

Comments
 (0)