@@ -56,7 +56,7 @@ def __init__(self, api_key: Optional[str] = None):
56
56
57
57
def _request (
58
58
self , method : str , endpoint : str , data : Optional [dict ] = None ,
59
- timeout : int = 10 , api_key : Optional [ str ] = None
59
+ timeout : int = 10
60
60
):
61
61
"""
62
62
Make a request to the specified endpoint using the given HTTP method.
@@ -66,33 +66,17 @@ def _request(
66
66
endpoint: The endpoint path to which the request will be made.
67
67
data: The JSON payload to send with the request.
68
68
timeout: The number of seconds to wait for the server to send data before giving up.
69
- api_key: Optional API key to use for this specific request.
70
69
71
70
Returns:
72
71
The JSON response from the server.
73
72
74
73
Raises:
75
- ValueError: If request API key conflicts with instance API key.
76
74
RuntimeError: If the response returns a 401 Unauthorized status.
77
75
requests.HTTPError: If the response contains an unsuccessful status code.
78
76
"""
79
- # Check for conflicting API keys
80
- if api_key and self .api_key and api_key != self .api_key :
81
- raise ValueError (
82
- "Conflicting API keys: Request API key differs from instance API key. "
83
- "Use only one API key source to avoid security issues."
84
- )
85
-
86
- # Use request-specific API key if provided, otherwise use instance API key
87
- effective_api_key = api_key or self .api_key
88
- headers = self .headers if not api_key else {
89
- "Content-Type" : "application/json" ,
90
- "Authorization" : f"Bearer { effective_api_key } " ,
91
- }
92
-
93
77
url = f"{ self .endpoint_url_base } /{ endpoint } "
94
78
response = self .rp_session .request (
95
- method , url , headers = headers , json = data , timeout = timeout
79
+ method , url , headers = self . headers , json = data , timeout = timeout
96
80
)
97
81
98
82
if response .status_code == 401 :
@@ -101,13 +85,13 @@ def _request(
101
85
response .raise_for_status ()
102
86
return response .json ()
103
87
104
- def post (self , endpoint : str , data : dict , timeout : int = 10 , api_key : Optional [ str ] = None ):
105
- """Post to the endpoint with optional API key override ."""
106
- return self ._request ("POST" , endpoint , data , timeout , api_key = api_key )
88
+ def post (self , endpoint : str , data : dict , timeout : int = 10 ):
89
+ """Post to the endpoint."""
90
+ return self ._request ("POST" , endpoint , data , timeout )
107
91
108
- def get (self , endpoint : str , timeout : int = 10 , api_key : Optional [ str ] = None ):
109
- """Get from the endpoint with optional API key override ."""
110
- return self ._request ("GET" , endpoint , timeout = timeout , api_key = api_key )
92
+ def get (self , endpoint : str , timeout : int = 10 ):
93
+ """Get from the endpoint."""
94
+ return self ._request ("GET" , endpoint , timeout = timeout )
111
95
112
96
113
97
# ---------------------------------------------------------------------------- #
@@ -116,30 +100,26 @@ def get(self, endpoint: str, timeout: int = 10, api_key: Optional[str] = None):
116
100
class Job :
117
101
"""Represents a job to be run on the Runpod service."""
118
102
119
- def __init__ (self , endpoint_id : str , job_id : str , client : RunPodClient ,
120
- api_key : Optional [str ] = None ):
103
+ def __init__ (self , endpoint_id : str , job_id : str , client : RunPodClient ):
121
104
"""
122
105
Initialize a Job instance with the given endpoint ID and job ID.
123
106
124
107
Args:
125
108
endpoint_id: The identifier for the endpoint.
126
109
job_id: The identifier for the job.
127
110
client: An instance of the RunPodClient to make requests with.
128
- api_key: Optional API key for this specific job.
129
111
"""
130
112
self .endpoint_id = endpoint_id
131
113
self .job_id = job_id
132
114
self .rp_client = client
133
- self .api_key = api_key # Store job-specific API key
134
115
135
116
self .job_status = None
136
117
self .job_output = None
137
118
138
119
def _fetch_job (self , source : str = "status" ) -> Dict [str , Any ]:
139
120
"""Returns the raw json of the status, raises an exception if invalid"""
140
121
status_url = f"{ self .endpoint_id } /{ source } /{ self .job_id } "
141
- # Pass the job-specific API key if available
142
- job_state = self .rp_client .get (endpoint = status_url , api_key = self .api_key )
122
+ job_state = self .rp_client .get (endpoint = status_url )
143
123
144
124
if is_completed (job_state ["status" ]):
145
125
self .job_status = job_state ["status" ]
@@ -197,8 +177,7 @@ def cancel(self, timeout: int = 3) -> Any:
197
177
return self .rp_client .post (
198
178
f"{ self .endpoint_id } /cancel/{ self .job_id } " ,
199
179
data = None ,
200
- timeout = timeout ,
201
- api_key = self .api_key
180
+ timeout = timeout
202
181
)
203
182
204
183
@@ -225,13 +204,12 @@ def __init__(self, endpoint_id: str, api_key: Optional[str] = None):
225
204
self .endpoint_id = endpoint_id
226
205
self .rp_client = RunPodClient (api_key = api_key )
227
206
228
- def run (self , request_input : Dict [str , Any ], api_key : Optional [ str ] = None ) -> Job :
207
+ def run (self , request_input : Dict [str , Any ]) -> Job :
229
208
"""
230
209
Run the endpoint with the given input.
231
210
232
211
Args:
233
212
request_input: The input to pass into the endpoint.
234
- api_key: Optional API key to use for this specific request.
235
213
236
214
Returns:
237
215
A Job instance for the run request.
@@ -241,65 +219,57 @@ def run(self, request_input: Dict[str, Any], api_key: Optional[str] = None) -> J
241
219
242
220
job_request = self .rp_client .post (
243
221
f"{ self .endpoint_id } /run" ,
244
- request_input ,
245
- api_key = api_key
222
+ request_input
246
223
)
247
- return Job (self .endpoint_id , job_request ["id" ], self .rp_client , api_key = api_key )
224
+ return Job (self .endpoint_id , job_request ["id" ], self .rp_client )
248
225
249
226
def run_sync (
250
- self , request_input : Dict [str , Any ], timeout : int = 86400 ,
251
- api_key : Optional [str ] = None
227
+ self , request_input : Dict [str , Any ], timeout : int = 86400
252
228
) -> Dict [str , Any ]:
253
229
"""
254
230
Run the endpoint with the given input synchronously.
255
231
256
232
Args:
257
233
request_input: The input to pass into the endpoint.
258
234
timeout: Maximum time to wait for the job to complete.
259
- api_key: Optional API key to use for this specific request.
260
235
"""
261
236
if not request_input .get ("input" ):
262
237
request_input = {"input" : request_input }
263
238
264
239
job_request = self .rp_client .post (
265
240
f"{ self .endpoint_id } /runsync" ,
266
241
request_input ,
267
- timeout = timeout ,
268
- api_key = api_key
242
+ timeout = timeout
269
243
)
270
244
271
245
if job_request ["status" ] in FINAL_STATES :
272
246
return job_request .get ("output" , None )
273
247
274
248
return Job (
275
- self .endpoint_id , job_request ["id" ], self .rp_client , api_key = api_key
249
+ self .endpoint_id , job_request ["id" ], self .rp_client
276
250
).output (timeout = timeout )
277
251
278
- def health (self , timeout : int = 3 , api_key : Optional [ str ] = None ) -> Dict [str , Any ]:
252
+ def health (self , timeout : int = 3 ) -> Dict [str , Any ]:
279
253
"""
280
254
Check the health of the endpoint (number/state of workers, number/state of requests).
281
255
282
256
Args:
283
257
timeout: The number of seconds to wait for the server to respond before giving up.
284
- api_key: Optional API key to use for this specific request.
285
258
"""
286
259
return self .rp_client .get (
287
260
f"{ self .endpoint_id } /health" ,
288
- timeout = timeout ,
289
- api_key = api_key
261
+ timeout = timeout
290
262
)
291
263
292
- def purge_queue (self , timeout : int = 3 , api_key : Optional [ str ] = None ) -> Dict [str , Any ]:
264
+ def purge_queue (self , timeout : int = 3 ) -> Dict [str , Any ]:
293
265
"""
294
266
Purges the endpoint's job queue and returns the result of the purge request.
295
267
296
268
Args:
297
269
timeout: The number of seconds to wait for the server to respond before giving up.
298
- api_key: Optional API key to use for this specific request.
299
270
"""
300
271
return self .rp_client .post (
301
272
f"{ self .endpoint_id } /purge-queue" ,
302
273
data = None ,
303
- timeout = timeout ,
304
- api_key = api_key
274
+ timeout = timeout
305
275
)
0 commit comments