Skip to content

Commit 0d9567c

Browse files
authored
Runpod: update RunpodApiClient (#3847)
* Use `requests.Session` * Pass API token as a header, not a query param. Prevents token leakage through logs: requests.exceptions.ConnectionError: Max retries exceeded with url: /graphql?api_key=rpa_xxxxx (Caused by ...)
1 parent 2e9c684 commit 0d9567c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/dstack/_internal/core/backends/runpod/api_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def __init__(self, errors: List[Dict]):
2222

2323
class RunpodApiClient:
2424
def __init__(self, api_key: str):
25-
self.api_key = api_key
25+
self._session = requests.Session()
26+
self._session.headers.update({"Authorization": f"Bearer {api_key}"})
2627

2728
def validate_api_key(self) -> bool:
2829
try:
@@ -353,9 +354,9 @@ def delete_cluster(self, cluster_id: str) -> bool:
353354

354355
def _make_request(self, data: Optional[Dict[str, Any]] = None) -> Response:
355356
try:
356-
response = requests.request(
357+
response = self._session.request(
357358
method="POST",
358-
url=f"{API_URL}?api_key={self.api_key}",
359+
url=API_URL,
359360
json=data,
360361
timeout=120,
361362
)

0 commit comments

Comments
 (0)