@@ -56,7 +56,7 @@ def __init__(self, api_key: Optional[str] = None):
5656
5757 def _request (
5858 self , method : str , endpoint : str , data : Optional [dict ] = None ,
59- timeout : int = 10 , api_key : Optional [ str ] = None
59+ timeout : int = 10
6060 ):
6161 """
6262 Make a request to the specified endpoint using the given HTTP method.
@@ -66,33 +66,17 @@ def _request(
6666 endpoint: The endpoint path to which the request will be made.
6767 data: The JSON payload to send with the request.
6868 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.
7069
7170 Returns:
7271 The JSON response from the server.
7372
7473 Raises:
75- ValueError: If request API key conflicts with instance API key.
7674 RuntimeError: If the response returns a 401 Unauthorized status.
7775 requests.HTTPError: If the response contains an unsuccessful status code.
7876 """
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-
9377 url = f"{ self .endpoint_url_base } /{ endpoint } "
9478 response = self .rp_session .request (
95- method , url , headers = headers , json = data , timeout = timeout
79+ method , url , headers = self . headers , json = data , timeout = timeout
9680 )
9781
9882 if response .status_code == 401 :
@@ -101,13 +85,13 @@ def _request(
10185 response .raise_for_status ()
10286 return response .json ()
10387
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 )
10791
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 )
11195
11296
11397# ---------------------------------------------------------------------------- #
@@ -116,30 +100,26 @@ def get(self, endpoint: str, timeout: int = 10, api_key: Optional[str] = None):
116100class Job :
117101 """Represents a job to be run on the Runpod service."""
118102
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 ):
121104 """
122105 Initialize a Job instance with the given endpoint ID and job ID.
123106
124107 Args:
125108 endpoint_id: The identifier for the endpoint.
126109 job_id: The identifier for the job.
127110 client: An instance of the RunPodClient to make requests with.
128- api_key: Optional API key for this specific job.
129111 """
130112 self .endpoint_id = endpoint_id
131113 self .job_id = job_id
132114 self .rp_client = client
133- self .api_key = api_key # Store job-specific API key
134115
135116 self .job_status = None
136117 self .job_output = None
137118
138119 def _fetch_job (self , source : str = "status" ) -> Dict [str , Any ]:
139120 """Returns the raw json of the status, raises an exception if invalid"""
140121 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 )
143123
144124 if is_completed (job_state ["status" ]):
145125 self .job_status = job_state ["status" ]
@@ -197,8 +177,7 @@ def cancel(self, timeout: int = 3) -> Any:
197177 return self .rp_client .post (
198178 f"{ self .endpoint_id } /cancel/{ self .job_id } " ,
199179 data = None ,
200- timeout = timeout ,
201- api_key = self .api_key
180+ timeout = timeout
202181 )
203182
204183
@@ -225,13 +204,12 @@ def __init__(self, endpoint_id: str, api_key: Optional[str] = None):
225204 self .endpoint_id = endpoint_id
226205 self .rp_client = RunPodClient (api_key = api_key )
227206
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 :
229208 """
230209 Run the endpoint with the given input.
231210
232211 Args:
233212 request_input: The input to pass into the endpoint.
234- api_key: Optional API key to use for this specific request.
235213
236214 Returns:
237215 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
241219
242220 job_request = self .rp_client .post (
243221 f"{ self .endpoint_id } /run" ,
244- request_input ,
245- api_key = api_key
222+ request_input
246223 )
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 )
248225
249226 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
252228 ) -> Dict [str , Any ]:
253229 """
254230 Run the endpoint with the given input synchronously.
255231
256232 Args:
257233 request_input: The input to pass into the endpoint.
258234 timeout: Maximum time to wait for the job to complete.
259- api_key: Optional API key to use for this specific request.
260235 """
261236 if not request_input .get ("input" ):
262237 request_input = {"input" : request_input }
263238
264239 job_request = self .rp_client .post (
265240 f"{ self .endpoint_id } /runsync" ,
266241 request_input ,
267- timeout = timeout ,
268- api_key = api_key
242+ timeout = timeout
269243 )
270244
271245 if job_request ["status" ] in FINAL_STATES :
272246 return job_request .get ("output" , None )
273247
274248 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
276250 ).output (timeout = timeout )
277251
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 ]:
279253 """
280254 Check the health of the endpoint (number/state of workers, number/state of requests).
281255
282256 Args:
283257 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.
285258 """
286259 return self .rp_client .get (
287260 f"{ self .endpoint_id } /health" ,
288- timeout = timeout ,
289- api_key = api_key
261+ timeout = timeout
290262 )
291263
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 ]:
293265 """
294266 Purges the endpoint's job queue and returns the result of the purge request.
295267
296268 Args:
297269 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.
299270 """
300271 return self .rp_client .post (
301272 f"{ self .endpoint_id } /purge-queue" ,
302273 data = None ,
303- timeout = timeout ,
304- api_key = api_key
274+ timeout = timeout
305275 )
0 commit comments