WeltPython SDK
Products: switch from Welt to another product
Open console

GuidesForecast time series with Chronos-2 and Timestral

Forecast time series with Chronos-2 and Timestral

For historical walk-forward accuracy and optional final forecasts, see Backtest a time series.

Forecast one series or a whole panel with Chronos-2. Add several targets, drivers you only observe in the past, and drivers you know ahead of time. You get a median and native quantiles for every series, target and future step. Timestral, listed after Chronos-2, forecasts one series per request through the same calls; see forecast with Timestral.

You'll need

  • welt-client>=0.14.0: pip install "welt-client>=0.14".
  • A Welt workspace with credits. Every forecast call is one priced request; see what a forecast costs.
  • A Welt server that offers the forecasting task for chronos-2. Older servers keep only the univariate API.

The steps build one script, forecast_sales.py. Run them in order in one Python session: each step reuses the data and model from the step before. The sales are simulated so the page runs anywhere; use your own history for real forecasts.

Prefer a notebook?

The forecasting notebook builds a realistic retail panel, holds out the last four weeks, and scores Chronos-2 with and without covariates against a seasonal-naive baseline, with MASE and interval coverage. The same tutorial runs as a script: forecasting_covariates.py.

Forecast one series#

Make a table with a time column and a value column, fit, then ask for a horizon.

forecast_sales.py
import numpy as np
import pandas as pd
from welt import Forecast

# A year of simulated daily sales for three stores. Use your own history.
rng = np.random.default_rng(0)
days = pd.date_range("2025-01-01", periods=365, freq="D")
stores = {"north": 120, "south": 90, "east": 60}
panel = pd.concat([pd.DataFrame({
    "date": days,
    "store": store,
    "sales": level * (1 + 0.3 * (days.dayofweek >= 5)) + rng.normal(0, 5, len(days)),
}) for store, level in stores.items()], ignore_index=True)

north = panel[panel["store"] == "north"]
model = Forecast(model="chronos-2").fit(north, time="date", target=["sales"])
result = model.forecast(14)
print(result.to_frame().head())
  • fit copies your columns, checks them locally and reads the model's published limits. It uploads nothing and starts no job: Chronos-2 is zero-shot, so the history is the context for each forecast.
  • forecast(14) sends one request for the 14 days after the last row and waits for the result.
  • Pass target as a list. With no id and no covariates, a single string target selects the older univariate API, which needs timezone-aware times and complete values.
  • Columns you don't name, like store here, are not sent.

Forecast a panel#

Name the column that identifies each series with id. Every store becomes its own series, and all of them go in one request.

forecast_sales.py
model = Forecast(model="chronos-2").fit(panel, time="date", id="store", target=["sales"])
result = model.forecast(14)
frame = result.to_frame()
print(frame.groupby("id")["median"].mean())
  • Rows can come in any order. Each (id, time) pair must appear once.
  • Series can differ in length and start date, but they share one frequency. Each series' forecast starts one step after its own last row.
  • IDs are strings or integers. Results return them as strings.
  • Already uploaded the history? Pass its dataset ID instead of a DataFrame: fit("ds_…", time="date", id="store", target=["sales"]). See dataset histories for how to upload it.

Forecast several targets#

Pass more than one target. Chronos-2 forecasts a series' targets jointly, so related targets can inform each other.

forecast_sales.py
# Visits move with sales; forecast both together.
panel["visits"] = (3 * panel["sales"] + rng.normal(0, 15, len(panel))).round()

model = Forecast(model="chronos-2").fit(
    panel, time="date", id="store", target=["sales", "visits"])
result = model.forecast(14)
print(result.to_frame().groupby(["id", "target"]).size())  # 14 rows per store and target

The result has one entry per series and target: series in the order their IDs first appear, then targets in the order you listed them.

Add covariates#

Covariates are drivers the model reads but doesn't forecast. Tell Welt when you know each one:

  • Past covariates are observed only up to now, like temperature or footfall. They appear in the history only.
  • Future covariates are known ahead, like planned promotions, holidays or prices you set. They appear in the history and in a separate future table.
  • Categorical names the covariates whose cells are labels (strings or integers) rather than amounts.

