> ## Documentation Index
> Fetch the complete documentation index at: https://nixtla.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart (TimeGPT-2.1)

> Learn how to use TimeGPT for accurate time series forecasting

## TimeGPT Family - Foundation Models for Time Series Forecasting

TimeGPT is a production-ready generative pretrained transformer for time series forecasting and predictions. It delivers accurate forecasts for retail sales, electricity demand, financial markets, and IoT sensor data with just a few lines of Python code. This quickstart guide will have you making your first forecast in under 5 minutes!

## Set Up TimeGPT for Python Time Series Forecasting

### Step 1: Get an API Key

* [Verify how you get access to Nixtla](https://nixtla.io/docs/introduction/ways_to_get_access.md).
  * Sign in using Google, GitHub, or your email.
  * Navigate to **API Keys** in the menu and select **Create Key**.
  * Your new API key will appear on the screen. Copy this key and save it in a safe place for use later.

![API Keys page in the Nixtla dashboard](https://mintcdn.com/nixtla-enterprise/YkQA62_aA_HFUp6v/images/forecasting/quickstart-api-keys.png?fit=max\&auto=format\&n=YkQA62_aA_HFUp6v\&q=85\&s=e51f6ca3e3279358fc78aad637d8ea0b)

The API Keys page in the Nixtla dashboard

### Step 2: Install Nixtla

Install the Nixtla library in your preferred Python environment:

```bash theme={null}
pip install nixtla
```

### Step 3: Import the Nixtla TimeGPT client

Import the Nixtla client and instantiate it with your API key:

```python theme={null}
from nixtla import NixtlaClient

nixtla_client = NixtlaClient(
    api_key='my_api_key_provided_by_nixtla'
)
```

### Step 4: Verify your API key

Verify the status and validity of your API key:

```python theme={null}
nixtla_client.validate_api_key()
```

```bash theme={null}
True
```

> [!NOTE]
>
> For enhanced security practices, see our guide on
> [Setting Up your API Key](https://nixtla.io/docs/setup/setting_up_your_api_key.md).

## Make Your First Time Series Forecast

We'll demonstrate TimeGPT's forecasting capabilities using the classic `AirPassengers` dataset, a monthly time series showing international airline passengers from 1949 to 1960.

```python theme={null}
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv')
df.head()
```

| | timestamp | value |
| - | - | - |
| 0 | 1949-01-01 | 112 |
| 1 | 1949-02-01 | 118 |
| 2 | 1949-03-01 | 132 |
| 3 | 1949-04-01 | 129 |
| 4 | 1949-05-01 | 121 |

> [!NOTE]
>
> If you are using your own data, here are the data requirements:
>
> * The target variable must not contain missing or non-numeric values.
> * The timestamp column must not contain missing values.
> * Date stamps must form a continuous sequence without gaps for the selected frequency.
> * pandas must be able to parse the timestamp column as datetime objects. ([see Pandas documentation](https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html)).
>
> For more details, visit [Data Requirements](https://nixtla.io/docs/data_requirements/data_requirements.md).

Plot the dataset:

```python theme={null}
nixtla_client.plot(df, time_col='timestamp', target_col='value')
```

![Time Series Plot](https://mintcdn.com/nixtla-enterprise/YkQA62_aA_HFUp6v/images/forecasting/quickstart-air-passengers.png?fit=max\&auto=format\&n=YkQA62_aA_HFUp6v\&q=85\&s=b7385f77e4f008a804438a890cd3be30)

Historical AirPassengers time series data visualization showing monthly passenger trends from 1949 to 1960

The `plot` method automatically displays figures in notebook environments. To save a plot locally:

```python theme={null}
fig = nixtla_client.plot(df, time_col='timestamp', target_col='value')
fig.savefig('plot.png', bbox_inches='tight')
```

## Real-World Forecasting Applications

TimeGPT excels at:

* **Retail forecasting**: Predict product demand and inventory needs
* **Energy forecasting**: Forecast electricity consumption and renewable energy production
* **Financial forecasting**: Project revenue, sales, and market trends
* **IoT predictions**: Anticipate sensor readings and equipment metrics

## Forecast the Next 12 Months

Forecast the next 12 months using the SDK's `forecast` method. By default, this uses the `timegpt-2.1` model:

```python theme={null}
timegpt_fcst_df = nixtla_client.forecast(
    df=df,
    h=12,
    freq='MS',
    time_col='timestamp',
    target_col='value'
)
timegpt_fcst_df.head()
```

Plot the forecast:

```python theme={null}
nixtla_client.plot(df, timegpt_fcst_df, time_col='timestamp', target_col='value')
```

![Forecasted Plot](https://mintcdn.com/nixtla-enterprise/YkQA62_aA_HFUp6v/images/forecasting/quickstart-forecast-12m.png?fit=max\&auto=format\&n=YkQA62_aA_HFUp6v\&q=85\&s=4625fede16dde2e07ace9e10f70a789d)

TimeGPT 12-month forecast for the AirPassengers dataset

## Frequently Asked Questions

### How accurate is TimeGPT for forecasting?

TimeGPT achieves state-of-the-art accuracy across multiple domains including retail, finance, and electricity forecasting with zero-shot learning.

### Can I use TimeGPT with my own time series data?

Yes, TimeGPT works with any time series data in pandas DataFrame format with a timestamp and target value column.

### How long does it take to generate forecasts?

TimeGPT typically generates forecasts in seconds, making it suitable for production environments.

## Next Steps

Now that you've made your first forecast, explore these tutorials to unlock TimeGPT's full capabilities:

* [Improve Accuracy](https://nixtla.io/docs/forecasting/improve_accuracy.md) - Advanced techniques to enhance forecast accuracy
* [Fine-Tuning](https://nixtla.io/docs/forecasting/fine-tuning/steps.md) - Customize TimeGPT for your specific data
* [Exogenous Variables](https://nixtla.io/docs/forecasting/exogenous-variables/numeric_features.md) - Include external variables in forecasts
* [Uncertainty Quantification](https://nixtla.io/docs/forecasting/probabilistic/introduction.md) - Generate prediction intervals and quantile forecasts
* [Cross-Validation](https://nixtla.io/docs/forecasting/evaluation/cross_validation.md) - Assess forecast performance
* [Forecasting at Scale](https://nixtla.io/docs/forecasting/forecasting-at-scale/computing_at_scale.md) - Process thousands of time series
* [Anomaly Detection](https://nixtla.io/docs/anomaly_detection/historical_anomaly_detection.md) - Identify outliers in your data
