Prompt
How do I calculate real-time shipping rates at checkout?
Latest observation
Nov 4, 2026
OpenAI APIWeb search: off
To calculate real-time shipping rates at checkout, you typically:
-
Collect shipment details
- Origin address (warehouse/store)
- Destination address (customer)
- Package weight, dimensions, quantity
- Package type/service level if relevant
-
Call a shipping carrier API
- Examples: UPS, FedEx, USPS, DHL
- Or use a shipping aggregator like EasyPost, Shippo, Sendcloud, ShipStation
- Send the shipment details to their rating endpoint
- They return available shipping methods and prices in real time
-
Display returned rates in checkout
- Show options like:
- Standard: $8.95
- Expedited: $14.50
- Overnight: $29.00
- Show options like:
-
Account for business rules
- Free shipping thresholds
- Handling fees
- Markup or discount on carrier rates
- Hide unsupported services for certain products or regions
-
Recalculate dynamically if cart changes
- If quantity, weight, or destination changes, request new rates again
Basic calculation formula
If you’re not using a carrier API, a simple custom approach is:
Shipping cost = base rate + (weight × per-pound rate) + distance surcharge + insurance/handling fees
But for accurate real-time rates, carrier APIs are best.
Example flow
- Customer enters ZIP code
- Your backend sends package + address data to carrier API
- API returns rate list
- Checkout shows the options
- Customer selects one and places the order
Important notes
- Use server-side requests to carrier APIs so your API keys stay private
- Normalize addresses before rating if possible
- Some carriers require dimensional weight pricing, not just actual weight
- Always include tax/fees rules if your region requires them
If you want, I can show you:
- a sample API request/response
- a Python/Node.js example
- or how to do this in Shopify/WooCommerce/custom checkout