Get early access

Docs / Reference / Public API reference (v1)

All docs

Start here

  • Quick startKeys, install, items, events and your first lists, in every library

Platforms

  • ShopifyInstall on Shopify with the default settings, and the three usual problems
  • WooCommerceInstall the WooCommerce plugin, what you see after ten minutes, the usual problems
  • MagentoInstall the Magento 2 module, what you see after ten minutes, the usual problems
  • Any websiteAny other website: one script tag, what recapi reads from your product pages, the usual problems

Reference

  • LibrariesInstall the library for your language, the three calls, and what all eight do for you
  • Public API reference (v1)Every call, field and error of the HTTP API
  • Accessibility statementWhat the row meets for screen readers, keyboards and narrow screens, how it is checked, and what it leaves to your site
  • Limits and errorsEach error code, what caused it and what to do, and the limits behind them

Understand and fix

  • FAQWhat people ask before they sign up: price, platforms, first lists, data, consent, stopping
  • Concepts in plain wordsPlacements, list kinds, visitors, the lift test, variety, Settings, consent and cookie banners in plain words
  • GlossaryEvery word the docs and dashboard use, in two lines each
  • TroubleshootingWhat you see after installing; row missing, empty lists, only popular items, orders or clicks not counted, CORS or key errors: the check and the fix

Public API reference (v1)

Last changed

Every call, field and error of recapi's HTTP API, and which library to use for your platform. Each error code, what caused it and what to do is also on the errors page.

In short

  • A shop sends what its visitors do (POST /v1/events) and asks which items to show them (POST /v1/recommendations).
  • Use a library: it keeps each visitor's history, batches events, retries and falls back to popular items.
  • Public keys (rk_pub_) go in pages and apps, secret keys (rk_sec_) stay on your servers.
  • Every error carries a code to branch on (errors).
Endpoint What it does Key
POST /v1/events record what visitors did public or secret
POST /v1/events:import load past events in bulk secret
PUT /v1/items/{item_id} describe an item, whole secret
PATCH /v1/items/{item_id} change some of an item's fields secret
POST /v1/items:batch describe up to 1,000 items at once secret
GET /v1/items/{item_id} read an item secret
DELETE /v1/items/{item_id} mark an item inactive secret
POST /v1/shopify/webhooks Shopify's product webhooks public, in the URL
POST /v1/shopify/products:seen what a Shopify product page says public
POST /v1/products:seen what any site's product page says public
POST /v1/recommendations one or more lists for a visitor or a product page public or secret
GET /v1/popular popular items, cacheable public or secret
GET /v1/users/{user_id}/history a user's stored history secret
DELETE /v1/users/{user_id} erase a user's events (GDPR) secret
GET /sdk/…, GET /goproxy/… download a library none
GET /healthz, GET /readyz health checks none

Where to start

You have… Start with
a Shopify, WooCommerce or Magento shop its guide: Shopify, WooCommerce, Magento
another site or an app Use a library
an error to fix the errors page, then troubleshooting
a word you don't know concepts and the glossary

Use a library

Integrate recapi through one of its client libraries rather than these endpoints:

Where your code runs Library
browsers, Node JS SDK (@recapi/client, or one script tag on sites without a bundler)
a Shopify shop the JS SDK in the theme, plus a custom pixel for add-to-carts and purchases (Shopify; the dashboard's quick start shows both with your address)
a WooCommerce shop one plugin file that prints the JS SDK on every page: views, add-to-carts and purchases on the order-received page; with a secret key, orders and products from the shop's server (below the table) (WooCommerce; the dashboard's quick start shows it with your address)
a Magento 2 shop a module: the JS SDK on every page for views and add-to-carts, orders sent from the server with the PHP library, products described (below the table), and a recommendation row on product pages (Magento, composer require recapi/module-recommendations from Packagist, or downloaded from the API as a zip)
Python servers (Django, Flask, FastAPI, workers) Python library (recapi, standard library only, pip install recapi from PyPI, or with pip from the API)
PHP sites (WordPress, Laravel, Symfony) PHP library (Recapi\Client, PHP 8.2 and curl, one file: composer require recapi/client from Packagist, or downloaded from the API)
Java servers (Spring...), Kotlin, Android apps Java library (io.recapi.Client, Java 11 or Android 7 (Android 7.0 trusts Let's Encrypt's root through a network security config), standard library only, io.recapi:recapi on Maven Central, or sources downloaded from the API as a zip)
Go servers Go library (package recapi, Go 1.24, standard library only, go get recapi.io/go: the module served by the API; before it, sources downloaded from the API as a zip)
iOS and macOS apps, Swift servers (Vapor, Hummingbird) Swift library (RecapiClient, Swift 6, iOS 15 or macOS 12, Foundation only, a Swift package from its git repository, or downloaded from the API as a zip)
Ruby servers (Rails, Solidus, Sinatra, jobs) Ruby library (Recapi::Client, Ruby 3.1, standard library only, one file: the gem recapi from RubyGems, or downloaded from the API)
.NET servers (ASP.NET Core, workers) C# library (RecapiClient, .NET 8, standard library only, the NuGet package Recapi, or the project downloaded from the API as a zip)

With a secret key, the WooCommerce plugin sends each order from the shop's server once paid, and describes each product with PUT /v1/items as it is saved and the whole catalog daily. The Magento module describes each product with PUT /v1/items as it is saved and the whole catalog nightly.

They keep each user's history and send it with every recommendation request, so recapi doesn't read it from storage. They batch events (one request for up to 1,000 instead of one each) with an idempotency key per event, retry what can succeed later, fall back to popular items when recapi is slow or failing (and to an empty list when recapi is down altogether, so the page still renders), and put the recommendation_id on clicks by themselves. The libraries share the behaviour vectors in spec/, so they make the same decisions.

The rest of this page is the HTTP reference the libraries are built on: for other languages, mobile apps and library authors (calling it directly).

Base URL: https://api.<your-domain> (local: http://localhost:8080). All bodies are JSON (Content-Type: application/json). Gzip request bodies are accepted (Content-Encoding: gzip).

Authentication

Every call needs an API key, created in the dashboard. A key belongs to one environment (production, test…) and reads and writes that environment's data only:

Kind Prefix Allowed calls Where to use
Secret rk_sec_ everything your servers only
Public rk_pub_ POST /v1/events, POST /v1/recommendations (without explain), GET /v1/popular, POST /v1/shopify/products:seen, POST /v1/products:seen browsers, mobile apps

Send it as Authorization: Bearer <key>. GET /v1/popular also accepts ?key=<public key> (public keys only) so responses can be cached by a CDN, and POST /v1/shopify/webhooks takes only that, since Shopify sends no header.

POST /v1/recommendations, POST /v1/events, POST /v1/shopify/products:seen and POST /v1/products:seen also accept ?key=<public key> (public keys only), so a browser can call them without a CORS preflight, the extra OPTIONS request that costs a network trip before the call. The body stays JSON, and the Content-Type is not read: send text/plain, with no Authorization or Content-Encoding header, or the browser asks first anyway. The answer, limits and billing are the same as with the header. Servers keep using the header. If a call has an Authorization: Bearer header, that header decides and ?key= is ignored.

A public key in a URL reaches access logs along the way. That is acceptable because a public key is public by design: it is in the page's source. A secret key in a URL gets 401.

No other endpoint accepts keys in the URL.

A public-key call is scored on the history it sends, never on the stored history of the user_id it names. Anyone can read your public key and guess a user id, and a list on that history would show what the user opened by what it leaves out. With no history sent, it gets the list a new visitor gets. The libraries send the history they keep, and your server, with the secret key, gets the stored one.

Naming your integration

A plugin or library may say what it is, so the dashboard words its setup hints in your platform's terms and opens the quick start on your platform's section, from the first call, before any product arrives:

  • from a server, a User-Agent starting recapi-<name>/<version>, as every recapi server library sends (recapi-python/0.5.0); our WooCommerce plugin sends recapi-woocommerce/<version>, our Magento module recapi-magento/<version> on its own calls;
  • from a browser, which can't set User-Agent, the query parameter ?platform=<name>/<version> on any call (?platform=magento%2F0.4.19): the JS library's platform option. A parameter, not a header: a custom header would make the browser send a CORS preflight first, and the call stays a simple one that a page-hide keepalive send can carry. When both are present, the parameter decides.

