Partial Lot Subsidy API

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.

POST https://www.promptbox.cn/api/partial.php

Request

Send a JSON body with the following fields:

FieldTypeRequiredDescription
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).
Validation rules:

Example request

{
  "current_price": 10,
  "purchase_volume": 50,
  "lot_cost": 200,
  "lot_size": 100
}

cURL

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
  }'

JavaScript (fetch)

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);

Response

Returns a JSON object containing the echoed inputs, computed outputs, and diagnostics. All numeric values are rounded to 5 decimals.

Top-level structure

{
  "input": { ... },
  "output": { ... },
  "diagnostics": { ... }
}

output fields

FieldTypeDescription
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.

Example successful response

{
  "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"
    ]
  }
}

Calculation Logic

NameFormulaNotes
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.

HTTP Status Codes

StatusMeaningExample 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 Cases

Idempotency & Rounding

Rate Limits & Auth

No authentication or explicit rate limiting is documented. Treat as a public unauthenticated endpoint; implement client-side backoff if needed.

Change Log