# POST /api/v1/inventory/production/runs/{run_id}/calculate

> What-if calculation

- **Tag:** inventory:production
- **Operation ID:** `calculate_run_api_v1_inventory_production_runs__run_id__calculate_post`

## Description

Recalculate costs without persisting.  Override total_units and/or unit_sale_price.

## Authentication

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

## Parameters

- `run_id` (path, string, required)

## Request body

Schema: `RunCalculateRequest`

- `total_units` (integer)
- `unit_sale_price` (integer)

## Responses

### 201 — Successful Response

Schema: `CostBreakdown`

- `materials_by_category` (object) — Cost per category in cents.
- `processing_steps_by_type` (object) — Cost per step_type in cents.
- `material_line_items` (array · object)
- `step_line_items` (array · object)
- `total_cost` (integer)
- `cost_per_unit` (integer)
- `sales_potential` (integer)
- `gross_profit` (integer)
- `gross_margin_pct` (number)
- `total_weight` (number)
- `total_weight_unit` (string)

### 404 — Not Found - Resource does not exist

### 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/inventory/production/runs/{run_id}/calculate' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "total_units": 0,
  "unit_sale_price": 0
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/inventory/production/runs/{run_id}/calculate', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "total_units": 0,
  "unit_sale_price": 0
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {
  "total_units": 0,
  "unit_sale_price": 0
}

response = httpx.post("https://api.ondayzero.com/api/v1/inventory/production/runs/{run_id}/calculate", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/inventory-production/calculate-run
- OpenAPI slice: https://www.ondayzero.com/docs/reference/inventory-production/calculate-run/openapi.json
- Other endpoints in **inventory:production**: https://www.ondayzero.com/docs/reference/inventory-production