Known names are shopify, woocommerce, magento and the libraries' go, python, php, java, csharp, swift and ruby. Naming nothing, or something else, is never an error: the call works the same and the name is ignored. recapi keeps the latest name per environment, and a platform's name outranks a library's (a plugin that calls through a library stays the platform). A call that names the recorded platform without a version keeps the version already known. An environment whose Shopify webhook secret is saved on the quick start counts as Shopify from then on.

Revoking a key on the dashboard takes effect within a minute, because API nodes cache keys for that long. Deleting an environment revokes all of its keys, and they get 401 within the same minute. To replace a leaked key, create the new one, deploy it, then revoke the old one.

Leaked keys found by GitHub are revoked and you are emailed: when GitHub's secret scanning reports one of your secret keys in a public repository, package, gist, issue or Actions log, recapi revokes it within a minute and emails every member of your organization where it was found and how to replace it. Public keys are never revoked this way. Secret keys created since 22 November 2026 have 38 characters after rk_sec_, the last six a checksum; older ones have 32 and keep working. Check a key by its prefix only.

Billing

Each successful call is metered under a call type with a fixed unit price (see the dashboard's Usage page). Failed calls (4xx/5xx) are not billed, except the events a batch stored before it failed. A batch of events retried within 2 minutes with the same event_id on every event is stored and billed once; the retry still answers 202.

Free units, the spend cap and the bill are your organization's: the calls of all its environments count towards them together. There is no contract: Cancel subscription on the Usage page keeps the paid plan until the end of the billing month, whose usage is invoiced as usual, then moves the organization back to the free plan (undo any time before that).

Call type Unit
event one accepted event (batches are billed per event)
recommendation one POST /v1/recommendations, a recommendation request: it fills every row of a page, up to 10 lists, and counts once on your bill, whatever their length. Against the request rate, each row counts
popular one GET /v1/popular (cache hits at the CDN are free)
item_write one item created/updated/deactivated: an item sent again exactly as stored is not billed, by PUT, PATCH, the batch or the dashboard's upload of a Shopify products export

Errors

{ "error": { "code": "invalid_request", "message": "count must be between 1 and 100",
             "docs_url": "https://app.recapi.io/docs/errors#400-invalid_request" } }
HTTP code Retry?
400 invalid_request (also unknown JSON fields, malformed gzip, and gzip that expands past 4× the body limit) no, fix the request
401 unauthorized (missing, malformed or revoked key, or a key of a deleted environment) no
403 forbidden (public key on a secret-only call or with explain, suspended shop) no
404 not_found no
413 too_large (body over the endpoint's limit, see below) no, split the batch
429 rate_limited (per-shop request rate: at least 2,000 a second, bursts up to 4,000, each API server counting on its own; ten events of a batch count as one request and each list of a several-list call as one; sent with Retry-After: 1) yes, after the delay (with backoff if the header is missing)
429 rate_limited (one visitor address past 600 requests a minute with your public key, counted the same way, so a copied key can't use up your shop's rate or quota; sent with Retry-After: 1) yes, after the delay
429 quota_exceeded (monthly quota or spend cap reached; both count for the whole organization, so another environment's calls use them up too) no; upgrade the plan, or ask us to raise the spend cap (caps are set by recapi, not on the dashboard)
503 unavailable (ingestion or a dependency is briefly down, a shop created seconds ago is not loaded yet, or the server is at its limit of calls at once; then sent with Retry-After: 1) yes, after the delay if Retry-After is sent, else with backoff
500 internal yes, with backoff

Branch on code: message is for people, and its wording can change. docs_url is the address of the code's section on the errors page, absent when the server has no public site address.

Request bodies reject unknown fields, so a typo such as "tag_any" fails with 400 instead of being ignored. Body size limits: 2 MB for POST /v1/events, 8 MB for POST /v1/items:batch, 256 KB for POST /v1/recommendations, 64 KB for PUT and PATCH /v1/items/{item_id} and 4 MB for a Shopify product webhook (gzip bodies may expand to 4× that, except the webhook's, which is read as sent).

Ids (item_id, user_id, anon_id, recommendation_id, event_id, context_item_id) are 1–256 bytes of UTF-8 without control characters. Tags are lowercase [a-z0-9:_-], 1–64 characters.

Without a library: other languages and mobile apps

The JS SDK keeps each visitor's history in the browser, and the Python, PHP, Java, Go, Swift, Ruby and C# libraries each user's on your server (or an Android or iOS app). A server in another language can skip that: send events with a user_id, then ask for recommendations with the same user_id and no history. The server then uses its stored history for that user (the Settings option for signed-in visitors, on by default). These calls work as shown, with a secret key in $RECAPI_KEY.

The five calls

Describe an item:

curl -X PUT "$RECAPI_URL/v1/items/item_4471" -H "Authorization: Bearer $RECAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"tags": ["sports"], "title": "Cup final highlights"}'

Record what a user did (here, opening the item: level 3, see interaction levels):

curl -X POST "$RECAPI_URL/v1/events" -H "Authorization: Bearer $RECAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"events": [{"user_id": "cust-881", "item_id": "item_4471", "level": 3}]}'

Check that the event is stored (a few seconds later). The top list should now hold item_4471:

curl "$RECAPI_URL/v1/users/cust-881/history" -H "Authorization: Bearer $RECAPI_KEY"

Get recommendations from the stored history:

curl -X POST "$RECAPI_URL/v1/recommendations" -H "Authorization: Bearer $RECAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"user_id": "cust-881", "placement": "homepage", "count": 4}'

Popular items, for pages without a user:

curl "$RECAPI_URL/v1/popular?count=4&tags_any=sports" -H "Authorization: Bearer $RECAPI_KEY"

Things to know

  • Keys. The secret key stays on your servers. A mobile app gets a public key: it can send events, get recommendations and popular items, nothing else. Its lists come from the history it sends, not the stored one (why).

  • Logged-out users. Send a stable anon_id (for example a device id) on events and recommendation calls. Experiments use it to show the same variant every time. A call with a user_id is assigned by the user_id instead, so a user who logs in during a test may switch variant. Only user_id has a stored history, so an anonymous user gets personalised results only if you send history/recent (the history spec).

  • Login (identify). Once events carry both the user_id and the anon_id (the libraries' identify(user) sends both from then on, where consent allows), the events sent with only that anon_id, before login or after logout, count as the user's: in their stored history, on every device, and in training. An anon_id that more than one user logged in under in the window (a shared device, or a site sending one constant id) stays a visitor of its own. The stored history takes in the five newest anon_ids of the user's own events.

  • Attribution. Put the response's recommendation_id on the user's click on an item in that response and on that item's later events (an add to cart, an article read to the end, a completed video), as "recommendation_id": "rec_…". The libraries do this by themselves: they tag an event on a shown item within 30 minutes of the display, then that item's later events for 24 hours after the click.

    An event without it is credited to the latest list that showed its item to that user (user_id, else anon_id) if recapi received it within 30 minutes after serving that list, so a click is still counted; a purchase an hour later, or an event with neither id, is not.

    Keep it off events about other items, and off items the user reached some other way: the dashboard counts a recommendation as clicked when any event carries its id.

Freshness, latency and failures

  • Freshness. New events reach the stored history within a few seconds. If you ask for recommendations before a user's first event is stored, the API node remembers for 10 minutes that this user has no history, so a visitor who never sends an event costs one read. Their first event ends that at once on the API node that accepts it: the next list there uses it. Another API node keeps its note, so there a new user's first events may take up to 10 minutes to count.

    A history it did find is kept for 10 seconds, so the several lists of one page cost one read. An event the same API node accepts drops that user's copy, and for 5 seconds after it, while the event is on its way to the store, the node reads the user's history afresh on every call. Another API node keeps its copy, so there a user's newest events may take up to 10 seconds longer to count.

    Imported events (events:import) don't drop the copy: they are the past, and count within 10 seconds. Events sent with an anon_id only reach a logged-in user's history through the store, also within 10 seconds.

  • Latency. Each call with a user_id and no history reads the user's last 90 days of events (at most 2,000). When an environment's reads find nothing more than 50 times a second, they wait up to 20 ms to share one query. The read is cut off after 300 ms, and the call then goes on without the history. After 5 failed reads in a row for your environment, the API node skips its stored history for 10 seconds; other environments are not affected, and a call whose client hung up does not count as a failure.

  • Failures. Use a short timeout: the libraries give up on a recommendation call after 1.5 s. Retry 429 rate_limited after Retry-After, and 5xx once with backoff. If the call still fails, show GET /v1/popular instead, and hide the slot if that fails too.

    The libraries do this by themselves, without the retry, on timeouts, network errors, 5xx and 429 (an empty list with fallback true when popular fails too), and answer 401 and 403 with that empty list at once, because popular would be refused too. A page never fails because of recapi's state or the shop's plan or key; the error goes to the library's log or onError, and the dashboard warns of a limit.

    A page often takes a product id from a visitor's URL, so the libraries check it first: a context_item_id this API would refuse is never sent, and the call answers with the popular list the same way (track drops only that event, with a log line, and throws nothing).

    They still fail on another bad request (400, 404, 413, another 3xx or 4xx) and a reply that isn't the API's (invalid_response): those can't start on a live site without a deploy. GET /v1/popular in the libraries follows the same rule, with an empty list.


POST /v1/events

Batch of up to 1000 interaction events. Against your shop's request rate, ten events of a batch count as one request: a batch of 1 to 10 events costs one, a full batch of 1,000 costs 100, so a shop sends up to 20,000 events a second. Past that, the whole batch gets 429 rate_limited with Retry-After: 1, nothing of it is stored, and the same batch can be sent again.

{
  "events": [
    {
      "user_id": "cust-881",
      "anon_id": "0d6c4c1e-…",
      "item_id": "item_4471",
      "level": 3,
      "recommendation_id": "rec_01JB…",
      "timestamp": "2026-10-23T12:00:00Z",
      "event_id": "evt-123"
    },
    { "user_id": "cust-881", "item_id": "item_4471", "level": 10, "value": 49.9, "currency": "EUR" }
  ]
}
Field Required Notes
item_id yes 1–256 bytes
level yes integer -10–10. 0 = impression seen (not used for training); below 0 = the user explicitly rejected the item (rejections)
user_id no your stable user id; enables the server-side history fallback
anon_id no a device or visitor id (the JS SDK generates one)
recommendation_id no id of the recommendation that led to this event (attribution)
timestamp no RFC 3339 or unix ms; defaults to reception time. Older than 7 days is clamped to 7 days ago; more than 7 days in the future is replaced by the reception time. For past events, use POST /v1/events:import
event_id no idempotency key; duplicates within 2 minutes are dropped, and a batch retried with the same event ids within 2 minutes is not billed again (Billing)
value no what the buyer paid for this line of a purchase (after discounts, before shipping), a number of at least 0. Stored for the sales per visitor of a lift test; it never changes the recommendations
currency no the value's ISO 4217 code, three letters (EUR, usd), stored upper case. Needs a value
own no true marks an event of the shop's own browser (an owner testing the site). It is stored and billed, and left out of every number and list: the shop's own visits
context_item_id no the product page an event with no user_id and no anon_id came from on your shop: its id, else its address, as the page before allows. Ignored on other events, or when it is the event's item_id. 1–256 bytes.

A negative value, a currency that is not three letters or comes without a value puts the event in rejected, with its index and the field's name, as the other fields do. A value that is not a number refuses the whole batch with 400 invalid_request. A repeated event_id keeps the first event's amount only within 2 minutes of the first, as duplicates are dropped only then: a later repeat may be stored as a second event, with its own amount.

One rule for every platform: a purchase's value is what the line paid after its discounts, without tax or shipping where the platform keeps them apart, in the currency the buyer paid in (never converted). Refunds and cancellations after the purchase are not subtracted. A line whose price can't be read goes without an amount, never without its purchase.

Source value
WooCommerce plugin the line's total after discounts (WooCommerce stores it without tax)
Magento module the order item's row total less its discount (row totals are without tax)
Shopify pixel the line's final price after its discounts, as the checkout reports it
Shopify orders export Lineitem price × Lineitem quantity less Lineitem discount

Shopify doesn't split a line's tax from its price in either place: a shop whose prices include tax (most shops in Europe) sends amounts with tax, one whose prices exclude it sends them without.

Interaction levels

Any integer 0–10 is accepted for an interaction (below 0 is a rejection), but the defaults (the dashboard's conversion level, the demo data, the examples in these docs) assume this scale. It is the same for every kind of catalog; only the user actions you map onto it change:

Level Meaning Shop News Video and music Games
0 shown only: an impression (not used for training)
1 light interest, short of opening the item quick view headline hover preview on hover trailer preview
3 opened the item, including a click on a recommendation product page view article opened play started game page view
5 strong interest added to cart read to the end half watched or listened added to a wishlist
10 the action that matters most to you purchase shared or subscribed completed or liked installed or bought

The dashboard counts attributed events at the conversion level (5 by default) and above as conversions (set in Settings), so a click must be sent as an open (3), not as 5: otherwise the conversion rate is just a second click rate.

A conversion counts when the user clicked the recommended item first: an earlier attributed event on the same item below the conversion level, or a level-5 event (an add to cart or to a wishlist) straight from the list. A level-10 event that carries the id with nothing before it does not count.

For the same reason, an item that is merely displayed, in a list or in a recommendation widget, is level 0: every event above 0 on a recommended item counts as a click and is used for training. Use the free levels for your own events: 2 or 4 for milder interest (a bookmark, a quarter of a video), and 6–9 only for events that should count as conversions.

The libraries take names too: track(itemId, 'view'), 'cart' and 'purchase' send 3, 5 and 10. They are shop words for the same three levels; any catalog can pass the integers instead (track(itemId, 5) for an article read to the end). 'reject' sends -10 (see below). The API itself only accepts the integers.

Rejections

A negative level (-1 to -10) means the user explicitly rejected the item: a "not interested", "don't show me this" or thumbs-down control. recapi then never recommends that item to the user again, whatever the seen-items setting, until a later positive event (level 1 or more) on the same item. The item also stops counting in the user's history. Send an explicit rejection only: a skip, a bounce or a quick scroll past is not a rejection, and sending one as a negative level hides items the user may well want. The size of the level is stored, but today every negative level has the same effect, so -10 is fine.

Through the stored history (a call with a user_id and no history), a rejection counts once it is stored, about a second after POST /v1/events accepts it. A call that reaches another API node than the event did may still show the item for up to 10 seconds (see Freshness). The libraries apply it at once: they send the user's rejections in exclude, below.

Rejections are not used for training, and the dashboard counts them as neither a click nor a conversion, even with a recommendation_id. It shows them apart, as rejected per 1,000 recommendations for each experiment arm: the items of a list that a rejection carrying its recommendation_id names, each item of a list once. The libraries add the id to a rejection of an item shown in the last 30 minutes, as they do for a click. They also keep the user's newest 200 rejections and send them in exclude. Without a library, do the same in your own exclude. The stored history (below) keeps the newest 200 rejections from the user's last 90 days of events.

The dashboard's metrics per recommendation follow from the levels: clicked if an event at level 1 or more carries its recommendation_id (or comes without one and is credited to it, as under Attribution above), converted if one is at the conversion level or more on an item the user clicked first (as above), and weight per recommendation is the sum of those events' levels. Experiment verdicts need at least 1,000 recommendations and 30 clicks per arm (30 conversions for the conversion lift).

Response and new items

At least one of user_id/anon_id is recommended (events without either are stored for statistics but not used for training).

Response 202:

{ "accepted": 1, "rejected": [ { "index": 3, "error": "level must be an integer from -10 to 10" } ] }

Invalid events are listed in rejected (by position in the batch) and the rest are accepted. A batch that would exceed the monthly quota fails as a whole with 429 quota_exceeded, and nothing is stored.

Visitors sent with a public key

Your public key is in your pages' source, and an event's visitor is the id it carries. So events sent with a public key from one address add only a few visitors to your popular and trending lists, and the rest of the batch can't buy your bestseller with made-up visitors:

  • One batch holds at most 5 visitors (user_id, else anon_id). Events of a sixth are listed in rejected and not billed. A browser or app batch holds one visitor, or two around a login, so the libraries never hit this. Send many visitors' events from your server, with the secret key.
  • One address adds at most 20 visitors an hour and 20 a week to a new or small shop. A busy shop's address may add more, in step with the shop's own traffic, so shoppers behind one office or mobile network keep counting: a fifth of the shop's visitors in an average hour, an hour, and 8% of its week's past the first 500, a week. A visitor counts once per hour, as popular counts them, and an event with no id counts as a visitor of its own. Past that, the events are dropped: the answer is still 202 and counts them in accepted, but they are not stored nor billed.
  • Events at level 0 or below are never dropped: no list counts them.
  • Your dashboard's Your data page says how many events these two limits left out in the last 7 days, and what to change.

Neither limit applies to the secret key. They raise the cost of forging visitors rather than closing it: someone with many addresses gets through.

Unknown item_ids are created automatically with no tags. With Closed catalog enabled in the dashboard settings, they are created inactive until you describe them with PUT /v1/items/{item_id}, so anyone holding your public key cannot make items recommendable.

Events create at most 50,000 items per environment on the free plan and 200,000 on the paid plan: every API node keeps every item in memory, so made-up ids must not grow it without bound (what one server holds). Past that cap an event naming an unknown item is still accepted, stored and billed as usual, but the item is not created, so it can't be recommended until you send it. Items you send with PUT /v1/items, POST /v1/items:batch, the dashboard's upload or a platform's catalog sync never count toward the cap and are never refused, and an item events created stops counting once you send it. The dashboard's Home warns from 80% of the cap ("Items created from events").

From 80% of the cap, an item events created is removed once it was first seen more than 90 days ago and no event has named it for 90 days. An event imported today counts as naming its item today. A shop that someone filled with made-up ids gets its room back on its own. Items you sent are never removed, nor any item of an environment below 80% of its cap. An event naming a removed item creates it again, under the cap.

POST /v1/events:import — secret key

Loads a shop's past events (orders, cart adds, product views from the months before it joined) with their real dates, so recapi trains on them in its next hourly run instead of waiting for weeks of live traffic. Send the catalog first with POST /v1/items:batch if you have one.

The body, limits (1000 events, 2 MB), per-event checks and response are those of POST /v1/events, with two differences: timestamp is required and kept as sent, and own is ignored. An event older than 90 days (the training window) or dated in the future is listed in rejected, never clamped. Send them oldest first, in batches of up to 1000:

{ "events": [ { "user_id": "cust-881", "item_id": "item_4471", "level": 10, "timestamp": "2026-08-14T09:30:00Z" } ] }

Without code, the dashboard's Your data page takes a CSV file of at most 20 MB with the header user_id,item_id,level,timestamp. Each level is any integer or one of view, cart and purchase; each timestamp is RFC 3339, unix seconds or unix milliseconds. Two more columns may follow, value and currency: the price the buyer paid for that line. It also takes Shopify's Orders, Products and Customers exports, and the file WooCommerce → recapi downloads.

Imported events are used for training (the next hourly run retrains once at least 200 events, and 5% of those the current model saw, have arrived), for the stored history of their users and for popular and trending, but not as live traffic: Home, the quick start, the data checks, attribution and experiments count only events sent to POST /v1/events, so an import never makes the integration look as if it works. They count against the monthly quota as ordinary events (pilots are complimentary).

An import doesn't store a purchase twice, so a batch can be sent again after an error:

  • An event with an event_id an earlier import stored, or an earlier event of the same batch, is skipped. Give each event an id drawn from your own records (an order line's, say), the same on every send; an event without one is stored again.
  • A purchase dated since your first live purchase is paired with a purchase of the same item that POST /v1/events received within 10 minutes of it, each with one at most, and the paired one is skipped: an import of orders the site already sent live adds none.

The response adds skipped, the number of events among accepted that were not stored for either reason (these are not metered). If those stores can't be read, the batch gets 503 unavailable and nothing of it is stored: send it again.

Ten events count as one request against your shop's request rate, as on POST /v1/events: an import loads up to 20,000 events a second, a million past events in under a minute. Faster, a batch gets 429 rate_limited: wait the Retry-After second and send that batch again (nothing of it was stored).

PUT /v1/items/{item_id} — secret key

Create or replace an item.

{ "tags": ["sports", "football"], "active": true, "published_at": "2026-10-20T00:00:00Z", "boost": 0.0, "title": "Cup final highlights",
  "metadata": { "name": "Cup final highlights", "picture": "https://cdn.example.com/cup.jpg", "url": "https://example.com/cup", "price": 0 } }
  • tags: up to 32 tags, lowercase [a-z0-9:_-], 1–64 chars (duplicates are dropped).
  • active (default true): inactive items are never recommended.
  • published_at: RFC 3339 string, used for the new-item boost; defaults to first time seen.
  • boost: merchandising multiplier in [-1, 10]; final score × (1 + boost).
  • title: optional display name shown in the dashboard, up to 512 bytes.
  • metadata: optional JSON object of your own (name, picture, link, price, anything), returned with the item in every recommendation and popular list, so you can show a list without looking the items up. See Item metadata.
  • item_id may be repeated in the body but must then match the URL.

This is a full replace: fields you omit go back to their defaults (no tags, active, no boost, no title, no metadata), so always send the complete item. To change some fields and keep the others, use PATCH.

Response 200 with the stored item:

{ "item_id": "item_4471", "tags": ["sports", "football"], "active": true, "title": "Cup final highlights",
  "boost": 0, "published_at": "2026-10-20T00:00:00Z",
  "first_seen_at": "2026-10-18T09:12:44Z", "updated_at": "2026-10-23T12:00:00Z" }

first_seen_at is kept when an item is replaced. updated_at moves only when a field actually changes, so re-sending your whole catalog on a schedule is cheap: unchanged items are not written again, nor billed. The quota is checked on the items a call creates or changes: once a free plan's item writes are used up, re-sending an unchanged item still returns 200. title, published_at and metadata are omitted when not set.

Item metadata

metadata is any JSON object: its keys and values are yours, and recapi never reads them to rank items. It comes back as the item's metadata in GET /v1/items/{item_id}, in every POST /v1/recommendations item (all slots) and in every GET /v1/popular item. An item without metadata has no metadata field.

  • Up to 2,048 bytes written as compact JSON (no spaces outside strings): a longer one is refused with 400 invalid_request (metadata must be at most 2048 bytes as compact JSON, got 2311). Your own indentation doesn't count. Numbers count as recapi stores them, in plain decimal: 1.5e2 comes back as 150 and 1e-3 as 0.001, so 1e3000 is a 3,001-byte number and is refused (… got 3007 with its numbers written out). A number beyond what can be stored at all (an exponent of a billion) is refused with metadata has a number out of range.
  • It must be an object (not a list, string or number), valid UTF-8, and no string or key may contain the character \u0000.
  • null and {} mean no metadata. Key order and spacing are not kept: {"b":1, "a":2} may come back as {"a":2,"b":1}, and re-sending the same object written differently is not a change.
  • A PUT stores a key set to null as null; a PATCH removes that key.
  • It is public: lists go to public keys, so anyone visiting your site can read it. Put only what you would show on the page in it (no cost price, stock source or supplier).
  • A number list_price above a number price is shown struck through before the price on the cards recapi draws, as a sale's old price (the ready row).
  • On Shopify, the dashboard's upload of the products export sets name, url, picture, price and, on sale, list_price (Shopify) for each product, the keys the theme snippet draws a card from, and keeps any other key you set (overview). The product webhooks set the same keys and available (see below).

Why 2,048 bytes: every API node keeps the catalog in memory to answer in a few milliseconds, and metadata costs exactly 1 KB of memory per KB of metadata (measured by BenchmarkMetadataMemory in the catalog package: 414 B per item without it, 1,438 B with 1 KB, 2,462 B with 2 KB). A name, picture link, page link and price take about 300 bytes. See what one server holds for what a node holds.

PATCH /v1/items/{item_id} — secret key

Change only the fields the body sends; the others keep their stored values. A job that syncs tags alone sends { "tags": ["sale"] } and the item keeps its title, metadata, boost and the rest. metadata changes key by key, so a price sync keeps the product's name, picture and link:

curl -X PATCH "$RECAPI_URL/v1/items/item_4471" -H "Authorization: Bearer $RECAPI_KEY" \
  -H "Content-Type: application/json" -d '{"tags": ["sale"], "metadata": {"price": 12}}'
  • The fields and their limits are those of PUT; only the fields sent are checked.
  • A field sent as null goes back to its default ("boost": null is 0).
  • metadata sets the keys it sends and keeps the other stored keys. Only top-level keys merge: a key whose value is an object is replaced whole. A key sent as null is removed ({"metadata": {"old_price": null}}), "metadata": null removes all of it, and "metadata": {} changes nothing.
  • The 2,048-byte cap applies to the merged object: keys that would take it over are refused with 400 invalid_request (metadata must be at most 2048 bytes as compact JSON once merged with the stored keys, got 2069) and nothing is changed. Remove keys you no longer need in the same call.
  • An unknown item is created, with the defaults for what the body leaves out and the metadata keys it sends, minus the ones sent as null.

Response 200 with the stored item, as for PUT, and billed the same way: a merge that changes nothing is free.

POST /v1/items:batch — secret key

{ "items": [ { "item_id": "item-1", "tags": ["a"] }, { "item_id": "item-2", "active": false } ] }

Up to 1000 items, each with the same fields (metadata included) and replace semantics as PUT. With "merge": true next to items, each item changes only the fields it sends, as PATCH does, metadata key by key: { "merge": true, "items": [ { "item_id": "item-1", "metadata": { "price": 12 } } ] }. An item whose merged metadata would pass the 2,048-byte cap is listed in rejected, and the others are stored.

Response 200:

{ "upserted": 999, "rejected": [ { "index": 3, "error": "boost must be between -1 and 10" } ] }

Invalid items are listed in rejected (by position in the batch, as events are) and the others are stored: one bad product doesn't keep a sync of 1,000 out of date. upserted counts the items stored. A body that isn't JSON, or holds no items or more than 1000, fails as a whole with 400, and a batch whose changes exceed the quota fails as a whole with 429. Each item created or changed is billed as one item_write; one sent exactly as stored, or rejected, is free.

GET /v1/items/{item_id} — secret key

Returns the stored item (same shape as the PUT response), or 404 not_found. Not billed.

DELETE /v1/items/{item_id} — secret key

Marks the item inactive (history and statistics are kept). Response 204 with no body, also when it is already inactive, or 404 not_found for an unknown item. Send the item again with PUT to reactivate it. Billed as one item_write.

POST /v1/shopify/webhooks — Shopify's product webhooks

?key=<public key>. The address a Shopify shop gives the webhooks it creates in its admin (Settings → Notifications → Webhooks, format JSON) for Product creation, Product update and Product deletion; the dashboard's quick start shows it with the key and saves the secret Shopify signs them with. A delivery whose X-Shopify-Hmac-Sha256 is not the base64 HMAC-SHA256 of its body under that secret gets 401 unauthorized, as does any delivery while no secret is saved.

Signed deliveries are not counted in the limit per visitor address on public keys, since Shopify sends every shop's webhooks from a few servers. Refused deliveries are: past 600 a minute from one address, the next get 429 rate_limited.

  • products/create and products/update write the item as the products export does: the handle as item_id, the title, the type, the category's last level and the tags as tags, and name, url, picture, price merged into its metadata (other keys, the boost and published_at are kept). It is active when the product's status is active and it is published on the online store. Its metadata's available is false when every variant is out of stock and not sold when out of stock: Shopify no longer says whether a variant's stock is tracked, so the theme snippet then looks the product up rather than hiding it. When its handle changed, the item of the old handle is made inactive.
  • products/delete makes the product's item inactive.
  • Deliveries of one product apply in the order of its updated_at: one older than the last applied (a delivery overtaken by a later one) changes nothing. One with the same updated_at is applied, since Shopify may not move it on a variant or stock change; a retry of the same delivery then changes, and bills, nothing.
  • Other topics, and a handle longer than an item_id may be, are answered 200 { "ignored": "topic" } or { "ignored": "handle" } and not applied: Shopify retries anything else for hours.

Response 200 { "written": 1, "stale": false }: written counts the items created or changed, each billed as one item_write; a quota exceeded answers 429, which Shopify retries.

POST /v1/shopify/products:seen — what a Shopify product page says

The theme snippet sends this from each product page, so a shop that never uploaded its products export still gets similar products by name: its products are named as visitors open them. A public or secret key; the snippet sends ?key=<public key> as text/plain.

{
  "products": [
    { "handle": "red-scarf", "title": "Red wool scarf", "type": "Scarves", "tags": ["Winter", "Gift Ideas"] }
  ]
}
  • 1 to 250 products per call (0 to 250 with page), the body at most 1 MiB. handle is required; title, type and tags are optional. Any other field (a link, a picture, a price, active) refuses the whole call with 400 invalid_request, as does malformed JSON.
  • The words are written as the products export writes them: the handle as item_id, the title (at most 512 bytes), the type then the tags as tags. A handle longer than an item_id may be is skipped and counted in ignored.
  • They only fill a product that nothing else described: one created by its views or by this call. A product written by the items API, the products export or a product webhook keeps its own title and tags, and any of those writes replaces what a page sent. Nothing but the title and tags is ever set: a product this call creates is created as a view would create it (inactive under Closed catalog, and counted against the limit on products that events create). A missing or empty title, or no tags, keeps the ones the product has: a page adds or replaces words, never erases them.

Anyone holding your public key, which is in your pages' source, can name a product your shop never described, and nothing else: they can't rename a product you sent, change a link, picture, price or active, or make a product recommendable under Closed catalog.

Response 200 { "written": 1, "ignored": 0 }: written counts the products named or renamed. Not billed; it counts against the request rate limit like any call.

Your shop's product list

A shop that only pasted the snippet has names for the products its visitors opened, not yet for the rest of its catalog. So while recapi has no product from a signed source (the items API, the products export, a webhook), the answer to a call without page may carry list_page:

{ "written": 1, "ignored": 0, "list_page": 2 }

It asks for that page of the shop's own product list, which every Shopify storefront serves at /products.json?limit=250&page=<n>. The snippet reads it once the browser is idle and sends it back, words only, with the page's number:

{
  "page": 2,
  "products": [
    { "handle": "blue-mug", "title": "Blue mug", "type": "Mugs", "tags": ["Kitchen"] }
  ]
}
  • page is 1 to 80, and the products are the page's, in the same fields as above (an empty page is allowed: it ends the list). The answer is { "written": …, "ignored": … }, never with list_page. Send it as an ordinary request, not a keepalive one: a page of 250 products with a few tags each passes the 64 KiB browsers allow a keepalive body.
  • Only the page recapi asked for may create products, under the same rules as above; any other page (sent twice, or out of turn) only renames products recapi already has.
  • recapi offers each page to one browser for 30 seconds, then to the next page view. The list ends after a page of fewer than 250 products, an empty page, page 80 (20,000 products), the limit on products that events create, or one page offered 30 times without arriving (a shop whose list browsers can't send on), and for good once a signed source sends a product: from then on no answer carries list_page. A product the list stops naming stays as it is: only the products export and the webhooks deactivate products.

Two cases worth knowing:

  • A product you deactivated or boosted through the items API keeps the words a page gave it before, and pages can no longer change them: your write made the product yours, so it no longer counts against the limit on products that events create. The products export or a webhook replaces those words.
  • A product that events or pages created and that you never wrote can still be renamed by a page while it is inactive. That changes nothing shown: an inactive product is never recommended.

One call per shop is handled at a time: a call that arrives while another of the same shop is still being written gets 429 rate_limited with Retry-After: 1, and nothing of it is written. The snippet sends the product, or the page of the list, again on a later view, so a refused call loses nothing.

POST /v1/products:seen — what any product page says

The JS library sends this on a product's first view in a browser, from the name and category the page prints for search engines (schema.org Product in JSON-LD or microdata, else Open Graph). So a site that never sent its products still gets similar products by name. On a page with none of them, the library of a site with no shop platform sends page_url alone. A public or secret key; the library sends ?key=<public key> as text/plain.

{
  "products": [
    { "id": "red-scarf", "title": "Red wool scarf", "category": "Accessories > Scarves",
      "page_url": "https://shop.example.com/products/red-scarf" }
  ]
}
  • 1 to 250 products per call, the body at most 1 MiB. id is the item_id and is required; title, category and page_url are optional. A card's field (name, url, image, price, list_price, available) or any other refuses the whole call with 400 invalid_request, as does malformed JSON.
  • The title is kept as on POST /v1/shopify/products:seen, the last level of the category as a tag. An id an item_id may not be is skipped and counted in ignored.
  • page_url is kept only when it is https on the host the call's Origin header names (a browser sends it), at most 2,048 bytes; else it is dropped and the words still count. Its fragment, utm_*, known click ids (gclid, fbclid, msclkid, …) and a visitor's session, currency and language keys (XTCsid, id_currency, lang, …) are dropped. Nothing returns it: no recommendation, no GET /v1/items. Once the shop confirms its site in Settings, recapi reads the card from that page itself (how).
  • Which products the words may name, the one call per shop at a time and the answer are those of the Shopify route; there is no product list relay here.

Anyone holding your public key can name a product your shop never described, and nothing else: they can't rename a product you sent, give it a link, picture, price or active, or make a product recommendable under Closed catalog.

POST /v1/recommendations

Try it on the demo shop

A real call, with the public key and catalog of our demo shop. That key only works for the demo: your own site takes your own key.

shell
curl -X POST 'https://api.recapi.io/v1/recommendations' -H 'Authorization: Bearer rk_pub_NzSPzTSaH0Xg9HAAzAMTiEA9VXxeEuIv' -H 'Content-Type: application/json' -d '{"placement":"demo_trending","count":4}'

Each card says why the API put it there (its reason code). The score behind it, model by model, needs a secret key: see explain mode.

{
  "user_id": "cust-881",
  "anon_id": "0d6c4c1e-…",
  "placement": "homepage",
  "count": 10,
  "tags_any": ["sports"],
  "tags_all": [],
  "exclude": ["item-1"],
  "context_item_id": "item_4471",
  "history": [["item_4471", 7.5132, 120], ["item-9", 3.0, 86400]],
  "recent": ["item-9", "item_4471"],
  "discovery": 0.5,
  "explain": false
}
Field Notes
history, recent the history a client library keeps, see the history spec. Preferred source. history takes up to 200 [item_id, weight] entries with weights 0–1e6 (repeated items are summed, the 50 heaviest are used); recent takes up to 50 ids (the newest 20 are used); age_seconds: below
user_id when history and recent are both empty, a secret-key call loads the stored history for this user (if enabled for the shop; never with a public key, why)
anon_id used for sticky A/B assignment when there is no user_id
placement name of a placement configured in the dashboard, [a-z0-9_-]{1,64} (default default). A name not configured serves with the default placement's settings and joins its running experiment, under its own name in the dashboard; two serve their own list instead: bought_together, a product page's second row, and recently_viewed, a home page's
count 1–100, default 10 (0 or omitted = default). The most a list holds: a narrow filter or small catalog may give fewer. A Bought together list is empty until shoppers have carted or bought two products together, and never filled with the shop's bestsellers or its newest items (strategies)
tags_any / tags_all only recommend items having any / all of these tags (up to 32 each)
exclude up to 500 item ids never to return. The context_item_id is always excluded, and so are items in the user's history (history, recent or the stored history) unless re-recommending seen items is enabled in the dashboard settings. Rejected items: below the table
context_item_id "similar items" mode: recommendations around this item ("bought together" on a Bought together placement, strategies)
discovery 0–1 override of the placement's discovery level (clamped to the shop's maximum, ignored when an experiment controls discovery)
explain secret key only: add a reason to every item (see below). With a public key the call fails with 403 forbidden. Billed as one recommendation like any other call
own true marks a list asked by the shop's own browser: it gets the shop's own list and joins no running test. It is billed like any call and left out of every number and list: the shop's own visits
placements, allow_repeats several lists in one call, billed as one: see below
mode accepted and ignored, kept for compatibility: don't send it. It is validated (exact or fast, anything else is a 400), but both values give the same results

A history entry's third value, age_seconds, is the number of seconds since the visitor last touched the item. It tells the server whether the call opens a visit: when every entry is over 30 minutes old and every recent id has an entry, a site whose own data keeps a list for the start of a visit serves that list. An entry without it may be from this visit. The libraries send it; send it too if you keep the history yourself.

A fourth value, max_level, is optional: the strongest level the visitor reached on the item (3 for a view, 10 for a purchase), an integer from 1 to 10. 0 or none means unknown. It tells a product the visitor opened from one they bought. The default lists start with one product opened earlier only when both age_seconds and max_level are known. A Bought together list on a product page keeps a pair the visitor opened or carted below 10, though seen (strategies); unknown counts as bought. The libraries send it when they know it.

In exclude, the libraries add the user's rejected items; the stored history's rejected items are always excluded.

Response

Response 200:

{
  "recommendation_id": "rec_01JBA7…",
  "items": [
    { "item_id": "item-77", "score": 0.912, "slot": "exploit", "why": "for_you",
      "metadata": { "name": "Rain coat", "picture": "https://cdn.example.com/77.jpg", "price": 89 } },
    { "item_id": "item-12", "score": 0.403, "slot": "explore", "why": "new" }
  ],
  "history": { "top": [["item_4471", 7.5132]], "recent": ["item_4471"], "rejected": ["item-5"], "as_of": 1761216000000 }
}
  • history: the stored history, for a server library to keep; see the history spec. A top entry may carry a third value, its max_level.
  • metadata: the item's metadata, absent when it has none.
  • why: the field to show your visitors. It says why the item is on the list, a reason code you turn into a label ("Trending now", "Similar items"). score and slot are for your own code, not for display.
  • slot: exploit (personalised), explore (discovery), backfill (popular items in the filter, then other matching items, recently added ones first, so the list is full; that order is not guaranteed).
  • score depends on the slot: the relevance score for exploit (only comparable within one response), the estimated click rate for explore, and 0 for backfill. Keep the returned order rather than sorting by score: explore items sit at the positions chosen for them.
  • history is only present when the server-side history was used, which only a secret-key call does (why). To restore a device's history after login, have your backend call GET /v1/users/{id}/history?anon_id=… (the device's own anonymous id) and pass it to the SDK (identify(userId, { history })).
  • Send recommendation_id back on events about these items.

Several lists in one call

A page with several rows (the product page's similar items, "bought together" and "for you") asks for them in one call with placements, and gets one list per placement, in the same order:

{
  "user_id": "cust-881",
  "history": [["item_4471", 7.5132, 120]],
  "exclude": ["item-1"],
  "placements": [
    { "placement": "product", "count": 4, "context_item_id": "item_4471" },
    { "placement": "cart", "count": 4, "tags_any": ["accessories"] }
  ]
}
{
  "lists": [
    { "placement": "product", "recommendation_id": "rec_01JBA7…", "items": [ … ] },
    { "placement": "cart", "recommendation_id": "rec_01JBA8…", "items": [ … ] }
  ]
}
  • The call is billed as one recommendation, however many lists it asks for (1 to 10), and the history is sent and read once.
  • Against your shop's request rate, each list counts as one request, as if it were asked alone: a call of 4 lists costs 4. A call the rate can't cover gets 429 rate_limited with Retry-After: 1; no list of it is built or counted and it is not billed. A call of 10 lists always gets through on a rate that hasn't been used for 2 seconds.
  • Each placement takes placement, count, context_item_id, tags_any, tags_all, exclude and discovery, with the same rules as above. With placements, these fields are refused at the top level (400), so a call never leaves you guessing which one counts. user_id, anon_id, history, recent, explain, own and the top-level exclude (applied to every list) are shared.
  • An item is never on two lists of the call: each list leaves out the items of the lists before it, so put the most important row first. One exception: a Bought together list keeps the products shoppers carted or bought with the item, and the lists before it leave those out instead (of two such lists, the first keeps them). "allow_repeats": true lets each list pick freely.
  • Each list has its own recommendation_id and is counted in the dashboard, and in its placement's experiment, as a call for that placement alone would be: send each list's id back on events about its items. Items carry the same fields as above, and history comes back once, under the same conditions.
  • A call without placements answers exactly as before.

The libraries' recommendLists (recommend_lists, RecommendLists) sends it; when recapi can't answer, each list falls back to popular items as recommend does, still without repeats.

Reason codes

Every item of POST /v1/recommendations and GET /v1/popular carries a why, with any key and at no extra cost. It names a kind of reason, never an item of the visitor's history, so it is safe to show to anyone. Map the codes you want to your own words, and show no label for a code you don't know: new codes may be added.

why The item is listed because… A label you could show
for_you it matches the visitor's history (history, recent or the stored history) Picked for you
similar it is close to the item on screen (context_item_id): bought or viewed with it, or sharing its tags or a similar name Similar items
next visitors go on to it after what this visitor just viewed Up next
bought_together shoppers carted or bought it with the item on screen or with the visitor's items (a Bought together placement, see strategies) Often bought together
trending its popularity is rising right now Trending now
popular it is among the shop's most popular items Popular
new it was added recently and is being shown to its first visitors New
explore few visitors have seen it yet: discovery gives it a chance Something different
more it fills the list: an item without statistics yet, recently added ones first; when nothing else is left, one the visitor already opened (backfill) You may also like
viewed_earlier the visitor opened it over 30 minutes ago and has not bought it: first in the default lists where the site's run keeps it; from a stored history, on secret-key calls only (when); every product of a Recently viewed row but its fill You looked at this

For any exploit item but viewed_earlier, the code names the signal that weighed most in its score: items liked together give similar with a context_item_id and for_you without, the next step of other visits gives next, carts and purchases together give bought_together, and popularity gives popular or trending.

An explore item is new while it is a new item within its impression budget, else explore. A backfill item is similar (a product whose name, tags and metadata are close to those of a context item few visitors opened, or a popular item sharing the context item's tags), popular, or more. Every item of GET /v1/popular is popular, except the newest-items fill (score 0), which is more.

Explain mode

With "explain": true (secret key only) every item also carries a reason:

{ "item_id": "item-77", "score": 0.912, "slot": "exploit", "why": "for_you",
  "reason": { "because": ["item_4471"] } }
Field Meaning
because up to 3 items from history, recent, context_item_id or the stored history that led to the item most, most influential first. Empty when popularity alone listed it, and for explore and backfill items

because reveals the user's history, so like history it is never returned to public keys: show your visitors the why code instead.

Until 24 November 2026 reason also held generators, adjustments and start_blend, which named recapi's internal models and their weights. They were removed, the one exception to this API only growing, while no shop used them.

GET /v1/popular

Try it on the demo shop

A real call, with the public key and catalog of our demo shop. That key only works for the demo: your own site takes your own key.

shell
curl 'https://api.recapi.io/v1/popular?count=4' -H 'Authorization: Bearer rk_pub_NzSPzTSaH0Xg9HAAzAMTiEA9VXxeEuIv'

Query: tags_any=a,b, tags_all=c (comma-separated, up to 32 each), count=10 (1–100), key=rk_pub_….

{ "items": [ { "item_id": "item-77", "score": 1.0, "slot": "backfill", "why": "popular", "metadata": { "name": "Rain coat" } },
             { "item_id": "item-12", "score": 0.81, "slot": "backfill", "why": "popular" } ] }

Each item carries its metadata when it has some, and a reason code: popular, or more for the newest-items fill.

score is the item's popularity relative to the most popular item listed (1.0), which is the first one except on news-like catalogs (below). Only active items are returned. When fewer than count popular items match, the list is filled with other active items, recently added ones first (the order is not guaranteed), with score 0, so a new shop gets a full shelf before it has statistics.

On a news-like catalog (one with a learnt item lifetime), items published more than twice the lifetime ago come after the others, each group in popularity order, so a story weeks old no longer leads the list (or the libraries' outage fallback). An older item can then score higher than the fresh ones above it. Other catalogs keep the plain popularity order.

With ?key= the response is Cache-Control: public, max-age=60 (the key makes the cache entry shop-specific). With an Authorization header it is private, max-age=60 with Vary: Authorization. Non-personalised and ideal for empty histories.

GET /v1/users/{user_id}/history — secret key

Returns the server-side history snapshot for a user (same shape as the history field above), built from their last 90 days of events (at most 2000), with the anonymous browsing identify linked to them (Login). rejected lists the items the user rejected with no positive event on them since, oldest first. A user without events gets an empty top, recent and rejected, and so does every user while the Settings option for signed-in visitors is off: the libraries restore a user on a new device from here, the same fallback the setting turns off for recommendations. Not billed.

?anon_id= (optional) leaves out the anonymous-only events of that anonymous id. Pass the asking device's own one: the device holds that browsing already, and merging the snapshot would count it twice. The user's own events from that device stay. In a browser, the JS SDK's getAnonId() gives it. The server libraries pass it by themselves: their identify(anon_id, user_id) keeps the visitor's id until the user's first restore. An anon_id that breaks the id rule is 400.

DELETE /v1/users/{user_id} — secret key

Erases all events and impressions of the user (GDPR). The id is matched as a user_id and as an anon_id, and the anonymous browsing the user did before logging in goes too: the events and impressions that carried only an anon_id which the user's own events also carried, unless another user sent events under that anon_id (a shared device). Requests are queued and applied in batches: a first pass within about a minute, and a second pass ten minutes later for events that were still in transit. Response 202 { "status": "scheduled" }. Not billed.

GET /sdk/{version}/{file} — the JS SDK

The JS SDK's files, for sites without a bundler: one tag installs it (the dashboard's quick start shows it with your address).

<script type="module">
  import { createClient } from 'https://api.<your-domain>/sdk/0.36.0/index.js';
  // createClient({ apiKey: 'rk_pub_…', baseUrl: 'https://api.<your-domain>', consent: false }) …
  // and recapi.setConsent(true) from your cookie banner: until then nothing is stored on the device.
</script>

{version} is the SDK's version and {file} one of its modules. No API key, not billed. Responses are text/javascript, gzipped when the request accepts it, with Access-Control-Allow-Origin: * (browsers fetch module scripts with CORS), an ETag (a request whose If-None-Match names it gets 304 and no body) and Cache-Control: public, max-age=31536000, immutable (a version's files never change).

From 0.28.0 each entry file below is served joined: one file, without comments, holding every module it imports, with the same exports. Its source map is {file}.map (application/json, the entry's cache), holding the modules' text. The other modules are served as they are, importing each other by relative paths.

The exceptions are the current version's entry files, index.js, shopify.js (what a Shopify shop's pasted pieces import, from 0.10.0), woocommerce.js (what the WooCommerce plugin imports, from 0.12.0) and magento.js (what the Magento module imports, from 0.13.0): public, max-age=86400, stale-while-revalidate=604800, so a browser asks for them again after a day and finds any newer version, and a fix reaches a returning visitor about a day after it ships. An older version answers 302 to the same file of the current version, with public, max-age=86400, so a tag pasted long ago keeps working. Any other version or file is 404 not_found.

From 0.5.0 the SDK respects Do Not Track and Global Privacy Control by default: such a visitor's browser stores nothing and sends no events and no visitor ids, only requests for recommendations, which are then popular or similar items (Do Not Track).

GET /sdk/python/{file} — the Python library

The Python library as a wheel, so a server that can't reach PyPI (pip install recapi) installs it with pip from the API (the dashboard's quick start shows the line with your address).

pip install https://api.<your-domain>/sdk/python/recapi-0.4.17-py3-none-any.whl

{file} is recapi-{version}-py3-none-any.whl, at the library's current version. No API key, not billed. Responses are application/octet-stream with Cache-Control: public, max-age=31536000, immutable (a version's wheel never changes). An older version answers 302 to the current wheel, cached for a day, so a requirements file written long ago keeps installing (pip installs the current version). Any other file is 404 not_found.

GET /sdk/php/{file} — the PHP library

The PHP library's one file, so a site without Composer (composer require recapi/client) downloads it from the API (the dashboard's quick start shows the line with your address).

curl -fLo recapi.php https://api.<your-domain>/sdk/php/recapi-0.4.16.php

{file} is recapi-{version}.php, at the library's current version. No API key, not billed. Responses are the source as text/plain; charset=utf-8 (never run by the API), with Cache-Control: public, max-age=31536000, immutable (a version's file never changes). An older version answers 302 to the current file, cached for a day, so a deploy script written long ago keeps working with curl -L (it downloads the current version). Any other file is 404 not_found.

GET /sdk/java/{file} — the Java library

The Java library's sources as a zip, to unzip into a project's src/main/java when it can't reach Maven Central (io.recapi:recapi; the dashboard's quick start shows the URL with your address).

curl -fLo recapi-java.zip https://api.<your-domain>/sdk/java/recapi-java-0.2.17.zip

then unzip recapi-java.zip -d src/main/java.

{file} is recapi-java-{version}.zip, at the library's current version: the io/recapi/*.java files, sources only, and the META-INF/native-image/ files that a GraalVM native image needs (they go in src/main/resources, see the library's README). No API key, not billed. Responses are application/zip, with Cache-Control: public, max-age=31536000, immutable (a version's zip never changes). An older version answers 302 to the current zip, cached for a day. Any other file is 404 not_found.

GET /goproxy/recapi.io/go/… — the Go module

The Go library as the Go module recapi.io/go, for go get recapi.io/go, through the module proxy protocol: the website answers https://recapi.io/go?go-get=1 with <meta name="go-import" content="recapi.io/go mod https://api.recapi.io/goproxy">, so the go command, proxy.golang.org and sum.golang.org fetch the module from here, with no public repository.

curl https://api.<your-domain>/goproxy/recapi.io/go/@v/list
Path after /goproxy/recapi.io/go/ Response
@v/list the version the API serves, v{version} (the library's current version), text/plain
@latest, @v/v{version}.info {"Version": "v{version}", "Time": "…"}
@v/v{version}.mod its go.mod: module recapi.io/go and the library's go line
@v/v{version}.zip the module zip: go.mod, LICENSE and the recapi/*.go sources (no tests) at the module's root, package recapi

No API key, not billed. A version's .info, .mod and .zip never change (sum.golang.org keeps their hashes) and are cached with Cache-Control: public, max-age=31536000, immutable; list and @latest for 5 minutes. Any other path, an older version included, is 404 in plain text, which tells the go command to try its next proxy: an older version stays at proxy.golang.org, which keeps every version it fetched.

GET /sdk/go/{file} — the Go library

The Go library's sources as a zip, to unzip at a module's root as its package recapi: how it was installed before the module, still served for those installs.

curl -fLo recapi-go.zip https://api.<your-domain>/sdk/go/recapi-go-0.1.17.zip

then unzip recapi-go.zip.

{file} is recapi-go-{version}.zip, at the library's current version: the recapi/*.go files and recapi/LICENSE, no tests. No API key, not billed. Responses are application/zip, with Cache-Control: public, max-age=31536000, immutable (a version's zip never changes). An older version answers 302 to the current zip, cached for a day. Any other file is 404 not_found.

GET /sdk/swift/{file} — the Swift library

The Swift library as a Swift package in a zip, to unzip into a folder of a project, which then adds it with .package(path:), when it can't reach the package's git repository (the dashboard's quick start shows the URL with your address).

curl -fLo recapi-swift.zip https://api.<your-domain>/sdk/swift/recapi-swift-0.1.20.zip

then unzip -o recapi-swift.zip -d Vendor/Recapi and .package(path: "Vendor/Recapi") in Package.swift.

{file} is recapi-swift-{version}.zip, at the library's current version: Package.swift and the Sources/Recapi/*.swift files, no tests. No API key, not billed. Responses are application/zip, with Cache-Control: public, max-age=31536000, immutable (a version's zip never changes). An older version answers 302 to the current zip, cached for a day. Any other file is 404 not_found.

GET /sdk/ruby/{file} — the Ruby library

The Ruby library's one file, so an app that can't reach RubyGems (bundle add recapi) downloads it from the API (the dashboard's quick start shows the line with your address). Save it as lib/recapi.rb in a Rails app.

curl -fLo recapi.rb https://api.<your-domain>/sdk/ruby/recapi-0.1.21.rb

{file} is recapi-{version}.rb, at the library's current version. No API key, not billed. Responses are the source as text/plain; charset=utf-8 (never run by the API), with Cache-Control: public, max-age=31536000, immutable (a version's file never changes). An older version answers 302 to the current file, cached for a day. Any other file is 404 not_found.

GET /sdk/csharp/{file} — the C# library

The C# library's project in a zip, to unzip next to a .NET project that references it, when it can't reach NuGet (dotnet add package Recapi; the dashboard's quick start shows the URL with your address).

curl -fLo recapi-csharp.zip https://api.<your-domain>/sdk/csharp/recapi-csharp-0.1.17.zip

then unzip -o recapi-csharp.zip -d vendor and dotnet add reference vendor/Recapi/Recapi.csproj.

{file} is recapi-csharp-{version}.zip, at the library's current version: Recapi/Recapi.csproj and the Recapi/*.cs files, no tests. No API key, not billed. Responses are application/zip, with Cache-Control: public, max-age=31536000, immutable (a version's zip never changes). An older version answers 302 to the current zip, cached for a day. Any other file is 404 not_found.

GET /sdk/magento/{file} — the Magento 2 module

The Magento 2 module, with the PHP library inside as lib/recapi.php, as a zip to unzip into a store's app/code (the dashboard's quick start shows the lines with your address). Stores with Composer install the same module from Packagist instead, composer require recapi/module-recommendations; never both ways (Magento).

curl -fLo recapi-magento.zip https://api.<your-domain>/sdk/magento/recapi-magento-0.4.45.zip

then unzip recapi-magento.zip -d app/code.

With the secret key, the module describes the default store view's products itself: each product saved goes as one PUT /v1/items/{item_id} once the response is out (one try of at most 2 s, so a save never waits on recapi), and the whole catalog goes nightly and on bin/magento recapi:sync-catalog as POST /v1/items:batch of 1,000. Every item is complete: active only while the product is enabled, visible, in the website and in stock, its category names as tags, its creation date as published_at, and name, url, picture and price (base currency) as metadata, shrunk below 2,048 bytes (picture first, then the name).

Only items that changed are billed, so the nightly send of an unchanged catalog costs nothing.

See the module's README.

{file} is recapi-magento-{version}.zip, at the module's current version (its composer.json): the Recapi/Recommendations/ directory. No API key, not billed. Responses are application/zip, with Cache-Control: public, max-age=31536000, immutable (a version's zip never changes). An older version answers 302 to the current zip, cached for a day. Any other file is 404 not_found.

GET /plugins/woocommerce/latest.json — the WooCommerce plugin's updates

The WooCommerce plugin asks this API, the address in its Update URI header, for updates, inside WordPress's own update check (twice a day, a 3 s timeout: an outage offers nothing and slows no page for long). No API key, not billed.

{"version": "0.12.0", "plugin_version": "0.12.0",
 "package": "https://api.<your-domain>/plugins/woocommerce/recapi.zip",
 "requires": "6.3", "requires_php": "7.4", "tested": "7.1",
 "wc_requires": "8.3", "wc_tested": "11.3",
 "changes": "https://api.<your-domain>/plugins/woocommerce/changes"}

version is the plugin's Version header as served now: the library version, so it moves at every release. plugin_version is the version at which the plugin's own code last changed. An installed plugin offers an update only when plugin_version is newer than its code and version newer than its header. A release that changes only the library, or an older release, offers nothing. The plugin builds the package address from its own API address and public key, whatever package says. changes is the page below: WordPress's View version details link opens it. Cache-Control: public, max-age=300.

GET /plugins/woocommerce/changes — what each plugin update brings

What each version of the plugin's own code brings, newest first, in a few plain sentences, with a link to the guide's Updates section. WordPress opens it in a small window (600 by 800) on the Plugins screen, and adds ?TB_iframe=true&width=600&height=800, which the page ignores. No API key, not billed. text/html, Cache-Control: public, max-age=300.

Any site may frame it: Content-Security-Policy: … frame-ancestors *, and no X-Frame-Options. It holds no script, form or cookie, so a frame can't trick anyone into an action. Every page of the website still refuses frames.

GET /plugins/woocommerce/recapi.zip?key={public key} — the WooCommerce plugin

The plugin as the dashboard's quick start shows it, with the API's address and the shop's public key, as recapi/recapi.php in a zip: WordPress's Plugins → Add New → Upload Plugin takes it, and so does its one-click update. No API key, not billed: a public key is in every page of the shop. key must have a public key's exact shape (rk_pub_ and 32 letters or digits), or the answer is 400 invalid_request. Responses are application/zip, Cache-Control: public, max-age=300.

Health

These need no API key.

  • GET /healthz – process is alive (200, empty body).
  • GET /readyz – dependencies reachable: 200 or 503 with the state of each dependency, e.g. { "postgres": "ok", "clickhouse": "ok", "nats": "unavailable" }.
  • GET /.well-known/security.txt – 301 to the website's security.txt: how to report a security flaw privately.
  • GET /metrics – Prometheus metrics, served on a separate listener (RECAPI_METRICS_ADDR, default :9090, off to disable) that should only be reachable from your private network.