Skip to main content
POST
Search API: Similar Products

How results are served

Similar products results are precomputed and cached for fast response times. The system runs the full ranking pipeline — combining visual and semantic similarity with behavioral signals — and stores the top results for each product. When you call this endpoint, results are served from the precomputed cache. If no precomputed data exists for a product (for example, a newly added product), the system falls back to computing similarity in real time. Precomputed results are refreshed daily and incrementally when a product’s content changes. All request parameters (filters, facets, pagination, and sort orders) work the same regardless of whether results are served from cache or computed in real time. When you pass variant_id in the request body, results are always computed in real time from that variant. Shoppers viewing different variants of the same product see different recommendations.

Authorization

string
required
Token-based authentication header in the form of <YOUR_LAYERS_TOKEN>.

Headers

string
default:"application/json"
required
string
default:"application/json"
required

Path parameters

integer
required
The ID of the product for which you want to find similar products.

Body

integer
When provided, the endpoint seeds similarity from that variant rather than the product as a whole. Results then reflect the variant’s visual and semantic attributes, such as a specific color or material. Pass the variant currently selected on the product detail page.The value is only used when the variant belongs to the anchor product in the path. If it doesn’t match, the value is silently ignored and results fall back to product-level similarity. If the variant isn’t indexed yet, results also degrade to product-level similarity.When variant_id is set, results are computed in real time rather than served from the precomputed cache. Different variants of the same product return different results and are cached under separate keys.
string[]
Product attributes to include in the response. By default, all attributes are included. Available attributes include: id, title, handle, body_html, vendor, product_type, tags, images, available, created_at, updated_at, published_at, price_range, options, original_options, metafields, named_tags, calculated, category, featured_media, is_gift_card, has_variants_that_require_components, combined_listing_parent_product_id, combined_listing_role, first_or_matched_variant, and variants. See the Product Schema for detailed descriptions, including nested field selection for slicing arrays and filtering collections (for example, images[:2].src, variants[sku=ABC].price, metafields[namespace=custom]).
object
Refer to our dedicated Filter Expressions guide to learn more about filter expressions.
Pagination Object
string[]
Facets to be included. Accepts both exact facet codes (e.g., "vendor", "options.Size") and wildcard patterns (e.g., "options.*", "metafields.product.*").Wildcard patterns expand to all matching attribute codes. For example, "options.*" expands to all option facets like "options.Size" and "options.Color". Wildcards must match at least one attribute code to be valid.Examples:
boolean
If the count of each facet value should be calculated.
boolean
If you want a min/max range for numeric facets such as price.
boolean
When true, any facet backed by a metaobject_reference or list.metaobject_reference metafield is returned with a companion facetDisplay object. Each entry maps a facet value (the metaobject handle) to the referenced metaobject’s display_name and fields.Use this when your storefront filter UI needs human-readable labels or nested field data (for example, a color name or swatch hex) instead of the raw handle. When false or omitted, only the handles are returned in facets.Values are looked up from the local metaobject cache. Handles with no matching cached metaobject are omitted from facetDisplay and remain as plain values in facets. See Metaobjects and reference metafields for the normalized shape of each entry.
string
Code of the sort order to apply. Use "relevance" for the default relevance-based ranking, or any custom sort order code configured in your store. Retrieve available sort order codes from the Sort Orders API.
array
Specify which product variants should be selected by default in the first_or_matched_variant field.Behavior:
  • Uses OR logic - selects the first variant matching ANY of the specified option values
  • Falls back to the first variant by position if no match is found
  • Automatically skipped when any option or variant filters are applied (filters take precedence)
  • Only affects the first_or_matched_variant field in the response
array
Apply discounts to products, variants, or collections. When provided, price-based sorting and filtering will use discounted prices. See the Discount Entitlements guide for detailed usage.
object
User identity information for tracking and personalization. Automatically managed by the Storefront Pixel; required for headless integrations.
object
Contextual information about the customer’s session, behavior, and environment. Automatically collected by the Storefront Pixel; must be manually provided for headless integrations. See Contextual Information for implementation guidance.
object
Per-request overrides for response behavior. Currently controls image preload hints emitted in the Link response header. You can disable preloads or narrow the srcset to the breakpoints your storefront uses. You cannot enable preloads when the store has them disabled.Example:

Response

Array of Objects
number
The total number of results.
number
The current page number.
number
The total number of pages.
object
If includeFacetRanges is true then an object with keys of the facet attribute code and value is an object with min/max.
object
If retrieveFacetCount is true then an object with keys and values of the specified attributes. Empty values and literal "null" strings are automatically excluded from facet results.
object
Only returned when enrichFacetMetaobjects is true and at least one requested facet is backed by a metaobject_reference or list.metaobject_reference metafield. Keys are facet attribute codes and values map each facet value (the referenced metaobject’s handle) to the metaobject’s display_name and fields. Handles with no matching cached metaobject are omitted here and remain as plain values in facets. See Metaobjects and reference metafields for the normalized field shape.
string
A unique request identifier (ULID) for this API call. Use this token to correlate requests with analytics events via the Beacon API.
object
array of objects
An ordered trace of processing steps the engine performed. See the Text Search documentation for the full list of possible step types.

Response headers