# POST /api/v1/budgets/forecast

> Generate forecast

- **Tag:** budgets
- **Operation ID:** `generate_forecast_api_v1_budgets_forecast_post`

## Description

Generate a financial forecast based on historical data.

## Authentication

Bearer token in `Authorization` header.
Required header: `x-business-id: <business uuid>`.

## Request body

Schema: `GenerateForecastRequest`

- `method` (ForecastMethodEnum) → `ForecastMethodEnum` — Forecasting method.
- `lookback_months` (integer) — Historical months to analyze.
- `forecast_months` (integer) — Months to forecast.
- `growth_rate_percent` (integer) — Growth rate adjustment.
- `use_seasonality` (boolean) — Apply seasonal adjustments.
- `include_cash_flow` (boolean) — Include cash flow projections.

## Responses

### 201 — Successful Response

Schema: `ForecastResponse`

- `business_id` (string · required) — Business UUID.
- `business_name` (string · required) — Business name.
- `forecast_start` (string · date · required) — Forecast period start.
- `forecast_end` (string · date · required) — Forecast period end.
- `method` (ForecastMethodEnum · required) → `ForecastMethodEnum` — Method used.
- `generated_at` (string · date-time · required) — Generation timestamp.
- `revenue_items` (array · ForecastLineItem) → `ForecastLineItem` — Revenue account forecasts.
  - `ledger_id` (string · required) — Ledger UUID.
  - `ledger_name` (string · required) — Ledger name.
  - `ledger_type` (string · required) — Ledger type.
  - `historical_average` (integer · required) — Average historical monthly amount.
  - `historical_trend` (number · required) — Monthly trend (slope).
  - `periods` (array · ForecastPeriod) — Forecasted periods.
- `total_forecasted_revenue` (integer · required) — Total forecasted revenue.
- `expense_items` (array · ForecastLineItem) → `ForecastLineItem` — Expense account forecasts.
  - `ledger_id` (string · required) — Ledger UUID.
  - `ledger_name` (string · required) — Ledger name.
  - `ledger_type` (string · required) — Ledger type.
  - `historical_average` (integer · required) — Average historical monthly amount.
  - `historical_trend` (number · required) — Monthly trend (slope).
  - `periods` (array · ForecastPeriod) — Forecasted periods.
- `total_forecasted_expenses` (integer · required) — Total forecasted expenses.
- `forecasted_net_income` (integer · required) — Forecasted net income.
- `cash_flow_forecast` (array · ForecastPeriod) → `ForecastPeriod` — Monthly cash flow projections.
  - `period_date` (string · date · required) — First day of the forecasted month.
  - `forecasted_amount` (integer · required) — Forecasted amount in cents.
  - `confidence_low` (integer) — Lower confidence bound.
  - `confidence_high` (integer) — Upper confidence bound.
  - `is_historical` (boolean) — True if this is actual historical data.
- `projected_ending_cash` (integer · required) — Projected cash at forecast end.

### 400 — Bad Request - Invalid input

### 401 — Unauthorized - Authentication required

### 403 — Forbidden - Insufficient permissions

### 422 — Validation Error

Schema: `HTTPValidationError`

- `detail` (array · ValidationError) → `ValidationError`
  - `loc` (array · string | integer · required)
  - `msg` (string · required)
  - `type` (string · required)
  - `input` (object)
  - `ctx` (object)

## Code samples

### cURL

```bash
curl -X POST 'https://api.ondayzero.com/api/v1/budgets/forecast' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "method": "string",
  "lookback_months": 0,
  "forecast_months": 0,
  "growth_rate_percent": 0,
  "use_seasonality": false,
  "include_cash_flow": false
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/budgets/forecast', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "method": "string",
  "lookback_months": 0,
  "forecast_months": 0,
  "growth_rate_percent": 0,
  "use_seasonality": false,
  "include_cash_flow": false
}),
});
const data = await response.json();
```

### Python

```python
import httpx

headers = {
    "Authorization": "Bearer dz_your_token",
    "x-business-id": "YOUR_BUSINESS_ID",
}

payload = {
  "method": "string",
  "lookback_months": 0,
  "forecast_months": 0,
  "growth_rate_percent": 0,
  "use_seasonality": false,
  "include_cash_flow": false
}

response = httpx.post("https://api.ondayzero.com/api/v1/budgets/forecast", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/budgets/generate-forecast
- OpenAPI slice: https://www.ondayzero.com/docs/reference/budgets/generate-forecast/openapi.json
- Other endpoints in **budgets**: https://www.ondayzero.com/docs/reference/budgets
