Overview
The Feature Tradeoff API computes the incremental units required to break even when a new product feature increases cost and optionally adds price uplift. It mirrors the logic from the original in-browser calculator and exposes it as a simple HTTP endpoint.
Base URL: https://www.promptbox.cn/api/feature.php
This endpoint accepts a JSON payload, performs the calculation, and returns well-structured JSON with intermediate totals and the required extra units (rounded up) to break even. If break-even is not feasible (profit per extra unit ≤ 0), the response reflects that.
| Protocol | HTTPS |
|---|---|
| Auth | None |
| Content-Type | application/json |
| Methods | POST |
| Rate Limits | No formal limits; please be sensible. |
| Version | v1 (stable) |
Endpoint
POST /api/feature.php
Request Headers
| Header | Value | Required |
|---|---|---|
| Content-Type | application/json | Yes |
Request Body (JSON)
| Field | Type | Units / Example | Notes |
|---|---|---|---|
costIncrease |
number | percent, e.g. 5 for 5% |
Incremental % increase to unit cost from the new feature. |
currentProfitMargin |
number | percent, e.g. 49.5 |
Existing gross margin (% of selling price). |
unitsWithoutFeature |
number | millions, e.g. 5 → 5,000,000 |
Annual units expected without the new feature. |
sellingPrice |
number | USD per unit, e.g. 1.00 |
Current ASP per unit. |
fixedCost |
number | USD millions, e.g. 1 |
One-time cost to implement the feature (amortized over 3 years in the model). |
extraSellingPrice |
number | USD per unit, e.g. 0.10 |
Additional price you expect to charge on the incremental units. |
Validation Rules
- All six fields are required and must be numeric.
unitsWithoutFeaturecan be fractional (in millions) and is converted to units by × 1,000,000.- If any field is missing/invalid JSON, the API returns an error object.
Calculation Model
-
Convert inputs:
CI = costIncrease / 100M = currentProfitMargin / 100U = unitsWithoutFeature × 1,000,000P = sellingPriceF = fixedCost × 1,000,000ΔP = extraSellingPrice
- Current cost & profit per unit:
C = P × (1 - M)π = P × M
- New cost & profit per unit with feature:
C' = C × (1 + CI)π' = P - C'Δπ = π - π'(decrease in profit per unit)
- Loss on base volume:
L = Δπ × U
- Amortized fixed cost (3 years):
A = F / 3
- Total loss to cover:
T = L + A
- Profit per extra unit (with price uplift on incremental units only):
P' = P + ΔPg = P' - C'
- Extra units required:
- If
g ≤ 0, break-even is not feasible. - Else
extraUnits = ceil(T / g).
- If
Interpretation: If your feature raises unit cost, you incur a loss on the existing plan (same price, same base units). You must cover that loss (plus 1/3 of fixed cost per year) with margin from additional units—optionally aided by a price uplift on those incremental units.
Examples
cURL
{
"cmd": "curl -s -X POST https://www.promptbox.cn/api/feature.php \\",
"data": "-H 'Content-Type: application/json' \\",
"json": "-d '{\"costIncrease\":5,\"currentProfitMargin\":49.5,\"unitsWithoutFeature\":5,\"sellingPrice\":1,\"fixedCost\":1,\"extraSellingPrice\":0.10}'"
}
HTTPie
http POST https://www.promptbox.cn/api/feature.php \ Content-Type:application/json \ costIncrease:=5 currentProfitMargin:=49.5 unitsWithoutFeature:=5 \ sellingPrice:=1 fixedCost:=1 extraSellingPrice:=0.10
JavaScript (fetch)
await fetch("https://www.promptbox.cn/api/feature.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
costIncrease: 5,
currentProfitMargin: 49.5,
unitsWithoutFeature: 5,
sellingPrice: 1.00,
fixedCost: 1.00,
extraSellingPrice: 0.10
})
}).then(r => r.json());
PHP
<?php
$payload = [
"costIncrease" => 5,
"currentProfitMargin" => 49.5,
"unitsWithoutFeature" => 5,
"sellingPrice" => 1.00,
"fixedCost" => 1.00,
"extraSellingPrice" => 0.10
];
$ch = curl_init("https://www.promptbox.cn/api/feature.php");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_RETURNTRANSFER => true,
]);
$out = curl_exec($ch);
curl_close($ch);
echo $out;
Python
import requests
r = requests.post(
"https://www.promptbox.cn/api/feature.php",
json={
"costIncrease": 5,
"currentProfitMargin": 49.5,
"unitsWithoutFeature": 5,
"sellingPrice": 1.00,
"fixedCost": 1.00,
"extraSellingPrice": 0.10
},
headers={"Content-Type":"application/json"}
)
print(r.json())
Responses
200 OK – Success
Returns computed totals. Currency values are rounded to 2 decimals; extraUnitsNeeded is an integer count (rounded up).
{
"lossFromInitialUnits": 123456.78,
"totalLossWithFixed": 223456.78,
"extraUnitsNeeded": 456789
}
200 OK – Not Feasible
If incremental unit profit ≤ 0, break-even cannot be achieved by selling more units.
{
"lossFromInitialUnits": 123456.78,
"totalLossWithFixed": 223456.78,
"extraUnitsNeeded": "Not feasible (profit per extra unit ≤ 0)"
}
200 OK – Error Object
If the payload is missing or malformed, you receive an error description.
{
"error": "Invalid JSON input."
}
Content-Type
All responses use application/json.
HTTP Status Codes
| Status | Meaning |
|---|---|
| 200 | Success (including validation errors surfaced as JSON error objects) |
| 4xx/5xx | Not typically used by this endpoint; infrastructure errors may still occur. |
Design choice: validation issues are returned with HTTP 200 and an error field for simplicity in clients.
JSON Schema (informal)
{
"type": "object",
"required": [
"costIncrease",
"currentProfitMargin",
"unitsWithoutFeature",
"sellingPrice",
"fixedCost",
"extraSellingPrice"
],
"properties": {
"costIncrease": { "type": "number", "description": "Percent (e.g. 5 => 5%)" },
"currentProfitMargin": { "type": "number", "description": "Percent gross margin" },
"unitsWithoutFeature": { "type": "number", "description": "Millions of units per year" },
"sellingPrice": { "type": "number", "description": "USD per unit" },
"fixedCost": { "type": "number", "description": "USD millions" },
"extraSellingPrice": { "type": "number", "description": "USD per unit uplift on incremental units" }
}
}
Worked Example
Inputs:
{
"costIncrease": 5,
"currentProfitMargin": 49.5,
"unitsWithoutFeature": 5,
"sellingPrice": 1.00,
"fixedCost": 1.00,
"extraSellingPrice": 0.10
}
Key steps (rounded here for readability):
C = 1.00 × (1 - 0.495) = 0.505 C' = 0.505 × (1 + 0.05) = 0.53025 π = 1.00 × 0.495 = 0.495 π' = 1.00 - 0.53025 = 0.46975 Δπ = 0.495 - 0.46975 = 0.02525 U = 5 × 1,000,000 = 5,000,000 L = 0.02525 × 5,000,000 = 126,250 A = 1,000,000 / 3 ≈ 333,333.33 T = 126,250 + 333,333.33 ≈ 459,583.33 P' = 1.00 + 0.10 = 1.10 g = 1.10 - 0.53025 = 0.56975 extraUnits = ceil(459,583.33 / 0.56975) ≈ 807,018
You would need approximately 807,018 incremental units per year to break even under these assumptions.
Edge Cases & Gotchas
- If
extraSellingPrice = 0and the feature raises costs,gmay be small; required units can become very large. - If
g ≤ 0(e.g., price uplift too low or cost increase too high), the API returns “Not feasible…”. - All currency math is done in decimal floats; returned currency values are rounded to two decimals.
- Fixed cost is amortized as
fixedCost × 1,000,000 / 3per year (3-year straight-line).
Security & CORS
The endpoint allows cross-origin requests via Access-Control-Allow-Origin: *.
No authentication is required. Do not send sensitive data.
Changelog
| Date | Change |
|---|---|
| 2025-09-28 | Initial public documentation for /api/feature.php. |
Support
Questions or issues? Open an issue with a reproducible example (request body and the JSON you received), or contact the site owner.