Time series forecasting has traditionally been the domain of statistical models and specialized neural architectures, but large language models are increasingly being repurposed for the task. By encoding numerical sequences as text tokens or structured prompts, developers can leverage the reasoning abilities of modern LLMs for trend extrapolation, anomaly detection, and seasonal forecasting without maintaining a separate forecasting stack. The challenge is that time series data consumes significant context window length, which makes inference cost unpredictable on token-based platforms. This is where inference pricing structure becomes a critical architectural decision, and Oxlo.ai offers a request-based alternative that removes the penalty for long historical windows.
Why LLMs for Time Series?
Statistical methods such as ARIMA or Prophet require domain knowledge, manual feature engineering, and separate infrastructure. Deep-learning approaches like TFT or N-BEATS deliver strong accuracy but demand dedicated training pipelines. LLMs introduce a third path: zero-shot and few-shot forecasting through prompt engineering. A model with strong reasoning capabilities can infer seasonality, trend, and noise directly from a textual or tabular prompt, then extrapolate future values without gradient updates.
This approach is particularly useful when forecasting is one step inside a larger agentic or analytical workflow. Instead of orchestrating a microservice for statsmodels and another for text generation, a single API call to a general-purpose or reasoning model can handle both narrative analysis and numeric prediction. Models such as DeepSeek R1 671B MoE, Kimi K2 Thinking, and Qwen 3 32B on Oxlo.ai can process these prompts with no cold starts, letting you move from idea to inference in seconds.
How LLM Time Series Forecasting Works
There are three common patterns for feeding series data into an LLM.
- Direct tokenization. You serialize the sequence as a comma-separated or newline-separated string and append the forecasting instruction. The model attends to the raw digits and punctuation.
- Patching or binning. You group contiguous timesteps into patches, compute a statistical summary per patch, and prompt the model to predict the next patch. This reduces sequence length at the cost of granularity.
- Textual encoding. You translate values into natural language descriptions, such as daily sales rose from 120 to 145 units. This format trades token efficiency for semantic alignment with the pre-training corpus.
Regardless of encoding, the output must be constrained. Fully OpenAI SDK compatible providers such as Oxlo.ai support JSON mode and function calling, so you can force the model to return a structured object like {"forecast": [14.2, 15.1, 13.8]} instead of free text. Multi-turn conversations are also useful: the first turn establishes the schema, and the second turn supplies the series.
Model Selection on Oxlo.ai
Because forecasting is a reasoning task, model choice should match the complexity of the temporal patterns and the length of the historical window. Oxlo.ai hosts 45+ open-source and proprietary models across 7 categories, all accessible through a single OpenAI-compatible endpoint.
- General-purpose reasoning. Llama 3.3 70B is a reliable default for standard univariate and multivariate prompts.
- Deep reasoning. DeepSeek R1 671B MoE and Kimi K2 Thinking excel at chain-of-thought analysis, which helps when the prompt includes covariates or conditional logic.
- Long-context series. DeepSeek V4 Flash supports a 1 million token context, and Kimi K2.6 handles 131K tokens with advanced reasoning and vision. These are useful when you need years of high-frequency data in a single prompt.
- Multilingual or multi-format inputs. Qwen 3 32B and GLM 5 handle agentic workflows and non-English metadata that often accompany global operational data.
Since Oxlo.ai carries no cold starts on popular models, you can benchmark several architectures against a holdout set without waiting for container spin-up.
Implementation Example
The following snippet uses the OpenAI Python SDK with an Oxlo.ai API key. It formats a short univariate series as a comma-separated string and requests a JSON array of future values.
import os
import openai
client = openai.OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.getenv("OXLO_API_KEY")
)
history = "12.4, 13.1, 11.8, 14.0, 15.2, 14.8, 16.1"
prompt = (
"Forecast the next 3 values for this daily energy consumption series. "
"Return only a JSON object with a 'forecast' key containing a list of floats.\n\n"
f"History: {history}\n\nForecast:"
)
response = client.chat.completions.create(
model="llama-3.3-70b", # verify exact model ID in the Oxlo.ai catalog
messages=[{"role": "user", "content": prompt}],
response_format={"type": "json_object"},
max_tokens=100
)
print(response.choices[0].message.content)
For multivariate scenarios, extend the prompt with column names or covariates. You can also enable streaming responses if the model produces a long explanatory preamble before the JSON block.
Context Length and Cost Engineering
Time series workloads are uniquely sensitive to input length. A single year of hourly data contains more than eight thousand observations. When each digit, decimal point, and delimiter becomes a token, prompt length balloons quickly. On token-based providers such as Together AI, Fireworks AI, OpenRouter, Replicate, or Anyscale, this means costs scale linearly with the history you provide.
Oxlo.ai uses request-based pricing: one flat cost per API request regardless of prompt length. For long-context and agentic workloads, this model can be 10-100x cheaper than token-based alternatives because you are not charged for every historical token you include. If you are running rolling forecasts on high-frequency data, or if you are concatenating multiple series with rich metadata into a single prompt, the savings compound. See https://oxlo.ai/pricing for plan details.
This pricing structure also makes large context windows economically practical. You can send a full year of data to DeepSeek V4 Flash or Kimi K2.6 without forecasting cost per token, paying only for the request itself.
Evaluation and Prompt Engineering
LLM forecasts should be evaluated with the same rigor as traditional models. Maintain a chronological train-test split, and report scale-independent metrics such as MAE, RMSE, or MASE. Because LLM outputs are stochastic, run multiple samples and report mean error and variance.
Prompt design is the dominant hyperparameter. Effective tactics include:
- Few-shot examples. Provide two or three completed input-output pairs before the target series.
- Seasonality hints. Explicitly note weekly, monthly, or annual cycles in the prompt text.
- Differencing guidance. Ask the model to forecast differences or log-returns if the series is non-stationary.
- Tool use. Use function calling to force a numeric schema and skip brittle regex parsing.
Oxlo.ai supports function calling, JSON mode, and streaming, so you can enforce structure and consume results incrementally without extra client logic.
Conclusion
LLM-based time series forecasting is not a universal replacement for specialized statistical or deep-learning models, but it is a pragmatic choice when you already operate an LLM stack and want to avoid fragmented infrastructure. The approach shines in agentic pipelines, rapid prototyping, and scenarios where explanatory reasoning is as valuable as the point prediction.
Oxlo.ai is a strong fit for this workload. With 45+ models, fully OpenAI SDK compatibility, no cold starts, and request-based pricing that decouples cost from input length, you can experiment with long historical windows and complex prompts without the token-meter running. Point your existing SDK to https://api.oxlo.ai/v1, select a reasoning model such as DeepSeek R1 671B MoE or Kimi K2.6, and start forecasting.
Top comments (0)