The same arguments work with model="chronos-2", "timestral-209m" and "timestral-28m". Start with one series and target=["sales"] to use the same example across all three models; Chronos-2 also accepts panels within its published envelopes. Timestral accepts one series per request and needs one target when any covariate is categorical. From SDK 0.14.2, fit checks the model's categorical/ multiple-target restriction locally, and forecast(cross_learning=True) checks its cross-learning restriction before submitting a job. SDK 0.14.0 and 0.14.1 receive the same unsupported_capability error from the server.

The downloadable covariate script accepts the same model choices. To run one simulated store with Timestral:

sh
python forecasting_covariates.py --model timestral-28m --store berlin
# Or use --model timestral-209m, or --model chronos-2.

This sends one priced forecast request. The script requires an explicit store for Timestral before making any request; it does not fan out into multiple paid calls.

forecast_sales.py
def holidays(dates):
    """Public holidays are on the calendar long before they happen."""
    return np.where(dates.dt.strftime("%m-%d").isin(["01-01", "05-01", "12-25", "12-26"]),
                    "holiday", "regular")

panel["promo"] = (panel["date"].dt.dayofweek == 4).astype(int)  # planned Friday promotions
panel["holiday"] = holidays(panel["date"])
panel["temperature"] = (12 + 9 * np.sin(2 * np.pi * (panel["date"].dt.dayofyear - 110) / 365)
                        + rng.normal(0, 2, len(panel)))  # known only once measured

model = Forecast(model="chronos-2").fit(
    panel, time="date", id="store", target=["sales", "visits"],
    past_covariates=["temperature"],
    future_covariates=["promo", "holiday"],
    categorical=["holiday"])

Then give the known values for the forecast days in a future table, and pass it to forecast:

forecast_sales.py
# The next 14 days for every store, with the values you already know.
ahead = pd.DataFrame({"date": pd.date_range("2026-01-01", periods=14, freq="D")})
future = pd.concat([ahead.assign(store=store) for store in stores], ignore_index=True)
future["promo"] = (future["date"].dt.dayofweek == 4).astype(int)
future["holiday"] = holidays(future["date"])

result = model.forecast(14, future=future)
  • The future table has exactly the time column, the id column and every future covariate: no targets, no past covariates.
  • It has exactly horizon rows for each series, at the steps right after that series' last row. The SDK checks this before sending anything.
  • Future covariates must be complete, in the history and the future table.
  • Chronos-2 encodes categories itself. A category that first appears in the future table is allowed; the native encoder handles it.

Read quantiles and the table#

Ask for the quantile levels you need, then read the long table or each series.

forecast_sales.py
result = model.forecast(14, future=future, quantile_levels=[0.05, 0.1, 0.5, 0.9, 0.95])
frame = result.to_frame()
print(frame.columns.tolist())
# ['id', 'target', 'timestamp', 'median', 'q_0.05', 'q_0.1', 'q_0.5', 'q_0.9', 'q_0.95']
print("Sorted steps:", result.rearranged_steps)

for series in result.series:
    print(series.id, series.target, series.context_length, series.predictions[:3])
  • Levels are any increasing subset of the 21 native levels: 0.01, 0.05, 0.10, 0.15, …, 0.95, 0.99. Model metadata publishes them as quantile_levels. The default is [0.1, 0.5, 0.9].
  • median is the native 0.5 quantile. It is always returned, even when you don't request 0.5.
  • to_frame() has one row per series, target and step. timestamp is UTC.
  • result.series holds one ForecastSeries per series and target, with id, target, context_length, timestamps, predictions and quantiles. For one series and one target, result.predictions, result.quantiles and result.timestamps read it directly.

Intervals are not calibrated

Every result reports calibrated_intervals: false. The band from q_0.1 to q_0.9 is the model's estimate, not a promise that 80% of future values fall inside it. Measure coverage on a holdout of your own data, as the notebook does.

