This tutorial will explain how to set up your API key when using the
Nixtla SDK. To create an Api Key
go to your
Dashboard.
There are different ways to set up your API key. We provide some examples below. A scematic is given below.
This approach is straightforward and best for quick tests or scripts that won’t be shared.
API Keys
of your Nixtla
dashboard.NixtlaClient
with your API key:Important
This approach is considered unsecure, as your API key will be part of your source code.
NIXTLA_API_KEY
. This can be done (a) temporarily for a session
or (b) permanently, depending on your preference.NixtlaClient
class, the SDK will automatically look for the NIXTLA_API_KEY
environment variable and use it to authenticate your requests.Important
The environment variable must be named exactly
NIXTLA_API_KEY
, with all capital letters and no deviations in spelling, for the SDK to recognize it.
This approach is useful if you are working from a terminal, and need a temporary solution.
Open a terminal and use the export
command to set NIXTLA_API_KEY
.
For Windows users, open a Powershell window and use the Set
command to
set NIXTLA_API_KEY
.
.env
fileFor a more persistent solution place your API key in a .env
file
located in the folder of your Python script. In this file, include the
following:
You can now load the environment variable within your Python script. Use
the dotenv
package to load the .env
file and then instantiate the
NIXTLA_API_KEY
class. For example:
This approach is more secure and suitable for applications that will be deployed or shared, as it keeps API keys out of the source code.
Important
Remember, your API key is like a password - keep it secret, keep it safe!
You can always find your API key in the API Keys
section of your
dashboard. To check the status of your API key, use the
validate_api_key
method of the
NixtlaClient
class. This method will return True
if the API key is valid and
False
otherwise.
You don’t need to validate your API key every time you use TimeGPT
.
This function is provided for your convenience to ensure its validity.
For full access to TimeGPT
’s functionalities, in addition to a valid
API key, you also need sufficient credits in your account. You can check
your credits in the Usage
section of your
dashboard.