Version 1.0 • Content-Type: application/json
Compute the subsidy amount required to cover unsold units in a fixed lot and the resulting new unit price to fully amortize the lot when a buyer purchases only a partial lot.
Send a JSON body with the following fields:
| Field | Type | Required | Description |
|---|---|---|---|
current_price |
number | Yes | Current unit selling price (must be ≥ 0). |
purchase_volume |
number | Yes | Units the customer will purchase (must be > 0 and ≤ lot_size). |
lot_cost |
number | Yes | Total cost paid per lot (must be ≥ 0). |
lot_size |
number | Yes | Total units per lot (must be > 0). |
purchase_volume > 0, lot_size > 0, and purchase_volume ≤ lot_size.current_price ≥ 0, lot_cost ≥ 0.{
"current_price": 10,
"purchase_volume": 50,
"lot_cost": 200,
"lot_size": 100
}
curl -X POST https://www.promptbox.cn/api/partial.php \
-H "Content-Type: application/json" \
-d '{
"current_price": 10,
"purchase_volume": 50,
"lot_cost": 200,
"lot_size": 100
}'
const res = await fetch("https://www.promptbox.cn/api/partial.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
current_price: 10,
purchase_volume: 50,
lot_cost: 200,
lot_size: 100
})
});
const data = await res.json();
console.log(data);
Returns a JSON object containing the echoed inputs, computed outputs, and diagnostics. All numeric values are rounded to 5 decimals.
{
"input": { ... },
"output": { ... },
"diagnostics": { ... }
}
output fields| Field | Type | Description |
|---|---|---|
subsidy_amount |
number | Dollar amount required to cover unsold units in the lot. |
new_price |
number | Adjusted unit price to fully amortize the lot using the buyer’s partial volume. |
{
"input": {
"current_price": 10.00000,
"purchase_volume": 50.00000,
"lot_cost": 200.00000,
"lot_size": 100.00000
},
"output": {
"subsidy_amount": 100.00000,
"new_price": 12.00000
},
"diagnostics": {
"unused_units": 50.00000,
"utilization_percent": 50.00000,
"unutilized_percent": 50.00000,
"notes": [
"subsidy_amount_equals_cost_of_unsold_units",
"new_price_equals_current_price_plus_subsidy_per_purchased_unit"
]
}
}
| Name | Formula | Notes |
|---|---|---|
| Unsold units | unused = lot_size - purchase_volume |
Lower-bounded at 0 by validation. |
| Subsidy amount | subsidy = (1 - purchase_volume / lot_size) * lot_cost |
Cost share for units that will never be sold. |
| New unit price | new_price = current_price + subsidy / purchase_volume |
Spreads the subsidy across purchased units. |
| Utilization % | utilization = (purchase_volume / lot_size) * 100 |
Shown in diagnostics. |
| Status | Meaning | Example body |
|---|---|---|
| 200 | OK — calculation succeeded | See “Example successful response”. |
| 400 | Bad Request — validation failed or bad JSON | {
"error": "purchase_volume must be greater than 0."
} |
| 405 | Method Not Allowed — only POST is supported | {
"error": "Only POST method is allowed."
} |
{"error":"Missing required field: lot_size."}{"error":"All fields must be finite numeric values."}{"error":"purchase_volume must be greater than 0."}{"error":"lot_size must be greater than 0."}{"error":"purchase_volume cannot be greater than lot_size."}{"error":"current_price cannot be negative."}No authentication or explicit rate limiting is documented. Treat as a public unauthenticated endpoint; implement client-side backoff if needed.