When native quantiles cross, Welt sorts them and tells you

Chronos-2 can return quantiles out of order at a step, for example a 0.1 value above the 0.5 value. Welt then sorts that step's 21 native values (monotone rearrangement) and takes your levels and the median from the sorted values. result.rearranged_steps counts the (series, target, step) triples it sorted. When it is 0, every value is exactly what the model returned. A non-finite native value fails the job instead.

Share information across series#

By default each series is forecast on its own. Set cross_learning=True to let the series in one request inform each other.

forecast_sales.py
shared = model.forecast(14, future=future, cross_learning=True)
print(shared.cross_learning)  # True
  • With cross_learning=False, a series' forecast is the one you would get by sending that series alone. Welt checks this when it qualifies the model.
  • With cross_learning=True, forecasts depend on which series you send together. It can help with many short, related series. Keep the panel fixed when you compare results.
  • It's priced the same. This call is a second request.

Check the limits#

Limits come from the model's published metadata. Read them before you send a large panel:

forecast_sales.py
from welt import Client

client = Client()
chronos = client.model("chronos-2")
print("Minimum rows per series:", chronos["min_context"])
for corner in chronos["forecast_envelopes"]:
    print(corner)  # max_context, max_variates, max_series, max_horizon

Each envelope is a measured corner. A request fits when one corner covers it on all four axes at once:

At release, Chronos-2 publishes these seven measured corners, and every series needs at least 16 rows (min_context):

Context (rows) Variates Series Horizon
8,000 50 1 1,024
8,000 5 8 1,024
4,000 10 8 1,024
2,000 20 8 1,024
2,000 5 32 256
1,000 50 8 256
512 20 32 256

Step 4's panel (365 rows × 5 variates × 3 series × 14 steps) fits the 2,000 × 5 × 32 × 256 corner, for example.

What a forecast costs#

A forecast is priced in tokens, at the same rate as tabular prediction: 50 credits per million tokens, rounded up, with a 5-credit minimum per request.

tokens = Σ over series (history rows + horizon) × (targets + covariates)

forecast_sales.py
import math

horizon, variates = 14, 2 + 1 + 2  # targets + past covariates + future covariates
tokens = sum((len(rows) + horizon) * variates for _, rows in panel.groupby("store"))
print(tokens, "tokens")  # 3 × (365 + 14) × 5 = 5,685
print(max(5, math.ceil(tokens * 50 / 1_000_000)), "credits")  # under the minimum, so 5

Prepare your data#

Welt forecasts the table you send. It doesn't fill, resample or truncate anything.

forecast_sales.py
gappy = panel.copy()
gappy.loc[gappy.index[100], "sales"] = np.nan  # a missed reading stays missing
gappy_model = Forecast(model="chronos-2").fit(
    gappy, time="date", id="store", target=["sales"], past_covariates=["temperature"])

Welt infers the frequency when every series has one constant spacing. Pass frequency= to state it:

forecast_sales.py
daily = Forecast(model="chronos-2").fit(
    panel, time="date", id="store", target=["sales"], frequency="D")
print(daily.frequency_)  # {'unit': 'day', 'every': 1}

Large tables and dataset histories#

The SDK sends DataFrames inline and never uploads them for you. A request body above 10 MiB (welt.forecast.MAX_REQUEST_BYTES) is refused with InvalidInputError (workload_limit) before anything is sent. Upload such a table once, then pass its dataset ID to fit, and to forecast(future=...) if the future table is large too: fit("ds_…", time="date", id="store", target=["sales"]).

Handle errors#

Most problems are caught before anything is sent:

forecast_sales.py
from welt import InvalidInputError

try:
    model.forecast(100_000, future=future)
except InvalidInputError as error:
    print(error.code)  # workload_limit: no published corner admits this horizon
