Skip to content

Commit 38a8675

Browse files
Merge pull request #39 from LukeWood/patch-1
Add informative error message when API key not provided
2 parents f02cc40 + e5afa8b commit 38a8675

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

runpod/endpoint/runner.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ def __init__(self):
1818
Initialize the client.
1919
'''
2020
from runpod import api_key, endpoint_url_base # pylint: disable=import-outside-toplevel, cyclic-import
21-
21+
if api_key is None:
22+
raise RuntimeError(
23+
"Expected `run_pod.api_key` to be initialized. "
24+
"You can solve this by running `run_pod.api_key = 'your-key'. "
25+
"An API key can be generated at "
26+
"https://www.runpod.io/console/user/settings"
27+
)
2228
self.rp_session = requests.Session()
2329
retries = Retry(total=5, backoff_factor=0.1, status_forcelist=[429])
2430
self.rp_session.mount('http://', HTTPAdapter(max_retries=retries))

tests/test_endpoint/test_runner.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
class TestEndpoint(unittest.TestCase):
1313
''' Tests for Endpoint '''
1414

15+
def test_missing_api_key(self):
16+
'''
17+
Tests Endpoint.run without api_key
18+
'''
19+
with self.assertRaises(RuntimeError):
20+
runpod.Endpoint("ENDPOINT_ID")
21+
1522
@patch.object(requests.Session, 'get')
1623
@patch.object(requests.Session, 'post')
1724
def test_run(self, mock_post, mock_get):
@@ -26,6 +33,7 @@ def test_run(self, mock_post, mock_get):
2633
mock_post.return_value = mock_response
2734
mock_get.return_value = mock_response
2835

36+
runpod.api_key = "MOCK_API_KEY"
2937
endpoint = runpod.Endpoint("ENDPOINT_ID")
3038

3139
request_data = {"YOUR_MODEL_INPUT_JSON": "YOUR_MODEL_INPUT_VALUE"}
@@ -47,6 +55,7 @@ def test_run_sync(self, mock_post):
4755
}
4856
mock_post.return_value = mock_response
4957

58+
runpod.api_key = "MOCK_API_KEY"
5059
endpoint = runpod.Endpoint("ENDPOINT_ID")
5160

5261
request_data = {"YOUR_MODEL_INPUT_JSON": "YOUR_MODEL_INPUT_VALUE"}

0 commit comments

Comments
 (0)