image of stars in the sky

Auctions

There is just a single auction endpoint, but as endpoints go it packs quite some punch. In this resource documentation, I will show how you can use this single endpoint in various ways. Hopefully one of these matches your use case.

The auction request payload

The payload you send to the auction endpoint can either be a single auction request or a list of auction requests. Below we are showing the properties that can be included in an auction request. Note that they are all optional. We recommend that you keep things simple, and as few as you need to meet your needs and no more than that.

Properties

  • Name
    num_ads
    Type
    integer
    Description

    The number of ads you would like returned from the auction. Defaults to 1 if not explicitly specified.

  • Name
    filter
    Type
    Filter
    Description

    A filter is used to restrict the ads that are eligible for the auction. The filter model is specified in more detail below. Filters can only be specified either in the singular form of filter or the plural form of filters, but not both at the same time.

  • Name
    filters
    Type
    [Filter]
    Description

    A list of filters used to restrict the ads that are eligible for the auction. Note that this list acts as a logical or, which is to say that an ad that matches at least one of the filters will become part of the auction. Filters can only be specified in the singular form of filter or the plural form of filters, but not both at the same time.

The filter request payload

The filter request payload is an optional subset of the auction request payload described above. It allows you to restrict which ads are included in the auction.

Properties

  • Name
    tags
    Type
    [string]
    Description

    Allows you to specify tags the ads that should be part of the auction must have. In other words: if you specify multiple tags, then only ads that have all of them are included in the auction.

  • Name
    product_ids
    Type
    [string]
    Description

    Allows you to restrict the ad candidates to those that are for a certain set of products. The IDs are the product IDs (in the sense of the products-model as opposed to the ad-id). Only ads for products with an ID in this list are included in an auction.

Usage

The tags and product_ids can be used separately or together. If both are provided, then only ads that satisfy both the tags and the product_ids properties become part of the auction. For example, if you provided the following filter:

{
  "product_ids": ["1", "2", "3"],
  "tags": ["search", "Norway"]
}

Only the ads for products with the IDs 1, 2, and 3 that also have the tag of search as well as the tag of Norway are eligible.


POST/api/v1/auction

Simple auction

The simplest form of auction is one where you do not provide any auction properties. When running such an auction, all ads you have added to Kleio are part of the auction, and a single winner is returned.

Request

POST
/api/v1/auction
curl -X POST \
  -H "Content-Type: application/json" \
  --data '{}' \
  https://example.com/api/v1/auction

Response

{
  "data": [
    {
      "product_id": "1539",
      "ad_id": "59b05f3c-1397-4135-9e32-cdce5ff17736",
      "metadata": "{\"tag\": \"Seasonal promotion\"}",
      "bid": 101,
      "tracking_code": "bx21QE19Rl5KIzQnLnKy1TyOn_TCNuD0GCxTfBvkr3UAWbBfPBOXQTWeMs3OX_F3NlKB9JCEiErRu-JZ9eokl0AAAAAAAAAAZQAAAABlTfxi"
    }
  ]
}

POST/api/v1/auction

Requesting multiple ads

You can specify how many ads you want returned from the auction. A use case where you might want this is where you would like the top three search results to be ads.

The auction will return at most as many ads as you specified. The number of ads is restricted by the number of eligible ads in the system. If for example there are only 4 ads but you have specified 5, then at most 4 ads are returned.

Request

POST
/api/v1/auction
curl -X POST \
  -H "Content-Type: application/json" \
  --data '{"num_ads": 3}' \
  https://example.com/api/v1/auction

Response

{
  "data": [
    {...},
    {...},
    {...}
  ]
}

POST/api/v1/auction

Auction with targeting

Filters can be used to achieve quite sophisticated targeting.

Let's explain the capabilities using an example of wanting to promote products in the search results of an e-commerce shop:

You likely have invested quite some resources in attaining a high degree of relevance in your search results. We do not want to give up this relevancy when introducing sponsored products. As a result, we might want to limit the products that are candidates for being promoted to those that the search engine would naturally return for a given search query. In practice, this could mean that where we might normally request and show the top 20 results, we might now instead request the top 100 results from the search index, and feed these into Kleio. A filter to achieve this goal could look like this:

{
  "product_ids": [... top 100 product ids]
}

Additionally, we might have a wide range of ads for products we want to promote in Kleio. Some of these ads are for promoting products among the recommendations we offer users on the front page, whereas others are targeted at search. In a scenario like this, you could add the tag of search to the ads that should also be eligible for promotion in search.

Expanding on our previous filter, it would now look like this:

{
  "product_ids": [... top 100 product ids],
  "tags": ["search"]
}

In some cases using search relevancy as a means of determining which product to promote might be too restrictive. We might for example also want to promote related products that wouldn't naturally be returned by the search engine. If we were to tag these products with the )search keywords_ we would like them to appear on, we could use a second filter to expand the pool of ads eligible for the auction:

{
  "tags": ["search", "keyword:<search term>"]
}

(there is nothing magic about the keyword:-prefix here. You can use whatever format you want for your tags, but this approach is one we commonly see.).

Combining the two filters we end up with:

[
  {
    "product_ids": [... top 100 product ids],
    "tags": ["search"]
  },
  {
    "tags": ["search", "keyword:<search term>"]
  }
]

which will include all products in the top 100 list that have been enabled for search, as well as all products that have been tagged with the search term.

Request

POST
/api/v1/auction
curl -X POST \
  -H "Content-Type: application/json" \
  --data '{"filters": [
    {
      "product_ids": ["1539"],
      "tags": ["search"]
    },
    {
      "tags": ["search", "keyword:<search term>"]
    }
  ]}' \
  https://example.com/api/v1/auction

Response

{
  "data": [
    {...}
  ]
}


POST/api/v1/auction

Multiple auctions

You can run multiple auctions as part of a single request.

This can come in handy if:

  • you have multiple ad spots you want to fill and want to reduce the latency incurred by bundling them into a single request to Kleio
  • you want model priority levels. For example, you want to show house ads if there are no regular ads to be shown

The response will contain the results for each auction in turn. The results are in the same order as the requests were made.

For example, if you wanted to model priority levels, you could create a request along the lines of:

[
  { ... request for priority level 1 ... },
  ...,
  { ... request for priority level N ... },
  { ... house ads ... }
]

Request

POST
/api/v1/auction
curl -X POST \
  -H "Content-Type: application/json" \
  --data '[
    {"filter": {"tags": ["search", "prio:premium"], "product_ids": ["1539"]}, "num_ads": 3},
    {"filter": {"tags": ["search", "prio:regular"], "product_ids": ["1539"]}},
    {"filter": {"tags": ["search", "prio:house"], "product_ids": ["1539"]}}
  ]' \
  https://example.com/api/v1/auction

Response

{
  "data": [
    [ ... premium results ],
    [ ... regular results ],
    [ ... house results ]
  ]
}