Error When What to do
ValueError A local check failed: a gap, a repeated time, a missing future value, wrong future rows. Fix the table. Nothing was sent.
InvalidInputError, code workload_limit No published corner admits the request, a series is shorter than min_context, or the request body is above 10 MiB. Shorten the history, use fewer variates or series, or ask for a shorter horizon. For a large table, upload it and pass its dataset ID.
InvalidInputError, code invalid_input The server refused the request. Read the message. It never repeats your cell values.
InvalidInputError, code unsupported_capability The server has no forecasting task, but you asked for a panel, covariates, a dataset history, a calendar frequency or forecast(). Or the model doesn't offer what you asked for: a panel, cross_learning=True, or categorical covariates with several targets on Timestral. Use the univariate API, or a current server. For Timestral, send one request per series, with cross_learning=False, and one target when you use categorical covariates.
ConflictError, code model_version_mismatch or configuration_version_mismatch The model changed after your fit. Fit again.
ConflictError, code idempotency_conflict You reused a replay key with a different request. Use a new key.
JobTimeoutError Your local wait ended. Reconnect. The forecast keeps running.
ExecutionError The forecast job failed. Retry later, or contact support with the job ID.
InvalidForecastResultError The result failed the SDK's checks. Report it. Nothing was repaired.

InvalidInputError is also a ValueError, so catch it first. Billing refusals such as insufficient_credits are described in wait and recover.

Submit now, collect later#

submit_forecast returns a job without waiting. Keep its ID, then wait, or reconnect from another session.

forecast_sales.py
from welt import JobTimeoutError

job = model.submit_forecast(14, future=future, idempotency_key="sales-forecast-2026-01-01")
print("Keep this job ID:", job.id)
try:
    result = job.result(timeout=60)
except JobTimeoutError:
    print("Still running. Reconnect later with the job ID.")
finally:
    job.close()

client = Client()
with client.forecast_job(job.id) as reopened:
    result = reopened.result(timeout=600)
print(result.to_frame().shape)

Delete a forecast#

Forecast inputs and results stay private in your workspace until you delete them:

Backtest and reconcile in ergodic

Use Chronos-2 inside ergodic's backtest and reconcile: Forecast with Welt's Chronos-2.

Forecast with Timestral#

Timestral is Mistral AI's forecasting model, in two sizes: timestral-209m (primary) and timestral-28m (small). The catalogue lists both after Chronos-2. They use the same Forecast calls, request, result and quantile levels as Chronos-2, with one difference that matters most: one series per request.

forecast_timestral.py
import numpy as np
import pandas as pd
from welt import Client, Forecast

# A year of simulated daily sales for one store, with planned Friday promotions.
rng = np.random.default_rng(0)
days = pd.date_range("2025-01-01", periods=365, freq="D")
north = pd.DataFrame({"date": days,
                      "sales": 120 * (1 + 0.3 * (days.dayofweek >= 5)) + rng.normal(0, 5, len(days))})
north["promo"] = (north["date"].dt.dayofweek == 4).astype(int)

model = Forecast(model="timestral-209m").fit(
    north, time="date", target=["sales"], future_covariates=["promo"])
ahead = pd.DataFrame({"date": pd.date_range("2026-01-01", periods=14, freq="D")})
ahead["promo"] = (ahead["date"].dt.dayofweek == 4).astype(int)
result = model.forecast(14, future=ahead)
print(result.to_frame().head())

client = Client()
timestral = client.model("timestral-209m")
print(timestral["forecast_envelopes"])  # the published single-series corners
print(timestral["attribution"]["notice"])  # 2026 - Mistral AI

A panel is refused before anything is sent. Fit and forecast each series on its own instead:

forecast_timestral.py
from welt import InvalidInputError

stores = pd.concat([north.assign(store="north"),
                    north.assign(store="south", sales=0.75 * north["sales"])], ignore_index=True)
try:
    Forecast(model="timestral-209m").fit(stores, time="date", id="store", target=["sales"])
except InvalidInputError as error:
    print(error.code)  # unsupported_capability: one series per request

