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.

Step 1: Copy your key from the Nixtla Dashboard.

Step 2: Paste the key into your Python code, for example:

NixtlaClient Initialization with API Key
from nixtla import NixtlaClient

nixtla_client = NixtlaClient(api_key='your_api_key_here')
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.

This method requires setting an environment variable named NIXTLA_API_KEY. The Nixtla SDK automatically detects this environment variable without needing to manually pass it into NixtlaClient.

Validate your API key

Use the validate_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
nixtla_client.validate_api_key()

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.