This tutorial explains how to set up your API key when using the Nixtla SDK. It covers both quick and secure methods to configure your API key directly in code or using environment variables. If you haven’t done so yet, create an API Key in your Nixtla Dashboard.

Diagram of the API Key configuration process
Overview
Why secure your API key?
Your API key grants access to your Nixtla account and should be treated like a password. By securing it, you prevent unauthorized usage and protect your usage credits.
Where to find your key
Your API key can be generated from your Nixtla Dashboard under the API Keys section. Make sure you copy the entire key with no extra spaces.
How to configure your API key
1
Option 1: Copy & Paste into Python
This approach is simple but not secure. Your API key will be stored in your source code, visible to anyone with access to it.
NixtlaClient Initialization with API Key
2
Option 2: Secure Method with Environment Variables
Storing your API key in an environment variable is the recommended approach for security and ease of sharing code without exposing credentials.
NIXTLA_API_KEY
. The Nixtla SDK automatically detects this environment variable without needing to manually pass it into NixtlaClient
.Temporary (Terminal Session)
Temporary (Terminal Session)
- Linux / Mac
- Windows (PowerShell)
Open your terminal and use the
export
command:Setting Environment Variable Temporarily on Linux/Mac
NixtlaClient
without specifying the key:NixtlaClient Initialization Using Environment Variable
Permanent (.env file)
Permanent (.env file)
Create a file named Then, in your Python script, load it with the
.env
in the same directory as your Python script with the following content:.env File Content
dotenv
package:Load Environment Variables with dotenv
Be sure not to commit your
.env
file to public repositories. Your API key grants access to your Nixtla account.Validate your API key
Use thevalidate_api_key
method of NixtlaClient
to confirm that you have correctly configured your API key. This method returns True
if your API key is valid, or False
otherwise:
Validate API Key Method
You do not need to validate your API key before every request. This method is a convenience function. To fully access TimeGPT functionality, ensure you have adequate credits by checking your Nixtla Dashboard.
Summary
You’ve now learned how to configure your Nixtla API key through multiple methods, ranging from the simplest copy-and-paste approach to more secure environment variable setups. Remember to keep your API key confidential to prevent unauthorized usage.