forecasts = {}
for store, rows in stores.groupby("store"):
    single = Forecast(model="timestral-209m").fit(
        rows, time="date", id="store", target=["sales"], future_covariates=["promo"])
    forecasts[store] = single.forecast(14, future=ahead.assign(store=store))
print({store: r.series[0].predictions[:3] for store, r in forecasts.items()})

At release, both sizes publish these three measured corners, single series only, and every series needs at least 16 rows (min_context):

Context (rows) Variates Series Horizon
32,000 10 1 1,024
16,000 20 1 1,024
8,000 50 1 1,024

The example above (365 rows × 2 variates × 1 series × 14 steps) fits the first. As for Chronos-2, read the corners from client.model("timestral-209m") rather than copying this table.

Timestral attribution

Timestral weights: 2026 - Mistral AI. Licensed under the Modified MIT licence: Timestral-209M licence, Timestral-28M licence. Model metadata carries the same notice and link as attribution.

Forecast one series with the univariate API#

The univariate API from SDK 0.11 stays supported: predict, predict_quantiles, predict_details and submit_predict, for one series and one target. Use it with an array, a Series with a DatetimeIndex, or a DataFrame with one string target and no id or covariates.

Run it from a terminal

Download the local CSV example and run python forecasting.py history.csv --time timestamp --target value --horizon 24 with your own observations and configured workspace credentials.

Prepare your history#

This example reads a local CSV with timestamp and value columns. Keep later observations aside for evaluation.

python
import pandas as pd
from welt import Forecast

history = pd.read_csv("history.csv")
history["timestamp"] = pd.to_datetime(history["timestamp"])
forecast = Forecast(model="chronos-2", timeout=600)
forecast.fit(history, time="timestamp", target="value")
result = forecast.predict_details(horizon=24)
print(result.to_frame())  # future UTC rows: median, q_0.1, q_0.5, q_0.9
print(result.job_id, result.model_version, result.configuration)

You can also fit an indexed series, or an array with a start time and spacing:

python
forecast.fit(history.set_index("timestamp")["value"])
forecast.fit(history["value"].to_numpy(),
             start="2026-01-01T00:00:00Z", frequency_seconds=3600)

Choose one output for each run#

Each call below is one separate request, starting one step after the last observation. The default levels are (0.1, 0.5, 0.9).

python
points = forecast.predict(24)                         # ndarray (24,): native medians
quantiles = forecast.predict_quantiles(24)            # ndarray (24, 3)
result = forecast.predict_details(24)                 # immutable ForecastResult
frame = result.to_frame()                             # owned UTC-indexed DataFrame
wire = result.to_dict()                               # independent native JSON payload

Call predict_details once and read its predictions, quantiles, quantile_levels and timestamps to get every view from one request. Quantiles are not calibrated intervals. On the univariate model run, crossed quantiles raise InvalidForecastResultError instead of being sorted.

Keep the job and reconnect#

Keep the job ID before you wait. A timeout leaves the job running; reconnect instead of submitting again.

python
from welt import Client, JobTimeoutError

saved_job_id = None
with forecast.submit_predict(24, idempotency_key="my-forecast-20260101") as job:
    print(job.id)  # retain before waiting
    print(job.inspect()["status"])
    try:
        result = job.result(timeout=60)
    except JobTimeoutError:
        saved_job_id = job.id
        # Accepted work remains running; reconnect later. Do not resubmit here.

if saved_job_id is not None:
    client = Client()
    with client.forecast_job(saved_job_id) as job:
        result = job.result(timeout=600)
        print(result.to_frame())

Version guards and privacy#

fit pins the model and configuration versions, your workspace and credential. Every request sends them as guard headers, so a changed model raises a ConflictError before any work starts; fit again to accept it. Client.submit_model_run and Client.submit_forecast accept the same pair as expected_model_version and expected_configuration_version.

Delete with client.delete_forecast(id). Only runs created on servers without the forecasting task are model runs, deleted with client.delete_model_run(id).

Next steps#

Documentation

Search SDK 0.16.5

Search this SDK version by task, method or error.