nixtla icon indicating copy to clipboard operation
nixtla copied to clipboard

ApiError: status_code: 401

Open Mzakery opened this issue 7 months ago • 6 comments

Hello I also got the 401 error. I registered on the site and received the token, but unfortunately I still get the 401 error. please guide me

ApiError: status_code: 401, body: {'data': None, 'message': 'Invalid API key', 'details': 'Key not found', 'code': 'A12', 'requestID': 'E7F2BBTB2P', 'support': 'If you have questions or need support, please email [email protected]'}

Mzakery avatar Dec 08 '23 21:12 Mzakery

hi @Mzakery. thanks for using nixtla. could you provide an example or screenshot of how you call the sdk?

AzulGarza avatar Dec 09 '23 07:12 AzulGarza

I registered on the website https://www.nixtla.io/ and received the token from the Get token section and defined it as a environment variable. I want to run the codes of this section

https://github.com/Nixtla/nixtla/blob/main/nbs/docs/getting-started/1_getting_started_short.ipynb

that in part timegpt.validate_token() And timegpt_fcst_df = timegpt.forecast(df=df, h=12, freq='MS', time_col='timestamp', target_col='value') timegpt_fcst_df.head()

It gives error 401

ApiError: status_code: 401, body: { 'data': None, 'message': 'Invalid API Key', 'details': 'Key not found', 'code': 'A12', 'requestID': 'E7F2BBTB2P' , 'support': 'If you have any questions or need support, please email [email protected]'}

Mzakery avatar Dec 09 '23 12:12 Mzakery

Codes run in colab with version 3.10

Mzakery avatar Dec 09 '23 12:12 Mzakery

load_dotenv('c.env') True TIMEGPT_TOKEN=os.environ.get("TIMEGPT_TOKEN") TIMEGPT_TOKEN '... token...' timegpt = TimeGPT( # defaults to os.environ.get("TIMEGPT_TOKEN") token = 'TIMEGPT_TOKEN') timegpt.validate_token()

ApiError Traceback (most recent call last) in <cell line: 1>() ----> 1 timegpt.validate_token()

1 frames /usr/local/lib/python3.10/dist-packages/nixtlats/timegpt.py in validate_token(self, log) 725 def validate_token(self, log: bool = True) -> bool: 726 """Returns True if your token is valid.""" --> 727 validation = self.client.validate_token() 728 valid = False 729 if "message" in validation:

/usr/local/lib/python3.10/dist-packages/nixtlats/client.py in validate_token(self) 419 except JSONDecodeError: 420 raise ApiError(status_code=_response.status_code, body=_response.text) --> 421 raise ApiError(status_code=_response.status_code, body=_response_json) 422 423 def validate_token_front(self) -> typing.Any:

ApiError: status_code: 401, body: {'data': None, 'message': 'Invalid API key', 'details': 'Key not found', 'code': 'A12', 'requestID': 'RQVKJPWP2N', 'support': 'If you have questions or need support, please email [email protected]'}

Mzakery avatar Dec 10 '23 11:12 Mzakery

hey @Mzakery!

Thanks for using TimeGPT.

I think the problem is related to this line:

timegpt = TimeGPT(
# defaults to os.environ.get("TIMEGPT_TOKEN")
token = 'TIMEGPT_TOKEN')

There, you're passing the string 'TIMEGPT_TOKEN' as a token. Instead, since you're loading your env variables, just timegpt = TimeGPT() should work. Alternatively, simply removing the quotes to access the TIMEGPT_TOKEN object should work as well,

timegpt = TimeGPT(token=TIMEGPT_TOKEN)

AzulGarza avatar Dec 11 '23 21:12 AzulGarza

Thanks But it gives error 429 in this part.

timegpt.validate_token()

ApiError Traceback (most recent call last) in <cell line: 1>() ----> 1 timegpt.validate_token()

1 frames /usr/local/lib/python3.10/dist-packages/nixtlats/client.py in validate_token(self) 419 except JSONDecodeError: 420 raise ApiError(status_code=_response.status_code, body=_response.text) --> 421 raise ApiError(status_code=_response.status_code, body=_response_json) 422 423 def validate_token_front(self) -> typing.Any:

ApiError: status_code: 429, body: {'data': None, 'message': 'Too many requests', 'details': 'You have reached your request limit, email [email protected] to continue using the API', 'code': 'A20', 'requestID': '868HB5JZ5T', 'support': 'If you have questions or need support, please email [email protected]'}

Mzakery avatar Dec 12 '23 07:12 Mzakery