44
55from .exceptions import FastLabelException , FastLabelInvalidException
66
7- FASTLABEL_ENDPOINT = "https://api.fastlabel.ai/v1/"
8-
97
108class Api :
119
10+ base_url = "https://api.fastlabel.ai/v1/"
1211 access_token = None
1312
1413 def __init__ (self ):
14+ if os .environ .get ("FASTLABEL_API_URL" ):
15+ self .base_url = os .environ .get ("FASTLABEL_API_URL" )
1516 if not os .environ .get ("FASTLABEL_ACCESS_TOKEN" ):
1617 raise ValueError ("FASTLABEL_ACCESS_TOKEN is not configured." )
1718 self .access_token = "Bearer " + os .environ .get ("FASTLABEL_ACCESS_TOKEN" )
@@ -27,7 +28,7 @@ def get_request(self, endpoint: str, params=None) -> dict:
2728 "Content-Type" : "application/json" ,
2829 "Authorization" : self .access_token ,
2930 }
30- r = requests .get (FASTLABEL_ENDPOINT + endpoint , headers = headers , params = params )
31+ r = requests .get (self . base_url + endpoint , headers = headers , params = params )
3132
3233 if r .status_code == 200 :
3334 return r .json ()
@@ -52,9 +53,7 @@ def delete_request(self, endpoint: str, params=None) -> dict:
5253 "Content-Type" : "application/json" ,
5354 "Authorization" : self .access_token ,
5455 }
55- r = requests .delete (
56- FASTLABEL_ENDPOINT + endpoint , headers = headers , params = params
57- )
56+ r = requests .delete (self .base_url + endpoint , headers = headers , params = params )
5857
5958 if r .status_code != 204 :
6059 try :
@@ -77,10 +76,12 @@ def post_request(self, endpoint, payload=None):
7776 "Content-Type" : "application/json" ,
7877 "Authorization" : self .access_token ,
7978 }
80- r = requests .post (FASTLABEL_ENDPOINT + endpoint , json = payload , headers = headers )
79+ r = requests .post (self . base_url + endpoint , json = payload , headers = headers )
8180
8281 if r .status_code == 200 :
8382 return r .json ()
83+ elif r .status_code == 204 :
84+ return
8485 else :
8586 try :
8687 error = r .json ()["message" ]
@@ -102,7 +103,7 @@ def put_request(self, endpoint, payload=None):
102103 "Content-Type" : "application/json" ,
103104 "Authorization" : self .access_token ,
104105 }
105- r = requests .put (FASTLABEL_ENDPOINT + endpoint , json = payload , headers = headers )
106+ r = requests .put (self . base_url + endpoint , json = payload , headers = headers )
106107
107108 if r .status_code == 200 :
108109 return r .json ()
0 commit comments