Cart Upsell & Cross-Sell
For any e-commerce business, the shopping cart represents a critical moment of high purchase intent. While getting items into the cart is a major goal, there's a significant opportunity to increase Average Order Value (AOV) and enhance the customer experience by suggesting relevant additional items before checkout. This includes:
- Upsell: Suggesting add-ons directly related to items already in the cart (e.g., batteries for electronics, a case for a phone, warranty).
- Cross-Sell: Suggesting related items from different categories that complement the overall purchase or inferred need (e.g., suggesting running socks if running shoes are in the cart, suggesting a specific lens if a camera body is added).
These intelligent cart recommendations, when done right, feel helpful to the customer and directly boost revenue. However, building an effective system that understands which items complement (either as an add-on or a related purchase) what's already in the cart is a surprisingly complex challenge.
The Shaped Approach: Simplifying Cart Upsell & Cross-Sell with complement_items
Building an effective system for both upsell and cross-sell traditionally requires tackling all the complexities outlined above. Shaped dramatically simplifies this with its platform approach and its dedicated complement_items
endpoint.
Shaped manages the data pipelines, trains sophisticated models that implicitly learn both direct complementarity and broader cross-category relationships from user interactions, and provides a specialized, low-latency API designed specifically for the cart context.
How Shaped Streamlines Cart Upsell & Cross-Sell:
- Data Integration: Connect your order history, product catalog, and interaction data using Shaped's connectors.
- Automated Modeling: Shaped trains models (often embedding-based) that learn which items tend to be purchased or viewed together, capturing both direct accessory patterns (upsell) and related item affinities across categories (cross-sell).
- Managed Serving (
complement_items
): Provides a dedicated API endpoint that takes a list of item IDs (the cart) as input and returns relevant complementary items, which can include both upsell and cross-sell candidates based on learned patterns. - Personalization Built-in: The
complement_items
endpoint can optionally accept auser_id
to personalize the suggestions based on that user's learned preferences, making both upsells and cross-sells more relevant. - Managed Infrastructure & MLOps: Shaped handles the scaling, serving, monitoring, and retraining.
Building Cart Upsell/Cross-Sell with Shaped using complement_items
Let's see how to implement this using Shaped's single endpoint.
Goal: Suggest relevant complementary items (both direct add-ons and related cross-category items) based on the current contents of a user's shopping cart.
1. Ensure Data is Connected: Assume you have connected:
order_data
orinteractions
: Contains purchase events linkinguser_id
,item_id
,order_id
,timestamp
. Co-purchase signals are key.product_catalog
: Containsitem_id
,title
,category
,price
, etc.
2. Define Your Model (YAML): The model definition focuses on learning from purchase (and optionally other) interactions.
model:
name: cart_complement_cross_sell_recs # Combined model name
connectors:
- type: Dataset
name: order_data # Or your primary interactions dataset
id: interactions
- type: Dataset
name: product_catalog
id: products
fetch:
events: |
SELECT
user_id,
item_id,
timestamp AS created_at,
order_id, -- Useful for grouping co-purchased items
-- Prioritize purchase signals for learning complementarity/relatedness
CASE
WHEN event_type = 'purchase' THEN 1.0
-- Optionally include weaker signals like add-to-cart
-- WHEN event_type = 'add_to_cart' THEN 0.5
ELSE 0.1
END as label
FROM interactions
WHERE event_type = 'purchase' -- Focus training strongly on actual purchases
items: |
SELECT
item_id,
title,
category,
price
-- Other relevant product metadata
FROM products
3. Create the Model:
shaped create-model --file cart_recs_model.yaml
4. Monitor Training: Wait for the model to reach the ACTIVE
state.
shaped view-model --model-name cart_complement_cross_sell_recs
5. Fetch Complementary & Cross-Sell Items: Once ACTIVE
, use the complement_items
API endpoint. Provide the list of item_ids
currently in the user's cart. Optionally provide the user_id
for personalization. The results will naturally include both potential upsells (accessories) and cross-sells (related categories) based on the patterns learned by the model.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
- Python
- JavaScript
- CLI
- Curl
from shaped import Shaped
shaped_client = Shaped() # Assumes SHAPED_API_KEY environment variable is set
items_in_cart = ['item_A', 'item_B']
results_limit = 5
complement_items_response = shaped_client.complement_items(
model_name='cart_complement_cross_sell_recs',
item_ids=items_in_cart,
user_id='USER_123', # Optional: for personalization
limit=5,
return_metadata=True,
filter_out_ids=items_in_cart # Ensure cart items aren't suggested
)
print(f"Retrieved {len(complement_items_response.metadata)} complement items.")
const { ShapedClient } = require('@shapedai/shaped');
const apiKey = process.env.SHAPED_API_KEY; // Assumes this is set in environment
const shapedClient = new ShapedClient({ apiKey: apiKey });
const complementItemsResponse = await shapedClient.complementItems({
modelName: 'cart_complement_cross_sell_recs',
itemIds: ['item_A', 'item_B'],
userId: 'USER_123',
limit: 5,
returnMetadata: true,
});
console.log(`Successfully retrieved ${complementItemsResponse.metadata.length} complement items.`);
shaped complement-items \
--model-name cart_complement_cross_sell_recs \
--item-ids '["item_A", "item_B"]' \
--limit 5
# --user-id 'USER_123' # Uncomment if using personalization
curl https://api.shaped.ai/v1/models/cart_complement_cross_sell_recs/complement-items \
-H "x-api-key: <YOUR_SHAPED_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"item_ids": ["item_A", "item_B"], # Items currently in cart
"user_id": "USER_123", # Optional: for personalization
"limit": 5,
"return_metadata": true,
}'
Key Changes and Considerations:
- SDK Method Names: Assumed
complement_items
(Python) andcomplementItems
(JavaScript). Verify these with the actual SDK documentation. - Parameter Names: Assumed
snake_case
for Python andcamelCase
for JavaScript. Verify these. item_ids
Parameter: Ensured this is passed as a list/array in Python/JS.filter_out_ids
Parameter: Added this crucial parameter to the Python and JS examples to match the cURL logic, preventing items already in the cart from being recommended.- CLI
filter_out_ids
: Added a note to the CLI example mentioning that complex parameters likefilter_out_ids
might not be directly supported via flags and might require client-side filtering if using the CLI output directly. Users should check the CLI's help (--help
). - Error Handling/Response Checks: Included basic checks in Python/JS, similar to previous examples.
- Placeholders: Kept
<YOUR_SHAPED_API_KEY>
in cURL and added verification comments (// ** Verify ... **
) in the SDK examples.
Response Structure (from complement_items
):
{
"ids": ["item_C_accessory", "item_D_related_category", "item_E_bundle", ...], // Upsell & Cross-sell IDs
"scores": [0.85, 0.78, 0.75, ...], // Relevance/Complementarity scores
"metadata": [ // Optional: if return_metadata=true
{"title": "Accessory for Item A", "price": 19.99, ...},
{"title": "Related Product D (Different Category)", "price": 49.99, ...},
{"title": "Bundle Item E", "price": 9.99, ...},
...
]
}
Your application takes this list (ids
), filters out cart items, checks inventory, potentially applies simple business rules (e.g., limit to 1 accessory + 2 related items), and displays the suggestions.
Shaped's complement_items
endpoint elegantly handles the context of multiple items in the cart, surfacing both direct complements (upsell) and relevant related items (cross-sell) based on powerful underlying models, significantly simplifying implementation.
Conclusion: Drive Higher AOV with Smarter Cart Upsell & Cross-Sell
Suggesting relevant add-on items (upsell) and related products from other categories (cross-sell) in the shopping cart are proven strategies to increase average order value and improve the customer journey. However, building the system to accurately determine these relationships based on cart context involves significant data engineering and machine learning hurdles.
Shaped, with its specialized complement_items
endpoint, provides a powerful shortcut. By leveraging Shaped's platform, you can easily connect your sales and product data, train models that understand both direct and indirect product relationships, and serve personalized, context-aware cart suggestions via a simple API. Don't leave money on the table – implement intelligent cart upsell and cross-sell strategies the easy way with Shaped.
Ready to boost your AOV with AI-powered cart recommendations?
Request a demo of Shaped today to see it in action with your specific use case. Or, start exploring immediately with our free trial sandbox.