Image Search: Execute Search
Image Search
Image Search: Execute Search
Image Search API endpoint to run visual searches across your product catalog using uploaded image IDs or base64-encoded image payloads.
POST
Image Search: Execute Search
Authorization
Token-based authentication header in the form of
<YOUR_LAYERS_TOKEN>.Headers
Body
Base64 Encoded PNG or JPEG Image Data. Required if
image_id is not provided.UUID identifier returned from the Image Upload API. Required if
image_data is not provided. Using image_id is recommended for better performance and support for larger images.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.Refer to our dedicated Filter Expressions guide to learn more about filter expressions.
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:If the count of each facet value should be calculated
If you want a min/max range for numeric facets such as price.
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.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_variantfield in the response
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.
User identity information for tracking and personalization. Automatically managed by the Storefront Pixel; required for headless integrations.
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.
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
The total number of results.
The current page number.
The total number of pages.
If
includeFacetRanges is true then an object with keys of the facet attribute code and value is an object with min/max.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.A unique request identifier (ULID) for this API call. Use this token to correlate requests with analytics events via the Beacon API.
Metadata about the search request.
An ordered trace of processing steps the engine performed. See the Text Search documentation for the full list of possible step types.
Response headers
| Header | Description |
|---|---|
x-request-id | A unique identifier (ULID) for the request. This matches the attributionToken in the response body. |
x-layers-build | The Layers build version that served the request. |
X-Layers-Results-Cache | Indicates whether the response was served from the results cache. Returns HIT or MISS. |
Link | Contains rel="preload" directives for product images (up to 6 items). See Early hints for details. Only included when early hints are enabled (enabled by default). |
Error responses
422 Unprocessable Entity
A 422 error is returned when theimage_id refers to an image that failed to process. This can occur when:
- The uploaded image is corrupted or invalid
- The image format is unsupported
- The image file cannot be read or decoded
message field provides specific details about why the image processing failed.
Usage examples
Using image ID (recommended)
First, upload an image to get animage_id:
image_id for searching: