Prompt
How do I get real-time shipping rates from an API at checkout?
Latest observation
Nov 4, 2026
OpenAI APIWeb search: off
To get real-time shipping rates at checkout, you generally need to connect your checkout flow to a shipping rate API that can calculate prices based on the order details and destination address.
Typical flow
-
Collect shipping address at checkout
- Country, postal code, city, state/province, and street if needed
- Package details if required: weight, dimensions, value, number of items
-
Call the shipping API
- Send:
- origin address
- destination address
- package weight/dimensions
- service options
- currency
- The API returns available shipping methods and prices
- Send:
-
Show rates to the customer
- Display options like:
- Standard — $8.95
- Express — $14.50
- Overnight — $29.99
- Display options like:
-
Recalculate when inputs change
- If the user changes address or cart contents, request updated rates
-
Use the chosen rate to create the shipment
- At order completion, book the label or save the chosen rate for fulfillment
What the API request usually needs
Most shipping APIs expect something like:
- Ship-from address
- Ship-to address
- Package weight
- Package dimensions
- Declared value / insurance if applicable
- Requested services like ground, air, international
- Pickup/delivery constraints if relevant
Example request fields:
{
"origin": {
"country": "US",
"postal_code": "94103"
},
"destination": {
"country": "US",
"postal_code": "10001"
},
"package": {
"weight": 2.5,
"weight_unit": "lb",
"length": 12,
"width": 8,
"height": 4,
"dimension_unit": "in"
}
}
Example response:
{
"rates": [
{ "service": "Ground", "price": 8.95, "currency": "USD", "eta": "3-5 days" },
{ "service": "2-Day", "price": 14.5, "currency": "USD", "eta": "2 days" }
]
}
Implementation options
1. Use a shipping carrier API directly
Examples:
- UPS
- FedEx
- DHL
- USPS (depending on country/support)
Pros:
- Direct carrier rates
- Potentially lower cost
Cons:
- Multiple integrations if you support more than one carrier
- More complex authentication and rate formats
2. Use a shipping aggregation API
Examples:
- EasyPost
- Shippo
- ShipEngine
Pros:
- One API for multiple carriers
- Easier rate comparison
- Often better developer experience
Cons:
- Platform fees may apply
- Rate availability depends on carrier coverage
Checkout integration pattern
Frontend
- User enters shipping address
- Frontend sends address/cart info to your backend
- Show loading state while fetching rates
Backend
- Receives request from frontend
- Validates address and cart data
- Calls shipping API securely using API key
- Returns rates to frontend
Important
Do not call the shipping API directly from the browser if it exposes secret credentials.
Best practices
- Cache rates briefly to reduce API calls
- Debounce address changes so you don’t call the API on every keystroke
- Validate addresses before requesting rates
- Handle API failures gracefully with fallback messaging
- Requote before final payment because rates can change
- Use the final selected rate in the order record
Simple backend example
Node.js / Express
app.post("/shipping-rates", async (req, res) => {
const { origin, destination, package: pkg } = req.body;
const response = await fetch("https://api.shippingprovider.com/rates", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${process.env.SHIPPING_API_KEY}`
},
body: JSON.stringify({ origin, destination, package: pkg })
});
const data = await response.json();
res.json(data);
});
If you want the simplest path
Use a shipping aggregation service like Shippo or EasyPost, then:
- create a backend endpoint for rate quotes
- pass the checkout address/cart data to that endpoint
- display returned rates in the checkout UI
If you want, I can also show you:
- a full checkout rate-fetching example in Node.js, Python, or PHP, or
- how to do this specifically with Shopify, WooCommerce, or Stripe Checkout.