---
title: "Optimize Flowsheet"
method: POST
path: "/api/optimize-flowsheet"
---

# Optimize Flowsheet

`POST /api/optimize-flowsheet`

## Request

- Base URL: `https://biotechdsp-579272663320.europe-west1.run.app`
- URL: `https://biotechdsp-579272663320.europe-west1.run.app/api/optimize-flowsheet`
- Auth: HTTP bearer

Find the best way to run a flowsheet the user has already chosen.

The topology is fixed: no step is added, removed or reordered. Only parameters that
`design_space.py` classifies as tunable are moved, so the search cannot make the process
look cheap by assuming a better resin or membrane than the one being costed.

Returns the optimised parameters per step, ready to write straight back onto the canvas,
together with the baseline they beat and a note on any value that landed on a bound.

## Request body

- OptimizeFlowsheetBody: Request body for parameter optimisation of a flowsheet the user has already chosen. Mirrors SimulateBody's shape (stream + steps carrying their own parameters), so the canvas can post exactly what it would post to simulate, plus the specs to hit.
  - `annual_operating_hours` integer
  - `cooling_water_price_usd_per_m3` number
  - `electricity_price_usd_per_kWh` number
  - `facility_type` string, nullable
  - `feed_flow_max_multiplier` number
  - `feed_flow_min_multiplier` number
  - `feeds` object
  - `hold_baseline_economics` boolean
  - `hold_baseline_production` boolean
  - `hold_baseline_quality` boolean
  - `labor_profile` string
  - `max_evaluations` integer
  - `min_purity` number
  - `min_yield` number
  - `objective` string
  - `optimize_feed_flow` boolean
  - `pareto` boolean
  - `pareto_purity_levels` number[], nullable
  - `product_identity_requested_targets` string[]
  - `product_identity_warnings` string[]
  - `product_selling_price_source` 'default' | 'user_supplied'
  - `product_selling_price_usd_per_kg` number
  - `recycles` RecycleSpec[]
    - `fraction` number, required
    - `from_step` integer, required
    - `outlet` 'light' | 'heavy'
    - `to_step` integer, required
  - `roles` string[]
  - `screen_first` boolean
  - `seed` integer
  - `skip_steps` integer[]
  - `steam_price_usd_per_GJ` number
  - `steps` object[], required
  - `stream` object, required
  - `stream_closure_warnings` string[]
  - `target_products` string[], required
  - `target_provenance` object, nullable
  - `terminal_streams` TerminalStream[], nullable
    - `fraction` number, required
    - `output_index` integer, required
    - `port_id` string, required
    - `sink` 'product' | 'waste' | 'vent', required
    - `step_index` integer, required
    - `target_products` string[]
    - `terminal_id` string, required
  - `wastewater_scope` 'included' | 'excluded_osbl'

## Response `200`

Successful Response

- unknown

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/untangle/apis/untangle-bio-engine-api.md) · [All operations](https://skmtc.dev/untangle/apis/untangle-bio-engine-api/llms.txt) · [OpenAPI document](https://skmtc.dev/untangle/apis/untangle-bio-engine-api/revisions/161714bf261c?raw)
