# Zigbongo documentation > Two calls from your server: ask which option to show, then report what it was worth. Start with a quickstart, then read the guides for the details. ## What Zigbongo does Zigbongo is a hosted API that sits behind the choices your product makes for each customer: an offer, the plan to lead with, a paywall, a trial length, an upsell, an onboarding step. At each of these decision points your server sends the options you have and the one you'd show today, and gets back the option to show. Later you report the outcome, such as revenue, and Zigbongo learns which options raise revenue per customer (ARPU). Each decision point keeps learning rather than running a fixed A/B test (a multi-armed bandit, and a contextual bandit when you send inputs): it starts from your default, moves traffic as the evidence builds, and measures the lift against a holdout, people who keep your defaults. It only chooses among the options you send. It never writes copy, sets prices or invents steps. More in [How it works](https://zigbongo.com/how-it-works/) and [Bandit vs A/B testing](https://zigbongo.com/bandit-vs-ab-testing/). ## Concepts - **Flow:** one place in your product where Zigbongo chooses for a customer, such as `checkout` or `onboarding`, named by a key you choose (1 to 128 letters, digits, `-`, `_` or `.`). A flow exists the first time your code asks about it. - **Decision point (node):** a place in a flow where your code asks Zigbongo to choose between options, such as `upsell`. A flow can have one or many. - **Option:** one of the choices at a decision point, named by a key, such as `none` or `annual`. You build every option; Zigbongo only decides which one to show. - **Default:** the option you'd show today. It's where learning starts, what the holdout always gets, what everyone sees while a flow is paused, and what the SDKs show when Zigbongo is slow or unreachable. - **Session:** one run of a flow for one customer, such as one visit to checkout, from its first decision to its outcome, however many decision points it has. A five-step quiz is one session, not five. Live sessions are what you pay for, after 10,000 free each month ([Pricing](https://zigbongo.com/pricing/)). - **Subject:** your own id for the person, such as their user id. Send the same one every time: it keeps their holdout assignment stable and lets you report outcomes per customer. - **Outcome:** what your app reports after Zigbongo chose, such as a purchase and its amount: revenue, margin, a renewal or a cancellation, as a number. You report it per session or per customer, and it counts when it happens within the flow's attribution window (one day by default). - **Holdout:** 5% of people keep your defaults, the same people for the life of the flow, so the lift is always measured against what you'd have done anyway, with a 95% interval. You can change the share per flow and per decision point. - **Lift:** how much more the customers Zigbongo chooses for bring than the holdout, per session. - **Environment and key:** each project has a live environment, for real customers, and a test environment, for development and staging. Each learns on its own, and test environments are free. An API key belongs to one environment, so the key you use decides where your calls go. Keys stay on your server. - **Input:** context you attach to a decision, such as plan, country, traffic source or an earlier answer. Inputs are flat strings, numbers and booleans, exact values or bands, and they let each group of customers get its own best option. ## The two calls Both calls come from your server, never from a browser or app. 1. **Decide** at each decision point: send the options, the default and, if you like, some inputs. You get back the option to show. Over HTTP, this is `POST /v1/flows/{flowKey}/decide`. 2. **Report the outcome** when you know it, minutes or weeks later: `POST /v1/outcomes`, per session or per customer. It counts within the flow's attribution window, one day by default and up to 90 days in the flow's settings. With the Node.js SDK: ```js import { Zigbongo } from "@zigbongo/sdk"; const zb = new Zigbongo({ apiKey: process.env.ZIGBONGO_KEY, baseUrl: "https://zigbongo.com" }); // 1. At the decision point const s = zb.session("checkout", user.id); const upsell = await s.decide("upsell", ["none", "annual"], "none"); show(upsell.option); // 2. Later, when they pay await s.outcome(invoice.total, invoice.id); ``` There is no schema and nothing to set up first. Registering a flow up front is optional: see [Registered flows](https://zigbongo.com/docs/registered-flows.md). Some safeguards are always on. The SDKs wait at most 150 ms for an answer; on a timeout or an error they show your default and report the fallback, which is never learned from. Pause a flow and within seconds everyone sees your default choices. ## For AI assistants and agents Every docs page is also plain Markdown, without the site around it: put `.md` in place of the trailing slash, so this page is [/docs.md](https://zigbongo.com/docs.md) and the Node.js quickstart is [/docs/quickstart/node.md](https://zigbongo.com/docs/quickstart/node.md). A request that asks for `text/markdown` gets the Markdown at the page's own address too. [llms.txt](https://zigbongo.com/llms.txt) lists every page with a sentence about it, and [llms-full.txt](https://zigbongo.com/llms-full.txt) holds all of them in one file, to give an assistant the whole of the docs at once. ## Where to go next Start with the quickstart for your language. Each one goes from an API key to a first decision and outcome in a free test environment: - [Node.js quickstart](https://zigbongo.com/docs/quickstart/node.md) - [PHP quickstart](https://zigbongo.com/docs/quickstart/php.md) - [HTTP quickstart](https://zigbongo.com/docs/quickstart/http.md), for any other language Then the guides: - [Sessions and outcomes](https://zigbongo.com/docs/sessions-and-outcomes.md): sessions over several decision points, and reporting outcomes per session or per customer. - [Holdout and lift](https://zigbongo.com/docs/holdout-and-lift.md): how the lift is measured, and when it's clear. - [Inputs](https://zigbongo.com/docs/inputs.md): sending context so each group of customers gets its own best option. - [Registered flows](https://zigbongo.com/docs/registered-flows.md): defining a flow's steps and routing up front. - [Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md): what happens when Zigbongo is slow or unreachable. - [Retries and rate limits](https://zigbongo.com/docs/retries-and-rate-limits.md): what to retry, and how long to wait. - [Pausing flows](https://zigbongo.com/docs/pausing-flows.md): the kill switch. - [Erasing customers](https://zigbongo.com/docs/erasing-customers.md): passing on a GDPR erasure request. - [Environments and keys](https://zigbongo.com/docs/environments-and-keys.md): live and test, and looking after your keys. Every call, field and error code is in the [HTTP API reference](https://zigbongo.com/docs/api.md). --- The Markdown of https://zigbongo.com/docs/. Every docs page: https://zigbongo.com/llms.txt # Node.js quickstart > From an API key to a first decision and outcome, in a free test environment. You need Node.js 22.12 or later and server-side code to call from. ## 1. Create a project and copy its test key 1. Sign in at [/signin/](https://zigbongo.com/signin/). If you don't have an account yet, the e-mailed sign-in link creates one. 2. Name your organization (usually your company) and accept the Terms of Service. 3. Create a project, such as "Checkout". It comes with two environments: **live**, for real customers, and **test**, for development and staging. 4. You land on the project's **API keys** page. Under **Test environment**, give the key a label if you like (such as "laptop") and select **Create key**. 5. Copy the key now: it's shown only once. It starts with `zb_`. The test environment is free, and it learns separately from live, so test traffic never sways live decisions. Keep the key on your server, for example in an environment variable. Never ship it in a browser or app. ## 2. Install the SDK The SDK is published to Zigbongo's npm registry on GitLab. Point the `@zigbongo` scope at it in your project's `.npmrc`, then install: ```sh echo "@zigbongo:registry=https://gitlab.com/api/v4/projects/87446139/packages/npm/" >> .npmrc npm install @zigbongo/sdk ``` No token is needed. Commit the `.npmrc` line with your project, so `npm ci` finds the SDK in CI and image builds too. To upgrade, run `npm install @zigbongo/sdk@latest`. The SDK needs Node.js 22.12 or later and has no runtime dependencies. It's an ES module, and `require("@zigbongo/sdk")` works from CommonJS too. The client refuses to start where `window` exists, since it carries your key. ## 3. Configure it from the environment Set `ZIGBONGO_KEY` where your server runs: ```sh export ZIGBONGO_KEY="zb_..." ``` Create one client when your server starts, and reuse it for every request: ```js import { Zigbongo } from "@zigbongo/sdk"; const zb = new Zigbongo({ apiKey: process.env.ZIGBONGO_KEY, baseUrl: "https://zigbongo.com", }); await zb.warm(); ``` `warm()` opens the client's connection to Zigbongo before your first visitor's request, so their decision doesn't wait for it, and checks the key. It never throws: an error goes to `onError` instead (see [Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md#the-connection-and-warm)). ## 4. Make your first decision Pick a choice your product already makes. In this example, the checkout can offer an annual upgrade, and today it doesn't: ```js const s = zb.session("checkout", user.id); const upsell = await s.decide("upsell", ["none", "annual"], "none"); if (upsell.option === "annual") { // show the annual upgrade } ``` - `"checkout"` is the flow. It's created the first time you ask about it, so there's nothing to register. - `user.id` is the subject: your own id for this customer, a string or an integer. Send the same id every time. An integer is sent as its text, so `42` and `"42"` are the same customer. - `"upsell"` is the decision point, `["none", "annual"]` are its options, and `"none"` is the default, the option you show today. `decide()` resolves to a decision: | Field | What it holds | |---|---| | `option` | The option to show. | | `arm` | `optimised` when Zigbongo chose, `holdout` when this customer keeps your defaults, `paused` when the flow is paused, `fallback` when the SDK fell back. | | `fallback` | `true` when the SDK returned your default because Zigbongo didn't answer in time or failed. | | `sessionId` | The session. `s` keeps it for its next calls. | | `decisionId` | This decision. | Zigbongo starts from your default: at first your customers mostly see what they see today, and traffic moves as the evidence builds. `decide()` never throws. If Zigbongo doesn't answer within 150 ms, can't be reached or answers with an error, you get your default back with `fallback: true`, and the SDK reports the fallback in the background so that decision is never learned from. In a serverless function, call `await zb.flush()` before it returns, so the report goes out. To log what the SDK absorbed, pass an `onError` function to the client. The details are in [Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md). ### More decision points in one session If the flow has more choices, call `s.decide()` at each one. `s` keeps the session id, so they all count as one session, however many there are. In its last argument, `s.decide()` also takes a `result` describing what happened at the previous decision point, such as the answer given: see [Sessions and outcomes](https://zigbongo.com/docs/sessions-and-outcomes.md). ### Context, if you have it Send what you know about the customer as inputs, so each group of customers can get its own best option: ```js const upsell = await s.decide("upsell", ["none", "annual"], "none", { inputs: { plan: "starter", country: "LT", source: "newsletter" }, }); ``` Inputs are flat: strings, numbers, booleans or `null`, raw or bucketed. They add up over the session. See [Inputs](https://zigbongo.com/docs/inputs.md). ## 5. Report the outcome When the customer pays, report what it's worth. You can do it per session or per customer. **Per session**, when the code that sees the payment still has the session: ```js await s.outcome(invoice.total, invoice.id); ``` **Per customer**, when it doesn't, such as in your payment provider's webhook or for a renewal a month later: ```js await zb.outcome({ outcomeId: invoice.id, flowKey: "checkout", subjectId: user.id, value: invoice.total }); ``` - `value` is a number: revenue, margin, or 1 for a renewal. Higher is better unless you change that in the flow's settings. - `outcomeId` is your own id for the outcome, a string or an integer, such as the invoice id. Reporting it again is harmless: nothing counts twice, and the call usually resolves to `duplicate` (it may read `accepted` when the repeat reaches another of Zigbongo's servers). It's unique across the environment, not per flow, so if you report one payment to two flows, give each report its own id. - An outcome counts when it happens within the flow's attribution window: one day from the session's start, by default. For renewals or churn, make the window longer in the flow's settings (up to 90 days). - `outcome()` resolves to `accepted` or `duplicate`. It retries timeouts, rate limits (429) and server errors, waiting as long as Zigbongo asks, up to 10 seconds in all, and throws a `ZigbongoError` otherwise. For example, its `code` is `invalid_input` for a flow key that isn't valid, such as one with a space in it. An outcome for a flow that has had no decision yet is accepted, and changes nothing. ### Which one to use Report **per session** when the outcome belongs to one run of the flow and you can carry that session to where the outcome happens, such as the purchase at the end of a checkout. It counts for that session only. In a later request, use the `sessionId` you kept from the decision (on the order, say): ```js await zb.outcome({ outcomeId: invoice.id, flowKey: "checkout", sessionId: order.zigbongoSessionId, value: invoice.total }); ``` A decision that fell back before any session started has a `sessionId` of `null`: report that customer's outcome per customer instead. `s.outcome()` does this for you. Report **per customer** when you only know who it was: a webhook, a renewal, a cancellation. The outcome counts towards each of that customer's sessions in the flow whose attribution window it falls in, so send the same `subjectId` you sent with the decision. ## 6. See it in the dashboard Open the project's **Flows** page and switch it to **Test**. `checkout` is listed after its first decision, marked "optimizing". Open it to see: - how many sessions it has had, and when the report was last updated; - the value per session of the customers Zigbongo chooses for against the holdout's, with a 95% interval, once each side has enough sessions with an outcome (the page says how many it's waiting for); - each decision point's options, their share of traffic, and how often the SDK fell back. Sessions whose attribution window is still open show as pending. On the **API keys** page, each key shows when it was last used, and by which SDK. ## 7. Switch to the live key When it works in test: 1. On the project's **API keys** page, under **Live environment**, create a key and copy it. 2. Set `ZIGBONGO_KEY` to it on your production servers. The code doesn't change: the key decides the environment. The live environment learns on its own, starting from your defaults, and its flows appear on their first live decision. Live sessions count towards your usage: 10,000 free every month, then €4 per 1,000, excluding VAT (see [Pricing](https://zigbongo.com/pricing/)). Keep the test key for development and staging. ## Next - [Sessions and outcomes](https://zigbongo.com/docs/sessions-and-outcomes.md): sessions across requests, step results and attribution. - [Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md): `onError`, `flush()` and what the SDK does on failure. - [Holdout and lift](https://zigbongo.com/docs/holdout-and-lift.md): reading the report. - [Environments and keys](https://zigbongo.com/docs/environments-and-keys.md): revoking and rotating keys. --- The Markdown of https://zigbongo.com/docs/quickstart/node/. Every docs page: https://zigbongo.com/llms.txt # PHP quickstart > From an API key to a first decision and outcome, in a free test environment. You need PHP 8.1 or later with the curl extension. ## 1. Create a project and copy its test key 1. Sign in at [/signin/](https://zigbongo.com/signin/). If you don't have an account yet, the e-mailed sign-in link creates one. 2. Name your organization (usually your company) and accept the Terms of Service. 3. Create a project, such as "Checkout". It comes with two environments: **live**, for real customers, and **test**, for development and staging. 4. You land on the project's **API keys** page. Under **Test environment**, give the key a label if you like (such as "laptop") and select **Create key**. 5. Copy the key now: it's shown only once. It starts with `zb_`. The test environment is free, and it learns separately from live, so test traffic never sways live decisions. Keep the key on your server, for example in an environment variable. Never ship it in a browser or app. ## 2. Install the SDK The SDK is published to Zigbongo's Composer registry on GitLab. Add it to your project's repositories, then require the SDK: ```sh composer config repositories.zigbongo composer https://gitlab.com/api/v4/group/144185712/-/packages/composer/packages.json composer require zigbongo/sdk ``` No token is needed. The first line leaves this in your `composer.json`, which you can also write yourself: ```json { "repositories": [{ "name": "zigbongo", "type": "composer", "url": "https://gitlab.com/api/v4/group/144185712/-/packages/composer/packages.json" }] } ``` `composer require` adds the latest release, and `composer.lock` keeps it. To upgrade, run `composer update zigbongo/sdk`. The SDK needs PHP 8.1 or later with the `curl` extension, and nothing else. ## 3. Configure it from the environment Set `ZIGBONGO_KEY` in the environment your PHP code runs in. From a shell: ```sh export ZIGBONGO_KEY="zb_..." ``` Then create the client, where your code needs it: ```php use Zigbongo\Zigbongo; $zb = new Zigbongo(apiKey: getenv('ZIGBONGO_KEY'), baseUrl: 'https://zigbongo.com'); ``` ## 4. Make your first decision Pick a choice your product already makes. In this example, the checkout can offer an annual upgrade, and today it doesn't: ```php $s = $zb->session('checkout', $user->id); $upsell = $s->decide('upsell', ['none', 'annual'], 'none'); if ($upsell->option === 'annual') { // show the annual upgrade } ``` - `'checkout'` is the flow. It's created the first time you ask about it, so there's nothing to register. - `$user->id` is the subject: your own id for this customer, a string or an int. Send the same id every time. An int is sent as its text, so `42` and `'42'` are the same customer. - `'upsell'` is the decision point, `['none', 'annual']` are its options, and `'none'` is the default, the option you show today. `decide()` returns a `Decision`: | Property | What it holds | |---|---| | `option` | The option to show. | | `arm` | `optimised` when Zigbongo chose, `holdout` when this customer keeps your defaults, `paused` when the flow is paused, `fallback` when the SDK fell back. | | `fallback` | `true` when the SDK returned your default because Zigbongo didn't answer in time or failed. | | `sessionId` | The session. `$s` keeps it for its next calls. | | `decisionId` | This decision. | Zigbongo starts from your default: at first your customers mostly see what they see today, and traffic moves as the evidence builds. `decide()` never throws. If Zigbongo doesn't answer within 150 ms, can't be reached or answers with an error, you get your default back with `fallback: true`. The SDK then reports the fallback, so that decision is never learned from. PHP has nothing running in the background, so reports wait in the client and go out when the script ends, when the client is destroyed or when you call `$zb->flush()`, within a second in all. Under PHP-FPM, finish the response first with `fastcgi_finish_request()` so nobody waits for them (Symfony and Laravel already do). In a long-running worker, call `$zb->flush()` after each job. The details are in [Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md). Before PHP 8.5, each request that decides opens a new connection to Zigbongo, and that counts towards the 150 ms. From PHP 8.5, the worker keeps its connection between requests. ### More decision points, across pages If the flow has more choices, call `$s->decide()` at each one: they all count as one session, however many there are. When each step is its own page, keep the session's ids between requests and carry on from them: ```php $s = $zb->session('checkout', $user->id, sessionId: $_SESSION['zb_session'] ?? null, lastDecisionId: $_SESSION['zb_last'] ?? null); $plan = $s->decide('plan', ['monthly', 'annual'], 'monthly'); $_SESSION['zb_session'] = $s->sessionId; $_SESSION['zb_last'] = $s->lastDecisionId; ``` `decide()` also takes a `result:` describing what happened at the previous decision point, such as the answer given, and the SDK attaches it to the decision in `lastDecisionId`. See [Sessions and outcomes](https://zigbongo.com/docs/sessions-and-outcomes.md). ### Context, if you have it Send what you know about the customer as inputs, so each group of customers can get its own best option: ```php $upsell = $s->decide('upsell', ['none', 'annual'], 'none', inputs: ['plan' => 'starter', 'country' => 'LT', 'source' => 'newsletter']); ``` Inputs are flat: strings, numbers, booleans or `null`, raw or bucketed. They add up over the session. See [Inputs](https://zigbongo.com/docs/inputs.md). ## 5. Report the outcome When the customer pays, report what it's worth. In PHP, that usually happens in another request: the confirmation page, or your payment provider's webhook. So report it **per customer**: ```php // in your payment handler $zb->outcome($invoice->id, 'checkout', $invoice->total, subjectId: $user->id); ``` ### Why per customer In PHP, the session object `$s` lives for one request: it, and the session id it holds, are gone once the page that made the decision has been sent. The request that sees the payment doesn't have them, but it does know who paid. An outcome reported per customer needs only that: it counts towards each of that customer's sessions in the flow whose attribution window it falls in. Send the same `subjectId` you used for the decision. The attribution window is one day from the session's start, by default. For renewals or churn, make it longer in the flow's settings (up to 90 days). ### Per session, if you keep its id To credit one session exactly, keep its id with the order when you decide, and report by it later: ```php // when deciding $order->zigbongo_session = $upsell->sessionId; // in your payment handler $zb->outcome($invoice->id, 'checkout', $invoice->total, sessionId: $order->zigbongo_session); ``` A decision that fell back before any session started has a `sessionId` of `null`: report that customer's outcome per customer instead. In the same request as the decision, `$s->outcome($invoice->total, $invoice->id)` reports per session, or per customer when there's no session. ### Good to know - `value` is a number: revenue, margin, or 1 for a renewal. Higher is better unless you change that in the flow's settings. - The outcome id (the first argument) is your own id for the outcome, a string or an int, such as the invoice id. Reporting it again is harmless: nothing counts twice, and `outcome()` usually returns `duplicate` (it may return `accepted` when the repeat reaches another of Zigbongo's servers). It's unique across the environment, not per flow, so if you report one payment to two flows, give each report its own id. - `outcome()` returns `accepted` or `duplicate`. It retries timeouts, rate limits (429) and server errors, waiting as long as Zigbongo asks, up to 10 seconds in all, and throws a `ZigbongoException` otherwise. Its `errorCode` is `invalid_input`, for example, for a flow key that isn't valid, such as one with a space in it. An outcome for a flow that has had no decision yet is accepted, and changes nothing. The waits hold the PHP worker, so report outcomes from a queued job where you can. ## 6. See it in the dashboard Open the project's **Flows** page and switch it to **Test**. `checkout` is listed after its first decision, marked "optimizing". Open it to see: - how many sessions it has had, and when the report was last updated; - the value per session of the customers Zigbongo chooses for against the holdout's, with a 95% interval, once each side has enough sessions with an outcome (the page says how many it's waiting for); - each decision point's options, their share of traffic, and how often the SDK fell back. Sessions whose attribution window is still open show as pending. On the **API keys** page, each key shows when it was last used, and by which SDK. ## 7. Switch to the live key When it works in test: 1. On the project's **API keys** page, under **Live environment**, create a key and copy it. 2. Set `ZIGBONGO_KEY` to it on your production servers. The code doesn't change: the key decides the environment. The live environment learns on its own, starting from your defaults, and its flows appear on their first live decision. Live sessions count towards your usage: 10,000 free every month, then €4 per 1,000, excluding VAT (see [Pricing](https://zigbongo.com/pricing/)). Keep the test key for development and staging. ## Next - [Sessions and outcomes](https://zigbongo.com/docs/sessions-and-outcomes.md): sessions across requests, step results and attribution. - [Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md): `onError`, `flush()` and the report timeout. - [Holdout and lift](https://zigbongo.com/docs/holdout-and-lift.md): reading the report. - [Environments and keys](https://zigbongo.com/docs/environments-and-keys.md): revoking and rotating keys. --- The Markdown of https://zigbongo.com/docs/quickstart/php/. Every docs page: https://zigbongo.com/llms.txt # HTTP quickstart > From an API key to a first decision and outcome with plain HTTPS requests, for any language without an SDK. You also build the timeout and fallback that the SDKs give you. ## 1. Create a project and copy its test key 1. Sign in at [/signin/](https://zigbongo.com/signin/). If you don't have an account yet, the e-mailed sign-in link creates one. 2. Name your organization (usually your company) and accept the Terms of Service. 3. Create a project, such as "Checkout". It comes with two environments: **live**, for real customers, and **test**, for development and staging. 4. You land on the project's **API keys** page. Under **Test environment**, give the key a label if you like (such as "laptop") and select **Create key**. 5. Copy the key now: it's shown only once. It starts with `zb_`. The test environment is free, and it learns separately from live, so test traffic never sways live decisions. Keep the key on your server, for example in an environment variable. Never ship it in a browser or app: every call to Zigbongo comes from your server. ```sh export ZIGBONGO_KEY="zb_..." ``` ## 2. Know the conventions Every call goes to `https://zigbongo.com/v1/...` with these headers: | Header | | |---|---| | `Authorization` | `Bearer $ZIGBONGO_KEY`. Without a valid key, the answer is `401`. | | `Content-Type` | `application/json`. Every body is JSON. | | `Idempotency-Key` | On decide calls: a new unique value for each call, such as a UUID (1 to 200 visible ASCII characters). | A field the service doesn't know is refused with `400 invalid_input`; only `result` takes fields of your own. Every answer carries an `X-Request-Id` header, which identifies the request if you ever need to ask about it. ## 3. Make your first decision Pick a choice your product already makes. In this example, the checkout can offer an annual upgrade, and today it doesn't. Ask which option to show with `POST /v1/flows/{flowKey}/decide`: ```sh curl https://zigbongo.com/v1/flows/checkout/decide \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 5b0e7c2a-3f61-4d8e-9a47-1c2b3d4e5f60" \ -d '{ "subjectId": "user_1842", "node": "upsell", "options": [{ "key": "none" }, { "key": "annual" }], "default": "none" }' ``` `checkout` is the flow. It's created by this first call, so there's nothing to register. Its key is 1 to 128 letters, digits, `-`, `_` or `.`. The body: | Field | | |---|---| | `subjectId` | Your own id for this customer, as a string. Required to start a session. On later calls of a session it's optional, and must match. | | `sessionId` | Leave it out on a session's first call. Send the `sessionId` you got back on its later calls. | | `node` | The decision point. | | `options` | The options, as objects with a `key` each. Keys are unique and not empty. | | `default` | The option you show today: one of the keys. | | `inputs` | Optional. Context about the customer, as a flat object of strings, numbers, booleans or `null`, such as `{ "plan": "starter", "country": "LT" }`. Inputs add up over the session; see [Inputs](https://zigbongo.com/docs/inputs.md). | | `holdoutPercent` | Optional. From 0 to 100: the share of customers who always get the default at this decision point. Zigbongo remembers it for the decision point until you send another. 5 if never sent. | | `result` | Optional, on a session's later calls: what happened at its previous decision, as an object with that decision's `decisionId` and any fields of your own, such as `"answer": "yes"`. | The answer is `200` with the option to show: ```json { "sessionId": "0f8b6a52-9c1d-4e3a-8b7f-2a6c5d4e3f21", "decisionId": "7d2e9f41-6b3a-4c5d-9e8f-1a2b3c4d5e6f", "option": "none", "arm": "optimised" } ``` | Field | | |---|---| | `sessionId` | The session. Send it with the session's later calls, and with outcomes per session. | | `decisionId` | This decision. Send it in the next call's `result`. | | `option` | The option to show. | | `arm` | `optimised` when Zigbongo chose, `holdout` when this customer keeps your defaults, `paused` when the flow is paused. | Zigbongo starts from your default: at first your customers mostly see what they see today, and traffic moves as the evidence builds. If Zigbongo receives the same `Idempotency-Key` again within 30 seconds, it answers with the decision it already made and changes nothing. A repeat that reaches another of its servers is decided again, but Zigbongo then learns from neither and counts the session once. The key is also how a fallback report finds its decision (see step 5). ### More decision points in one session If the flow has more choices, call `decide` at each one with the session's `sessionId`. They all count as one session, however many there are. If you like, `result` reports what happened at the previous decision: ```sh curl https://zigbongo.com/v1/flows/checkout/decide \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 9c4f1e2d-8a7b-4c6d-b5e4-3f2a1b0c9d8e" \ -d '{ "sessionId": "0f8b6a52-9c1d-4e3a-8b7f-2a6c5d4e3f21", "node": "addon", "options": [{ "key": "none" }, { "key": "priority_support" }], "default": "none", "result": { "decisionId": "7d2e9f41-6b3a-4c5d-9e8f-1a2b3c4d5e6f", "accepted": false } }' ``` See [Sessions and outcomes](https://zigbongo.com/docs/sessions-and-outcomes.md). ## 4. Report the outcome When the customer pays, report what it's worth with `POST /v1/outcomes`. **Per session**: ```sh curl https://zigbongo.com/v1/outcomes \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -d '{ "outcomeId": "inv_10023", "flowKey": "checkout", "sessionId": "0f8b6a52-9c1d-4e3a-8b7f-2a6c5d4e3f21", "value": 49.0 }' ``` Or **per customer**, with `subjectId` in place of `sessionId`: ```json { "outcomeId": "inv_10023", "flowKey": "checkout", "subjectId": "user_1842", "value": 49.0 } ``` | Field | | |---|---| | `outcomeId` | Your own id for the outcome, as a string, such as the invoice id. It's unique across the environment, not per flow: if you report one payment to two flows, give each report its own id. | | `flowKey` | The flow. It isn't checked against your flows: an outcome for a flow key Zigbongo doesn't know is accepted and changes nothing, so check the spelling. | | `sessionId` or `subjectId` | Exactly one of them: the session, or your id for the customer. | | `value` | A number: revenue, margin, or 1 for a renewal. Higher is better unless you change that in the flow's settings. | | `at` | Optional. When it happened, as an RFC 3339 time such as `2026-10-11T09:30:00Z`, from 400 days ago to a day ahead. Now, if left out. | The answer is `200`: ```json { "outcomeId": "inv_10023", "status": "accepted" } ``` Reporting the same `outcomeId` again is harmless: nothing counts twice, and the answer's `status` is usually `duplicate` (a repeat that reaches another of Zigbongo's servers, or comes over 10 minutes later, may read `accepted`). So when an outcome call times out or gets a `429` or `5xx` answer, send it again, after the number of seconds in the answer's `Retry-After` header if it has one. The SDKs try three times, waiting 200 ms and then 400 ms, or longer when Zigbongo asks. See [Retries and rate limits](https://zigbongo.com/docs/retries-and-rate-limits.md). To send many outcomes at once, use `POST /v1/outcomes:batch` ([API reference](https://zigbongo.com/docs/api.md)). ### Per session or per customer Report **per session** when the outcome belongs to one run of the flow and you can carry its `sessionId` to where the outcome happens, such as the purchase at the end of a checkout. It counts for that session only. Report **per customer** when you only know who it was: a payment webhook, a renewal, a cancellation. The outcome counts towards each of that customer's sessions in the flow whose attribution window it falls in, so send the same `subjectId` you sent with the decision. The attribution window is one day from the session's start, by default. For renewals or churn, make it longer in the flow's settings (up to 90 days). ## 5. Fall back when Zigbongo is slow Nobody should wait on Zigbongo for long. The SDKs give every decide call 150 ms; if there's no answer by then, or it fails, they show your default and tell Zigbongo, so that decision is never learned from. With plain HTTP, you build this yourself: 1. **Give each decide call a time limit.** The SDKs use 150 ms. Reuse connections where your HTTP client can, so a new connection doesn't take up the time. 2. **On a timeout, a network error or any answer but `200`, show your default.** That includes `429` and `5xx`. Don't retry the decide call after a timeout or an answer: the SDKs don't either. One failure is worth sending again, once, at once and with the same `Idempotency-Key`: a connection that closed before any answer, as a server or proxy retiring a reused connection does. The SDKs do that within the same 150 ms. 3. **Report the fallback, in the background,** with `POST /v1/fallbacks`. `requestId` is the `Idempotency-Key` of the decide call that fell back: ```sh curl https://zigbongo.com/v1/fallbacks \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -d '{ "flowKey": "checkout", "requestId": "5b0e7c2a-3f61-4d8e-9a47-1c2b3d4e5f60", "node": "upsell", "reason": "timeout" }' ``` `node` and `reason` are optional; the SDKs send reasons such as `timeout`, `network` and `http_503`. If the decision reached Zigbongo, now or after the report, it's never learned from. The answer is `{ "status": "recorded" }`, or may be `{ "status": "duplicate" }` for a report already made. 4. **Carry on without that decision.** Don't send a `result` for it. If it was the session's first call, you have no `sessionId`: the next call starts a new session with `subjectId`, and that customer's outcome goes per customer. The flow's page in the dashboard shows how often each decision point fell back. More in [Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md). ## 6. See it in the dashboard Open the project's **Flows** page and switch it to **Test**. `checkout` is listed after its first decision, marked "optimizing". Open it to see: - how many sessions it has had, and when the report was last updated; - the value per session of the customers Zigbongo chooses for against the holdout's, with a 95% interval, once each side has enough sessions with an outcome (the page says how many it's waiting for); - each decision point's options, their share of traffic, and how often it fell back. Sessions whose attribution window is still open show as pending. On the **API keys** page, each key shows when it was last used. ## 7. Switch to the live key When it works in test: 1. On the project's **API keys** page, under **Live environment**, create a key and copy it. 2. Set `ZIGBONGO_KEY` to it on your production servers. The requests don't change: the key decides the environment. The live environment learns on its own, starting from your defaults, and its flows appear on their first live decision. Live sessions count towards your usage: 10,000 free every month, then €4 per 1,000, excluding VAT (see [Pricing](https://zigbongo.com/pricing/)). Keep the test key for development and staging. ## Errors An error answer has a status and a JSON body such as `{ "error": { "code": "invalid_input", "message": "default upgrade is not one of the options" } }`. The ones you're most likely to meet: | Status | `code` | When | |---|---|---| | 400 | `invalid_input` | A field is missing, malformed or unknown, such as a `default` that isn't one of the options. | | 401 | `unauthorized` | The key is missing, wrong or revoked. | | 404 | `not_found` | An unknown session or decision. | | 409 | `decision_already_reported` | A `result` that differs from the one already reported for that decision. | | 413 | `body_too_large` | A body over 2 MiB. | | 429 | `rate_limited` | Over your rate limit. `Retry-After` says how many seconds to wait. | | 503 | `starting`, `timeout` or `unavailable` | Zigbongo is starting, busy or briefly unavailable. `Retry-After` says when to try again. | On a decide call, every one of them means: show your default. The [HTTP API reference](https://zigbongo.com/docs/api.md) lists every call, field and error. --- The Markdown of https://zigbongo.com/docs/quickstart/http/. Every docs page: https://zigbongo.com/llms.txt # Sessions and outcomes > A session is one run of a flow for one person. Every decision in it shares the outcomes you report, by session or by customer, within the flow's attribution window. ## Flows, subjects and sessions - **A flow** is one place in your product where Zigbongo chooses for a customer, with one goal: `checkout`, `paywall`, `onboarding-quiz`. Its key is 1 to 128 characters of letters, digits, `-`, `_` and `.`. A flow exists the first time your code asks about it. - **A subject** is your id for the person: any non-empty string except `.` and `..`, or an integer, which the SDKs send as its text. Keep it stable. It decides whether the person is in the [holdout](https://zigbongo.com/docs/holdout-and-lift.md), and it's how you report outcomes and [erase a customer](https://zigbongo.com/docs/erasing-customers.md) later. An id is personal data whatever it looks like, so prefer your internal user id to an e-mail address. - **A session** is one run of a flow for one subject, such as one visit to checkout or one onboarding. It starts with its first decision. - **A decision** is one choice at a decision point (a node) in the session: which plan to lead with, which upsell, which question next. ## Decisions in a session The SDK's session helper keeps the session id between calls and attaches the previous decision's id to the result you report: ```js import { Zigbongo } from "@zigbongo/sdk"; const zb = new Zigbongo({ apiKey: process.env.ZIGBONGO_KEY, baseUrl: "https://zigbongo.com" }); const s = zb.session("checkout", user.id); const plan = await s.decide("plan", ["monthly", "annual"], "monthly", { inputs: { country: "LT" } }); // show plan.option, then at the next decision point: const upsell = await s.decide("upsell", ["none", "insurance"], "none", { result: { answer: "annual" } }); ``` - The first call starts the session. Each later call in it adds a decision. - `inputs` add up over the session; a later value replaces an earlier one. See [Context inputs](https://zigbongo.com/docs/inputs.md). - `result` says what happened at the previous decision, such as the answer given. Reporting the same result again changes nothing; a different result for the same decision is refused with `409 decision_already_reported`. Results are stored with the decision, but they aren't outcomes: only outcomes are learned from. - To put a list in order, ask at the same decision point again in the session, with the items still left as the options. Zigbongo decides the first pick at the node and each later position on its own, so it learns which item works best in each position. When each step is its own request, as in PHP, keep the session's ids between requests and carry on from them: ```php use Zigbongo\Zigbongo; $zb = new Zigbongo(apiKey: getenv('ZIGBONGO_KEY'), baseUrl: 'https://zigbongo.com'); $s = $zb->session('checkout', $user->id, sessionId: $_SESSION['zb_session'] ?? null, lastDecisionId: $_SESSION['zb_last'] ?? null); $upsell = $s->decide('upsell', ['none', 'insurance'], 'none', result: ['answer' => $_POST['plan']]); $_SESSION['zb_session'] = $s->sessionId; $_SESSION['zb_last'] = $s->lastDecisionId; ``` > Every `decide` call without a session id starts a new session. If you call `zb.decide()` directly rather than through `zb.session()`, pass the `sessionId` the first call returned, or each step becomes a session of its own. ## Outcomes An outcome is a number you report when something happens: revenue, margin, a renewal (1), a cancellation (1, with lower set as better). Report it by session or by subject, never both. ```js // By session: you still have the session at hand. await s.outcome(order.total, order.id); // By subject: from a payment webhook or a renewal job, minutes or weeks later. await zb.outcome({ outcomeId: invoice.id, flowKey: "checkout", subjectId: user.id, value: invoice.total, at: invoice.paidAt, // a Date, or an ISO 8601 string with its time zone }); ``` ```php $zb->outcome($invoice->id, 'checkout', $invoice->total, subjectId: $user->id, at: $invoice->paidAt); ``` | Report by | Use it when | It counts for | |---|---|---| | Session (`sessionId`) | The outcome belongs to that run, such as the purchase at the end of a checkout | That session | | Subject (`subjectId`) | You know the person but not the session, such as a renewal webhook | Each of the subject's sessions in that flow whose window covers the outcome's time | How a flow turns outcomes into a session's value: - **Adding up.** A session's outcomes are summed by default. The flow's `objective.aggregate` can instead take the largest (`max`) or the latest by time (`last`). - **Pending, then zero.** A session with no outcome by the end of its window counts as 0. Until then it's pending, not zero. - **Large values don't swamp the rest.** Zigbongo learns from a session's value ranked among the flow's last 2,000 positive values, so one very large order doesn't outweigh many ordinary ones. Reports show the values as you sent them. For learning, a session whose value is zero or below counts as no outcome. - **Direction.** Higher is better unless you set `objective.direction` to `minimize` ("Better outcome is: Lower" on the flow page), for churn or cancellations. ## Idempotency by outcomeId `outcomeId` is your id for the event, such as the order or invoice id. Reporting the same id again changes nothing, even with a different value, so retries are always safe. The repeat usually answers `duplicate`, but may answer `accepted` when it reaches another of Zigbongo's servers or comes more than 10 minutes later; either way it counts once. The SDKs rely on this when they retry ([Retries and rate limits](https://zigbongo.com/docs/retries-and-rate-limits.md)). - An `outcomeId` is unique across every flow of an environment. If one order matters to two flows, give each report its own id, such as `order_1001:checkout` and `order_1001:upsell`. - To correct a value, report the difference under a new id: a refund as a negative value, timed within the window, cancels a purchase in a flow that sums its outcomes. ## The attribution window The window is how long after a session starts its outcomes still count. It's 1 day (`P1D`) unless you change it. - An outcome counts for a session when its time (`at`) falls between 60 seconds before the session started and the end of its window. - While the window is open, decision points without inputs learn from what's known so far: an outcome counts as soon as it arrives, and the final value replaces it when the window closes. Decision points that use inputs learn when the window closes. - Set it on the flow page's settings (1 minute to 90 days), with `objective.window` on `PATCH /v1/flows/{flowKey}`, or in a [registered flow's](https://zigbongo.com/docs/registered-flows.md) definition. The API takes an ISO 8601 duration in weeks, days, hours, minutes and seconds (`PT30M`, `P7D`, `P30D`); years and months aren't accepted. - A new window applies to the sessions already open, not only to new ones. With a shorter one, those whose new window has passed close within seconds, and outcomes after their new end stop counting; with a longer one, they stay open longer. A session whose window had closed stays closed. ```sh curl -X PATCH https://zigbongo.com/v1/flows/checkout \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -d '{"objective": {"window": "P30D"}}' ``` Choose a window longer than the flow takes and long enough for the outcome to arrive. A short window learns sooner but misses later outcomes: a 5-minute window on a 12-minute quiz counts the purchase at its end as nothing. For churn, think in weeks, such as 30 days (`P30D`). ## Outcomes reported late - **Send `at`.** Without it, an outcome is timed when Zigbongo receives it. An outcome reported a week late without `at` falls outside a 1-day window. `at` can be up to 400 days back, and up to a day ahead for clocks that differ; beyond that the outcome is refused with `400 invalid_input`. - **Report before the window closes.** Once a session's window has closed, Zigbongo stops learning from it: an outcome that arrives afterwards isn't learned from, even if its `at` falls inside the window. The lift report fixes each session's numbers about an hour after its window closes. - **An outcome by subject needs a session to land in.** One timed before the person's session, or for a subject with no session in that flow, is accepted and stored but counts for nothing. - **Outcomes aren't checked as they arrive.** One for a flow or session Zigbongo doesn't know, such as one with a typo in its flow key, is accepted and stored too, and counts for nothing. - **Records don't last for ever.** Sessions, decisions and outcomes are deleted 180 days after their last activity. An outcome for such a session counts for nothing. ## When outcomes stop arriving If far fewer sessions than usual end with an outcome, as when a purchase webhook starts failing, Zigbongo puts the flow's learning on hold: the sessions that end meanwhile aren't learned from, so the missing outcomes don't count against the options people saw, and Zigbongo keeps choosing from what it had learned. The flow's page says so, and the organization's owners get an e-mail for a live flow. Learning resumes on its own once outcomes arrive again. If your outcome really became rarer for good, such as a change from sign-ups to purchases, learning resumes once Zigbongo's idea of the usual share has caught up, within a few weeks; a new flow starts afresh at once. ## Batches To send many outcomes at once, such as a nightly import, use `outcomes()`: ```js const results = await zb.outcomes([ { outcomeId: "inv_1001", flowKey: "checkout", subjectId: "u_81723", value: 49, at: "2026-10-10T14:03:00Z" }, { outcomeId: "inv_1002", flowKey: "checkout", sessionId: savedSessionId, value: 19 }, ]); for (const r of results) { if (r.error) console.warn(r.outcomeId, r.error.code); } ``` - Each item succeeds or fails on its own: `{ outcomeId, status }`, where `status` is `accepted` or `duplicate`, or `{ outcomeId, error: { code, message } }`. One invalid item doesn't stop the others. - A request body is at most 2 MiB, about 25,000 outcomes. A larger one is refused with `413 body_too_large`. - Every outcome in a batch counts against your outcomes rate limit, so send big imports in batches at your limit's pace ([Retries and rate limits](https://zigbongo.com/docs/retries-and-rate-limits.md)). - The SDK retries a batch like a single outcome. An item an earlier attempt stored reads `duplicate`, or may read `accepted` when the retry reaches another of Zigbongo's servers; either way it counts once. ## What counts as a billed session A session is one run of a flow for one person, however many decision points it has. A five-step quiz is one session, not five. - A session counts when Zigbongo starts it: at a `decide` call without a session id, or a registered flow's `start()`. A call that falls back before it reaches Zigbongo starts nothing. - Sessions in the holdout and in a paused flow count too. - A session counts on the day (UTC) Zigbongo receives it. A call sent twice, as a retry can be, starts one session. - Outcomes, fallback reports and the other calls aren't sessions. - Only live environments are billed. [Test environments](https://zigbongo.com/docs/environments-and-keys.md) are free. - The first 10,000 live sessions each month are free, then each 1,000 costs €4. Prices exclude VAT. After a failed payment, days on which Zigbongo didn't choose for you at all aren't billed ([Pausing flows](https://zigbongo.com/docs/pausing-flows.md)). See [Pricing](https://zigbongo.com/pricing/) for the rest. --- The Markdown of https://zigbongo.com/docs/sessions-and-outcomes/. Every docs page: https://zigbongo.com/llms.txt # The holdout and how lift is measured > A share of people always get your defaults. Comparing them with everyone else measures what Zigbongo adds, with an interval you can check as often as you like. ## What the holdout is The holdout is a group of people who always get the default you send. Everyone else gets what Zigbongo chooses. The difference between the two is the lift: what Zigbongo adds over what you would have shown anyway. It works like an A/B test against your current experience that runs for as long as the flow does. - **Per person, and stable.** Whether someone is held out is worked out from the flow and their subject id, so the same person is in or out every time, in every session, with nothing stored. Raising the share only adds people; lowering it only removes them. The one exception so far: once, in an upgrade of Zigbongo, each flow's holdout was drawn afresh, and its lift comparison started again from then. - **Never learned from.** Holdout decisions show your default and teach Zigbongo nothing, so the comparison stays clean. - **Visible in each answer.** A decision's `arm` says what happened: `optimised` (Zigbongo chose), `holdout` (your default, held out), `paused` (your default, the flow is paused) or, from the SDK, `fallback` (your default, no answer in time). ## Flow and node holdouts There are two kinds, and both are 5% by default. - **The flow holdout:** its share of people see your default choices at every decision point of the flow. The lift is measured against this group. - **A node holdout:** its share of people see your default at one decision point only. These decisions are counted apart from the ones Zigbongo chose at that point and aren't learned from. With both at 5%, about 9.75% of decisions show your default. Set a node's holdout with `holdoutPercent` on any decide call. Zigbongo remembers it for that decision point until you send another value: ```js const offer = await s.decide("upsell", ["none", "annual"], "none", { holdoutPercent: 10 }); if (offer.arm === "holdout") { // this person sees your default at this point } ``` In a [registered flow](https://zigbongo.com/docs/registered-flows.md), give a node its `holdoutPercent` in the definition. ## Changing the holdout - **On the dashboard:** the flow page's settings, "Holdout (%)", from 0 to 50. - **Through the API:** `PATCH /v1/flows/{flowKey}` with `holdoutPercent` from 0 to 100. The SDKs have no call for flow settings. - **In a registered flow:** the definition's `holdoutPercent`. Each registration sets the flow back to its definition's settings, so change it there; the dashboard shows it but doesn't offer it. ```sh curl -X PATCH https://zigbongo.com/v1/flows/checkout \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -d '{"holdoutPercent": 10}' ``` A session keeps the flow holdout it started with; new sessions follow the new share. A larger holdout proves lift sooner but means more people see your default choices. In simulation, a 5% holdout limited how soon lift could be proved on flows with small effects, not how well Zigbongo learned; a small flow may want a larger holdout for a while. A holdout of 0 leaves nothing to measure lift against. ## How lift is computed - **Two sides.** Sessions are split by whether the person was in the flow holdout. Holdout sessions got your defaults everywhere. The other sessions had Zigbongo on, including the node holdouts and fallbacks inside them, so the comparison measures Zigbongo as it really runs. Sessions that saw the flow paused are left out of both sides. - **Each session's value.** Its outcomes within its [attribution window](https://zigbongo.com/docs/sessions-and-outcomes.md), added up by the flow's rule (sum, largest or latest). A session with no outcome counts as 0 once its window closes. Sessions still within their window are pending and not yet compared. - **The test.** When every closed session's value is 0 or 1, the sides are compared as conversion rates (two proportions). Otherwise they're compared as means per session (Welch's unequal variances). - **The numbers.** The difference, in your outcome's units, and the relative lift: the mean of the customers Zigbongo chooses for over the holdout's, minus one. Both come with a 95% interval. - **Direction.** When lower is better, the side with the lower value wins. ## When the comparison starts The comparison starts once each side has at least 20 closed sessions with a non-zero outcome. Until then the status is "Gathering data": the dashboard shows no lift figure, only each side's progress towards 20 and which side it's still waiting for. The holdout is the smaller side, so it's usually the one. ## The 95% interval The interval is sequential, or always valid: it holds however often you look. You can check the dashboard every day and act as soon as it says "Clearly better", and the chance that a clear result was wrong stays at most 5% across all your looks. - **"Clearly better"** means the interval for the difference leaves out zero, above it. Until then the status is "No clear difference yet". If the holdout does clearly better, the dashboard says "Clearly worse". The relative lift's interval comes from the same test, so it leaves out zero exactly when the result is clear. - **It can be open-ended.** While the holdout's average is too uncertain to put an upper bound on the ratio, as with revenue just past 20 outcomes, the interval reads "−20% or more": any lift above its lower end is possible. - **It's wider than a one-look interval.** That's the price of looking whenever you like. It's narrowest when the smaller side has about 1,500 sessions (30,000 sessions in all at the default 5% holdout) and widens slowly after. - **A result can come and go.** A lift can show as clearly better on one look and not on a later one. The guarantee covers every look together. - **Skewed revenue is less exact early on.** With a 5% holdout and revenue where a few orders are very large, the first looks rest on few holdout purchases. In simulation, 7.7% of runs with no real difference showed a false win at some point. Learning comes before proof. In simulation, in a five-step quiz where the best version earns 44% more than the default, Zigbongo found that version after about 20,000 sessions (median of 100 simulated runs), and the lift against the holdout became clear at a median of 42,500 sessions. ## What the dashboard shows Each flow's page leads with the comparison: - **The status line:** "optimizing", or "paused · showing your default choices", the sessions covered and when the report was computed. - **The lift:** "Conversion vs holdout" for 0/1 outcomes, "Value per session vs holdout" otherwise. The relative lift, its status (Gathering data, No clear difference yet, Clearly better or Clearly worse) and the 95% interval, drawn as a band with zero marked. A note on how it's measured names the test it comes from (sequential two-proportion test or sequential Welch test). - **Both sides:** "Zigbongo's choices", the customers Zigbongo chooses for, and the "Holdout", with its share, each with its value per session and its closed and pending sessions. - **Over time:** the last 30 days; while the flow is under two days old, the last 48 hours by the hour; and while it is under 8 hours old, every minute since its first session. It shows the lift to date (each day's, hour's or minute's lift over the sessions started by then, with its interval as a band, once the comparison has started), both sides' value per session, and sessions, by when each session started, in UTC, once there are two days, hours or minutes of data. While sessions are still in their attribution window, a chart shows the share of them with an outcome so far, on each side: it rises as outcomes arrive, until the window closes. - **Each decision point:** each option's share of traffic, over the last 7 days and all time, and per day over the last 30 days; its estimate with a 95% interval and its "Chance it's best"; the share of calls that fell back, where the customer saw your default because Zigbongo didn't answer in time; and, where the point uses inputs, the share of people each option is best for, and what Zigbongo learned for each group of customers. Where a point uses inputs, its estimates are Zigbongo's on average over everyone, not the rate among the people each option was shown to, who it was chosen for. For numeric outcomes, estimates are a "Score" on a 0 to 100 scale that ranks the options, not money. Traffic shares describe what happened: traffic shifted as Zigbongo learned, so they don't tell you which option is better. The lift against the holdout is the measure of what Zigbongo adds. The same numbers are in the API: `GET /v1/flows/{flowKey}/report` ([API reference](https://zigbongo.com/docs/api.md)). --- The Markdown of https://zigbongo.com/docs/holdout-and-lift/. Every docs page: https://zigbongo.com/llms.txt # Context inputs > Inputs are the context you attach to a decision, such as country, device or traffic source, so Zigbongo can learn which option works best for whom. ## What inputs are Inputs are a flat set of keys and values sent with a decision: strings, numbers, booleans or `null`. There's no schema to declare. Zigbongo types them itself and, at decision points that use them, learns which option works best for which context: a contextual bandit rather than one answer for everyone. ```js const s = zb.session("paywall", user.id); const plan = await s.decide("plan", ["monthly", "annual", "lifetime"], "monthly", { inputs: { country: user.country, platform: "ios", source: "newsletter", visitsLast30d: 12 }, }); ``` ```php $plan = $s->decide('plan', ['monthly', 'annual', 'lifetime'], 'monthly', inputs: ['country' => $user->country, 'platform' => 'ios', 'source' => 'newsletter', 'visitsLast30d' => 12]); ``` - **They add up over a session.** Send inputs with any call; a later value for the same key replaces the earlier one. The first decision of a session sees only what you send with it, so send what you know about the person (country, platform, campaign) from the first call. - **`null` means unknown.** It's left out, never guessed. - **Flat only.** A nested object or an array is refused with `400 invalid_input`, and the SDK shows your default for that call. Input names can be any non-empty string except `.` and `..`. - **A decision point decides once whether it uses inputs.** If the first decision Zigbongo learns from at a point carries inputs, the point learns per context; if it carries none, the point learns one answer for everyone, for good. - **Context costs traffic.** Learning for each group of customers needs more sessions than learning one answer. In simulation, flows that chose by context learned about 10 times slower than flow-level choices. ## Types are fixed by the first observations Each input's type is its JSON type: number, boolean or text. A string that looks like a number is text, so `"34"` and `34` are different values. - An observation is a decision that carries the input. At its 1,000th observation in a flow, an input's type is fixed, for good, to its most common type so far. A 10-step flow gets there within about its first 100 sessions. - After that, a value of another type is ignored, when learning and when choosing, as if the input were missing. It's still stored, and the flow page's Inputs section flags it, with a notice near the top of the page. - To change an input's type, send it under a new name: it starts afresh. ## Raw or bucketed Both are fully supported; choose per input. - **Raw numbers** (`age: 34`, `basketValue: 72.5`): Zigbongo learns ten bins from the first 500 values. Until then the input counts as unknown. - **Bucketed values** (`ageBand: "25-34"`): text, learned as categories. Send a bucket when you'd rather not send the exact value, such as an age band instead of a birth date, or when your own bands are the ones that matter to your business. ## Outliers in numbers Numbers are learned only as bins. The outer bins are open-ended, so an extreme value falls in with the highest (or lowest) values seen, and nothing is scaled, so there's nothing to clip. The bin edges come from the first 500 values, and a few outliers barely move them. Rules on the dashboard show the outer bins as open ranges. ## Text inputs with many values - A text value gets a weight of its own from its 30th observation. Until then it shares one "other" group with the input's other rare values, and so does a value Zigbongo has never seen. - At its 51st distinct value, an input switches to hashing for good: its values are spread over 256 shared features, aren't combined with other inputs and never appear in the dashboard's rules. So inputs work best with a modest number of values: plan, country, platform, campaign. An id, an e-mail address or a free-text field ends up hashed and adds nothing you can read. ## Switching an input off You can stop Zigbongo using an input in a flow without changing your code: - **On the dashboard:** the flow page's Inputs section, "Switch off" (click twice to confirm), and "Switch on" to bring it back. - **Through the API:** `PATCH /v1/flows/{flowKey}/inputs/{key}` with `{"use": false}`, or `{"use": true}` to switch it back on. Any name can be switched off, even one not sent yet. The SDKs have no call for it. ```sh curl -X PATCH https://zigbongo.com/v1/flows/paywall/inputs/age \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -d '{"use": false}' ``` - It takes effect on every server within a few seconds, usually about one. Each decision records the inputs it left out. - What was learned from the input stays in the model, unused, and fades over time. Switching it back on carries on from there. - A switched-off input is still received, stored for the flow's retention period and counted towards its type. To stop storing it, stop sending it. - A [registered flow's](https://zigbongo.com/docs/registered-flows.md) default rules still read it: they're your rules for the default, not learning. ## What not to send - **Anything that identifies a person.** Names, e-mail addresses, phone numbers, user or device ids. They don't help (they end up hashed) and they're personal data. An identifying value can also end up in Zigbongo's statistics about inputs, which [erasing a customer](https://zigbongo.com/docs/erasing-customers.md) doesn't search. - **Sensitive details you don't need.** Inputs such as health details can be special-category data under the GDPR. What you send is your decision: send a band rather than the exact value, or leave it out. The inputs you do send aren't kept for ever: - Inputs and step results (such as quiz answers) are forgotten after each flow's retention period: 90 days unless you set another, from 1 to 36,500 days. Set it on the flow page ("Keep inputs and answers (days)") or with `retentionDays` on `PATCH /v1/flows/{flowKey}`. Keep it no longer than you need. - The clock starts when each value was sent; a session's inputs count from its last call. What was learned from them stays. The dashboard's "What Zigbongo learned for each group of customers" shows what each input does to the choice, so you can check that nothing is chosen for a reason you wouldn't accept. Values that change the best option have a row each; an input's other values share one row, with the best option over everyone. --- The Markdown of https://zigbongo.com/docs/inputs/. Every docs page: https://zigbongo.com/llms.txt # Registering a flow up front > Optionally, describe a flow once and let Zigbongo route each step. The SDK keeps your definition, so if a call fails it takes the person through the rest of the flow with your default choices. ## Step by step or registered You don't have to register anything. Step by step, your code keeps its own routing and calls `decide` wherever it has a real choice; a flow exists the first time you ask about it ([Sessions and outcomes](https://zigbongo.com/docs/sessions-and-outcomes.md)). Registering suits a flow with many steps, such as a quiz or an onboarding, when you'd rather describe it once: - Zigbongo checks the definition when you register it: a cycle, a missing default or a step that points to a node that doesn't exist is refused. - Zigbongo routes each step, including answer-based routing, optional steps and the order of a set of questions, and returns each option's payload with its step. - Your current rules for who sees what can be the starting point. - The SDK keeps the definition, so a failure mid-flow still takes the person to the end, with your default choices. Both ways share the same learning, outcomes and reports. Keep the node and option keys the same and what was learned carries over between them. ## A definition ```js // flows.js export const quizFlow = { key: "onboarding-quiz", objective: { direction: "maximize", window: "P1D", aggregate: "sum" }, holdoutPercent: 5, start: "q_goal", nodes: [ { key: "q_goal", type: "variant", options: [ { key: "v1", default: true, payload: { title: "What's your goal?" } }, { key: "v2", payload: { title: "What brings you here?" } }, ], next: { byAnswer: { lose_weight: "route" }, else: "lifestyle" }, }, { key: "route", type: "branch", options: [ { key: "diet", to: "lifestyle", default: true }, { key: "fitness", to: "q_injury" }, ], }, { key: "q_injury", type: "variant", optional: { default: "include" }, options: [{ key: "short", default: true }, { key: "detailed" }], next: "lifestyle", }, { key: "lifestyle", type: "sequence", items: [{ key: "sleep" }, { key: "stress" }, { key: "activity" }], defaultOrder: ["sleep", "stress", "activity"], next: "pitch", }, { key: "pitch", type: "variant", options: [{ key: "fitness" }, { key: "healthy_eating" }, { key: "general", default: true }], defaultRules: [{ when: { goal: "lose_weight", age: [30, 45] }, option: "healthy_eating" }], next: null, }, ], }; ``` The flow: | Field | Required | Meaning | |---|---|---| | `key` | yes | The flow's key, the same as in the URL | | `objective.direction` | yes | `maximize` or `minimize` | | `objective.window` | no | The [attribution window](https://zigbongo.com/docs/sessions-and-outcomes.md), an ISO 8601 duration; `P1D` by default | | `objective.aggregate` | no | How a session's outcomes add up: `sum` (default), `max` or `last` | | `holdoutPercent` | no | The flow [holdout](https://zigbongo.com/docs/holdout-and-lift.md); 5 by default | | `explorationFloor` | no | The share of traffic each option keeps until it's confidently beaten; 0.02 by default | | `start` | yes | The first node's key | | `nodes` | yes | The nodes, which must not form a cycle | The node types: | `type` | Decides | Fields | |---|---|---| | `variant` | Which version of a step to show | `options`, `next` | | `branch` | Which node comes next | `options`, each with `to` (a node key, or `null` to end) | | `sequence` | Which item of a set comes next, until all are shown | `items`, `defaultOrder`, `next` | - **Every node** has a unique `key` and may have `optional: { default: "include" | "skip" }` and its own `holdoutPercent`. - **Options** of a `variant` or `branch` node: exactly one has `default: true`, the option your own flow would show. A `payload` can be anything; it comes back with the step. - **`next`** is a node key, `null` for the end, or answer routing: `{ byAnswer: { "yes": "q_injury" }, else: "q_goal" }`. It's required, so a forgotten field isn't read as the end, and `byAnswer` needs `else`. Zigbongo follows answer routing; it never optimizes it. - **`defaultRules`** on a `variant` or `branch` node are your current rules for its default, top to bottom: the first rule whose every test the session's inputs pass gives the default, else the option marked default. A test is an exact string or boolean, or `[min, max]` for numbers, bounds included, `null` for an open end. A missing or `null` input passes nothing, and `"30"` isn't a number. A definition that can't be used is refused with `400 invalid_flow`, naming every problem and its node. A request body is at most 2 MiB, about 20,000 small nodes. ## How each node runs - **Variant:** Zigbongo picks the option, then follows `next`, by the answer you report where it routes by answer. - **Branch:** Zigbongo picks the option and goes where its `to` leads. - **Sequence:** one step per item, each chosen among the items not yet shown; the first pick and each later position are learned on their own. When all are shown, `next` follows, by the last item's answer. - **Optional node:** Zigbongo first decides whether to include it. Skipped, it costs no round trip: the flow carries on as if the node had been shown and not answered (`next`, or its `else`; a branch goes where its default option leads). A start can end at once when every node is skipped. - **Default rules** set each decision's default: people in the holdout, or in a paused flow, get the rule's option, and learning starts from it. - **Answers** route as their JSON text: a string as it is, a number or boolean as written in JSON (`3`, `true`). ## Versions - Each distinct definition is a version, numbered 1, 2, 3 in the order first registered. Registering the same content again returns the existing version; registering an earlier one makes it current again. - A start that sends a definition Zigbongo already has runs on that version and changes nothing: it doesn't make it current or set the flow's settings again. Only registering, or a start with content Zigbongo hasn't seen, makes a version current. So servers running different definitions during a deploy don't switch the current version back and forth. - Registering new content, with `register()` or at a start, counts once more against the `other` rate-limit allowance ([Retries and rate limits](https://zigbongo.com/docs/retries-and-rate-limits.md)). - A session stays on the version it started on. - Registering sets the flow's goal, window, aggregate, holdout and exploration floor to the definition's, defaults included, every time. A change made on the dashboard or with `PATCH` lasts only until the next registration, so the dashboard shows a registered flow's settings without offering to change them. The flow's retention period isn't part of a definition. ## Register, start and next in Node.js ```js import { Zigbongo } from "@zigbongo/sdk"; import { quizFlow } from "./flows.js"; const zb = new Zigbongo({ apiKey: process.env.ZIGBONGO_KEY, baseUrl: "https://zigbongo.com" }); const quiz = zb.flow(quizFlow); // once, at module scope; sends nothing // At deploy or startup: throws a ZigbongoError with code "invalid_flow" for a bad definition. const { version, created } = await quiz.register(); // In a request handler: const run = await quiz.start(user.id, { inputs: { platform: "ios", age: 34 } }); render(run.step); // { node, option, payload, arm, fallback, decisionId }; null once done req.session.quiz = run.state; // plain JSON // In the next request: const again = quiz.resume(req.session.quiz); const step = await again.next({ result: { answer: "lose_weight" }, inputs: { goal: "lose_weight" } }); if (step === null) showResults(); else render(step); req.session.quiz = again.state; // Later, by session (or by subject if the start fell back): await again.outcome(49.0, order.id); ``` - **`zb.flow(definition)`** keeps a copy of the definition. Create it once per process, so it remembers the version. - **`register()`** registers the definition (`PUT /v1/flows/{flowKey}`) and returns `{ version, hash, created, createdAt, registeredAt }`; `created` is false when the same content was registered before. It isn't retried and throws on failure, which is what you want at deploy. - **`start(subjectId, { inputs, segment })`** sends the definition with it until the client knows its version, from `register()` or an earlier start, then the version only. Without `register()`, the first start of each process registers a changed definition within its 150 ms budget, and can fall back. `segment` is a shorthand for the input `segment`; send one or the other. - **`next({ result, shown, inputs })`** reports the step and gives the next one, or `null` at the end. `result.answer` drives `byAnswer`. Pass `shown: false` when you didn't show the step: it isn't learned from, though the route still follows Zigbongo's choice. `inputs` add to the session's. - **`run.state` and `resume(state)`** carry a run across requests as plain JSON. `run.done` is true once `step` is null. - **`abandon()`** ends the run when the person leaves, and never throws. A registered session with no call for 30 minutes counts as abandoned at its last step; a step after that is refused, and the SDK carries on with your default choices. ## The same in PHP Under PHP-FPM a client lives for one request, so register at deploy and pass the version `register()` returned to `flow()`. Starts then send only the version. Without it, each start sends the whole definition: that works too, since a start with a definition Zigbongo already has runs on its version and changes nothing, but every request carries the definition, and only `register()` makes it the current version. ```php use Zigbongo\Zigbongo; $zb = new Zigbongo(apiKey: getenv('ZIGBONGO_KEY'), baseUrl: 'https://zigbongo.com'); $definition = require __DIR__ . '/flows/quiz.php'; // arrays, or JSON text // At deploy: throws a ZigbongoException (errorCode "invalid_flow") for a bad definition. $version = $zb->flow($definition)->register()->version; // In a request: $quiz = $zb->flow($definition, version: $config['quiz_version']); $run = $quiz->start($user->id, inputs: ['platform' => 'ios', 'age' => 34]); render($run->step()); // node, option, payload, arm, fallback, decisionId; null once done $_SESSION['quiz'] = $run->state(); // In the next request: $run = $quiz->resume($_SESSION['quiz']); $step = $run->next(result: ['answer' => $_POST['answer']], inputs: ['goal' => $_POST['answer']]); $step === null ? showResults() : render($step); $_SESSION['quiz'] = $run->state(); ``` - Give `flow()` only the version `register()` returned for exactly this definition. A version Zigbongo doesn't have falls back, and the next start sends the definition. - Write the definition as ordinary arrays: where Zigbongo reads an object (`byAnswer`, a rule's `when`), the SDK sends one. A payload is sent as you give it, so `[]` stays an array; use `new \stdClass()` or JSON text for `{}`. - A float answer routes as PHP sends it: `3.0` routes as `"3.0"`, `3` as `"3"`. ## When a call fails: the rest of the flow with your default choices `start()` and `next()` never throw. On a timeout (150 ms), when Zigbongo can't be reached, or on an error answer, the SDK reports the fallback, so Zigbongo forgets every decision that call made, and from there follows your definition's defaults to the end without calling Zigbongo again: - optional nodes at their `optional.default`; - `defaultRules` on the inputs so far, else the option marked default; - a sequence's items in `defaultOrder`; - `next` by the answer you report, and a branch where its default option leads. These steps have `fallback: true`, `arm: "fallback"` and no `decisionId`, and `run.fallback` is true. They're the same steps your customers see while a flow is paused. So keep the definition in your code: the SDK needs it to fall back. After a deploy that changes the definition, a run you resume carries on with the version Zigbongo started it on, but a fallback would follow the new definition, so change a live definition with care. More on fallbacks: [Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md). ## Over HTTP | Call | Body | Answer | |---|---|---| | `PUT /v1/flows/{flowKey}` | The definition | `201` for a new version, `200` for one registered before | | `POST /v1/flows/{flowKey}/sessions` | `{ subjectId, version or flow, inputs, segment }` | `201 { sessionId, version, arm, step, done }` | | `POST /v1/sessions/{sessionId}/steps` | `{ decisionId, shown, result, inputs, state }` | `{ step, done }` | | `POST /v1/sessions/{sessionId}/events` | `{ "type": "abandoned", state }` | `{ sessionId, status, node, endedAt }` | `version` is a number, or `"latest"` for the version registered last, which is the default. Send an `Idempotency-Key` header with each start and step so a fallback can be reported against it. `state` is the run as you keep it, at the step reported. The [API reference](https://zigbongo.com/docs/api.md) has the details. --- The Markdown of https://zigbongo.com/docs/registered-flows/. Every docs page: https://zigbongo.com/llms.txt # Fallbacks and timeouts > Nobody waits on Zigbongo. If a decision doesn't come back in 150 ms, or anything goes wrong, the SDK returns your default and tells Zigbongo not to learn from that call. ## The 150 ms timeout `decide()`, and a registered flow's `start()` and `next()`, wait at most 150 ms for Zigbongo. If the answer doesn't come in time, Zigbongo can't be reached, or it answers with an error, the call returns your default instead. These calls never throw. ```js const zb = new Zigbongo({ apiKey: process.env.ZIGBONGO_KEY, baseUrl: "https://zigbongo.com", timeoutMs: 150, // the default }); ``` `timeoutMs` changes the budget. A longer one gives a slow answer more time, and makes your page wait that much longer when Zigbongo is slow. Errors fall back too, not only timeouts. A `400` for a malformed call, a `401` for a revoked key or a `429` over your [rate limit](https://zigbongo.com/docs/retries-and-rate-limits.md) all return your default, so a mistake in your integration shows up as fallbacks, not exceptions. Watch for them with `onError` (below) and on the dashboard. A connection that closes before Zigbongo answers, as a proxy can do when it retires one, doesn't cost a fallback: the call is sent once more at once, within the same 150 ms ([Retries and rate limits](https://zigbongo.com/docs/retries-and-rate-limits.md)). ## The connection, and warm() Opening a connection to Zigbongo takes a DNS lookup and a TLS handshake on top of the call itself, and that counts against the 150 ms. From servers far from Zigbongo, a call that has to open one can miss its budget. So the Node.js SDK keeps one HTTP/2 connection open between calls, shared by every client in the process, however many calls you make at once. It closes the connection after 50 seconds without a call. Only the first call after your server starts, or after a quiet spell, waits for a new one. An idle connection never keeps your process from exiting. To open the connection before your first visitor arrives, call `warm()` when your server starts, or in a serverless function's init: ```js const zb = new Zigbongo({ apiKey: process.env.ZIGBONGO_KEY, baseUrl: "https://zigbongo.com", }); await zb.warm(); // opens the connection ``` `warm()` never throws. If Zigbongo can't be reached or the key is refused, the error goes to `onError` and your server starts anyway, with decisions falling back to your defaults until Zigbongo answers. Calls go through Node's own `fetch` instead when a proxy variable (`HTTPS_PROXY` or `HTTP_PROXY`) is set, when `baseUrl` is plain `http:`, or when you pass your own `fetch` (a mock in your tests, or your own dispatcher). Node's `fetch` closes a connection after 4 seconds without a call, so more calls wait for a new one. ## What a fallback returns From `decide()`: ```js { option: "monthly", arm: "fallback", fallback: true, sessionId: null, decisionId: null } ``` - `option` is the `default` you sent. Show it as usual. - `arm` is `"fallback"` and `fallback` is `true`. - `decisionId` is null: there's no decision to report a result for. The session helper drops the `result` you pass at the next call, and the session carries on. - `sessionId` is the one you passed, or null when the fallback started no session. From a registered flow, the step comes from your definition's defaults, with `fallback: true`, `arm: "fallback"` and no `decisionId`. From then on the run follows the defaults to its end without calling Zigbongo again ([Registered flows](https://zigbongo.com/docs/registered-flows.md)). An outcome you report after a fallback still counts. With no session, the session helper and a registered run report it by subject instead. ## Fallbacks aren't learned from A call can time out on your side and still reach Zigbongo, which would then record a decision the person never saw. So every `decide`, `start` and `next` carries an `Idempotency-Key`, and on a fallback the SDK reports it to `POST /v1/fallbacks` with that key and the reason (`timeout`, `network`, `http_503`, and so on): - If the decision reached Zigbongo, it's marked and forgotten while its session's window is open. For a registered flow, every decision that call made is forgotten. - If the report arrives before the decision does, the two are matched when the decision lands. - Reports for calls that never arrived are kept, so they count in the fallback rate. The dashboard shows, at each decision point, the share of calls that fell back. If you call the HTTP API yourself, do the same: send an `Idempotency-Key` header (1 to 200 visible ASCII characters) with each decide, and report a call you gave up on: ```sh curl -X POST https://zigbongo.com/v1/fallbacks \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -d '{"flowKey": "checkout", "requestId": "7d1f0c2e-5b9a-4c55-9e0f-2a8d4b1c6e31", "node": "plan", "reason": "timeout"}' ``` `requestId` is the decide call's `Idempotency-Key`. The answer is `{"status": "recorded"}`; a repeated report is kept once, and may answer `duplicate`. ## flush() and serverless functions In Node.js the fallback report goes out in the background, after `decide()` has returned your default. A serverless function can be frozen or stopped as soon as it returns, with the report unsent. Wait for it first: ```js export async function handler(event) { const offer = await zb.decide("checkout", { subjectId: event.userId, node: "upsell", options: ["none", "annual"], default: "none" }); const body = render(offer.option); await zb.flush(); // waits for any fallback reports return { statusCode: 200, body }; } ``` `flush()` returns at once when nothing is waiting. PHP has nothing running in the background, so its reports wait in the client and go out when you call `flush()`, when the client is destroyed, or when the script ends, even after a fatal error. They all share one budget, `fallbackReportTimeoutMs` (1,000 ms by default), so a page that fell back can take up to that much longer to finish: - Under PHP-FPM, finish the response first with `fastcgi_finish_request()` (Symfony and Laravel already do), or lower `fallbackReportTimeoutMs`. - In a long-running worker (queues, RoadRunner, Swoole), call `$zb->flush()` after each job. Before PHP 8.5, each request that decides opens a new connection to Zigbongo, and the handshake counts against the 150 ms. From PHP 8.5 the worker keeps the connection between requests. ## onError Every error the client absorbs instead of throwing goes to `onError`: decide fallbacks, a registered run's failed starts, steps and abandons, and fallback reports that couldn't be sent. ```js const zb = new Zigbongo({ apiKey: process.env.ZIGBONGO_KEY, baseUrl: "https://zigbongo.com", onError: (e) => logger.warn({ reason: e.reason, status: e.status, code: e.code }, e.message), }); ``` ```php $zb = new Zigbongo( apiKey: getenv('ZIGBONGO_KEY'), baseUrl: 'https://zigbongo.com', onError: fn (\Zigbongo\ZigbongoException $e) => error_log("zigbongo {$e->reason} {$e->status} {$e->errorCode}: {$e->getMessage()}"), ); ``` - `reason` is `timeout`, `network`, `http` (Zigbongo answered with an error) or `invalid_response`; PHP adds `invalid_request`, for a request that can't be encoded, such as a `NAN` value. - `status` is the HTTP status when Zigbongo answered, and the error code (`code` in Node.js, `errorCode` in PHP) is Zigbongo's, such as `invalid_input` or `rate_limited`. - Keep `onError` short. Both SDKs ignore an `onError` that throws (or, in Node.js, returns a promise that rejects), so a mistake in it can't make a call throw or stop your process, though what it was about to log is lost. A steady stream of `timeout` errors points at the network between your servers and Zigbongo, or at Zigbongo being slow; `http` errors with a 4xx status usually mean a mistake in the calls. --- The Markdown of https://zigbongo.com/docs/fallbacks-and-timeouts/. Every docs page: https://zigbongo.com/llms.txt # Retries and rate limits > Decisions never wait for a retry: they fall back to your default. Outcomes and erasures, which must not be lost, are retried, waiting as long as Zigbongo asks within a budget. ## Which calls retry | Call | Timeout per attempt | On failure | |---|---|---| | `decide()`, a registered flow's `start()` and `next()` | 150 ms (`timeoutMs`) | Not retried: returns your default ([Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md)) | | `outcome()`, `outcomes()` | 5,000 ms (`requestTimeoutMs`) | Retried, up to 3 attempts in all (`outcomeAttempts`), then throws | | `eraseSubject()` | 65,000 ms (`erasureTimeoutMs`) | Retried like outcomes, then throws ([Erasing customers](https://zigbongo.com/docs/erasing-customers.md)) | | `register()`, `pause()`, `resume()` | 5,000 ms (`requestTimeoutMs`) | Not retried: throws | | A registered run's `abandon()` | 5,000 ms (`requestTimeoutMs`) | Not retried; never throws | | `warm()` | 5,000 ms (`requestTimeoutMs`) | Not retried; never throws ([The connection](https://zigbongo.com/docs/fallbacks-and-timeouts.md#the-connection-and-warm)) | | Fallback reports | 5,000 ms in Node.js; in PHP all of them within 1,000 ms (`fallbackReportTimeoutMs`) | Not retried; the error goes to `onError` | Retrying is safe because these calls are idempotent: an outcome by its `outcomeId`, an erasure because erasing again finds nothing. An outcome an earlier attempt stored usually reads `duplicate`, and may read `accepted` when the retry reaches another of Zigbongo's servers; either way it counts once. ## A dropped connection A server or proxy between you and Zigbongo can close a connection while requests are still on it. On HTTP/2, which the Node.js SDK uses, that's a `GOAWAY`. When a call's connection closes before any answer, the SDK sends it once more at once, on a new connection, within the same timeout, so a decision still comes back within 150 ms. That holds for every call, `decide()` included, and doesn't count as one of `outcomeAttempts`. Sending twice is safe: a decision by its idempotency key, an outcome by its `outcomeId`. The Node.js SDK does this itself; in PHP, curl does it for the SDK. ## What's retried, and how long it waits A failed attempt is retried when it could succeed unchanged: a timeout, a network error, an unexpected answer, `429` or a `5xx`. Any other error (`400 invalid_input`, `401`, `404`, `409`, `413`, and in PHP a request that can't be encoded) is thrown at once, since sending it again won't help. Before each retry the SDK waits its backoff, 200 ms and then 400 ms (doubling), or as long as Zigbongo asked in its `Retry-After` header, whichever is longer. All the waits of one call together are capped by `maxRetryWaitMs`, 10,000 ms by default. When the next wait would go past it, the SDK doesn't sleep on it: it throws at once, and the error's `retryAfterMs` says how long Zigbongo asked you to wait. ```js import { Zigbongo, ZigbongoError } from "@zigbongo/sdk"; try { await zb.outcome({ outcomeId: order.id, flowKey: "checkout", subjectId: user.id, value: order.total, at: order.paidAt }); } catch (e) { if (e instanceof ZigbongoError && e.retriable) { job.retryIn(e.retryAfterMs ?? 60_000); // your queue's retry } else { throw e; } } ``` ```php use Zigbongo\ZigbongoException; try { $zb->outcome($order->id, 'checkout', $order->total, subjectId: $user->id, at: $order->paidAt); } catch (ZigbongoException $e) { if (!$e->isRetriable()) { throw $e; } $job->release(intdiv($e->retryAfterMs ?? 60_000, 1000)); // your queue's retry, in seconds } ``` While it waits, the call holds up its process. Under PHP-FPM that's a worker, so report outcomes from a queued job, or lower `maxRetryWaitMs`. ## Rate limits Each environment has three allowances, so one kind of traffic never starves another: | Allowance | Calls | Default limit | |---|---|---| | `decide` | `decide`, a registered flow's starts, steps and abandon events | 1,000 a second | | `outcomes` | Outcomes (each outcome in a batch counts) and fallback reports | 1,000 a second | | `other` | Everything else: flow settings, pause and resume, registering, reports, input switches, erasure; and making a new flow | 20 a second | - **Per environment.** A project's live and test environments each have their own. - **A second's worth at a time.** Each allowance holds one second's worth of calls and refills at its limit. Each of Zigbongo's servers counts your calls on its own, so when they reach several servers, more than your limit can get through. Don't count on it: plan for your limit. - **Batches.** A batch of outcomes is let in on one call's worth, then takes the rest of its size from the allowance, even below zero. A batch bigger than your limit still gets through, and your next outcome calls wait until the allowance has refilled. - **New flows and content.** Two things count once more against `other`: a decide for a flow key Zigbongo hasn't seen, which makes the flow, and registering a definition Zigbongo doesn't have yet, whether with `register()` or at a registered flow's start. So a first decide for a new flow key, or a start with a new definition, can get a `429`, and falls back. Keep flow keys fixed: a key made per person or per order makes a flow each time, and is refused once past `other`. - **The dashboard doesn't count.** Its own calls don't use your allowances. If you need more, ask us: Zigbongo can give an environment limits of its own. The [terms](https://zigbongo.com/terms/) ask you not to load-test Zigbongo or send traffic beyond your limits on purpose without agreeing it with us first. ## The 429 answer A call over an allowance is refused, and nothing about it is stored: ```http HTTP/1.1 429 Too Many Requests Retry-After: 1 Content-Type: application/json {"error": {"code": "rate_limited", "message": "over this environment's `outcomes` limit of 1000 per second; retry after 1 s"}} ``` `Retry-After` is in whole seconds, at least 1. After a big batch it can be several seconds. - **Outcomes and erasures** wait for it and retry, within `maxRetryWaitMs`. Outcomes sent one after another faster than your limit all arrive, paced by Zigbongo. A burst well over your limit can't all fit in three attempts: the rest throw, with `retryAfterMs`. - **Backfills** should go in batches at your limit's pace: a batch no bigger than your per-second limit, about once a second. ## What decide does when limited `decide()` doesn't wait. Over the `decide` allowance, or over `other` for a flow key Zigbongo hasn't seen, it gets a `429`, returns your default with `fallback: true`, and passes the error to `onError` with `status` 429 and code `rate_limited`. The fallback report goes on the `outcomes` allowance, so it still gets through, and the call counts in that decision point's fallback rate. That person sees your default and teaches Zigbongo nothing, as with any fallback. ## When Zigbongo is busy When one of Zigbongo's servers has just started, or Zigbongo is busy, or its database is out of resources or restarting, it answers `503` with code `starting`, `timeout`, `overloaded` or `unavailable` and `Retry-After: 1`. Decisions, outcomes and fallback reports get `starting`, `overloaded` or `unavailable`, never `timeout`. `overloaded` means that server is too far behind in storing what it's sent, and turns those calls away until it catches up rather than accept what it might lose. Outcomes and erasures retry after it; decisions fall back. A request body over 2 MiB is refused with `413 body_too_large` and isn't retried: split the batch. If you call the HTTP API yourself, do the same: honour `Retry-After`, retry outcomes with the same `outcomeId`, and show your default rather than retry a decision. --- The Markdown of https://zigbongo.com/docs/retries-and-rate-limits/. Every docs page: https://zigbongo.com/llms.txt # Pausing a flow: the kill switch > Pause a flow and within a few seconds everyone sees your default choices, while your product keeps working. Resume it and Zigbongo carries on from what it had learned. ## Pause and resume from code ```js await zb.pause("checkout"); // everyone sees your default choices await zb.resume("checkout"); // Zigbongo chooses again ``` ```php $zb->pause('checkout'); $zb->resume('checkout'); ``` - Both throw on failure (a `ZigbongoError` or `ZigbongoException`); they aren't retried. A flow that doesn't exist yet answers `404`: you can only pause a flow that has been used or set up. - Over HTTP, they're `POST /v1/flows/{flowKey}:pause` and `POST /v1/flows/{flowKey}:resume`, and each answers with the flow's settings and its `status`, `paused` or `learning`. - They count against the `other` allowance, not `decide`, so the kill switch stays reachable while your decide traffic is at its limit ([Retries and rate limits](https://zigbongo.com/docs/retries-and-rate-limits.md)). - A flow is paused in one environment: pausing the live flow leaves the test flow of the same name as it was. ```sh curl -X POST "https://zigbongo.com/v1/flows/checkout:pause" \ -H "Authorization: Bearer $ZIGBONGO_KEY" ``` ## Pause and resume from the dashboard On the flow's page, "Pause this flow" (click it twice to confirm) pauses it for the environment you're looking at. The page then shows "paused · showing your default choices", and "Start choosing again" starts it again. Anyone who can open the project can do it, and the organization's audit log records who did. ## How fast it applies A pause or a resume applies on every one of Zigbongo's servers within about a second, the one that took it included, and within a few seconds when they're busy. Calls already on their way may still get the old answer. ## What your customers see while a flow is paused - **Your default at every decision point.** Each decision answers with the default you sent and `arm: "paused"`. - **A registered flow's default path.** Each step is your definition's default: optional nodes at their `optional.default`, `defaultRules` on the session's inputs, a sequence in `defaultOrder`. These are the same steps the SDK walks when it falls back ([Registered flows](https://zigbongo.com/docs/registered-flows.md)). - **New sessions too.** A session that starts while the flow is paused gets your default choices for as long as the pause lasts, whichever side of the holdout the person is on. ## What a paused flow records - **Calls still work.** Sessions start and decisions are recorded, marked as paused, and outcomes are accepted as usual. Your code needs no change. - **Nothing is learned from paused decisions.** What Zigbongo learned before the pause is kept, and resuming carries on from it. - **The lift comparison leaves paused sessions out.** A session that saw the pause got your default choices on both sides, so it's left out of both and counted apart. See [Holdout and lift](https://zigbongo.com/docs/holdout-and-lift.md). - **Paused sessions still count as sessions** in your usage ([Sessions and outcomes](https://zigbongo.com/docs/sessions-and-outcomes.md)). ## When a payment fails If a payment fails, you have 30 days to pay it. After that, Zigbongo stops choosing for your organization in every environment, test environments included, until the invoice is paid: - **Your customers see your default choices, and your product keeps working.** Every flow answers with your default and `arm: "paused"`, flows created later included. Your data is kept. - **Your own pauses are kept apart.** Each flow keeps its own status. Resuming a flow doesn't start Zigbongo choosing again, and once you've paid, a flow you had paused yourself stays paused. - **Paying restores it.** Zigbongo starts choosing again within seconds of Stripe confirming the payment. - **Those days aren't billed.** Days on which Zigbongo didn't choose for you at all aren't billed; amounts due remain due. - **You're told.** Owners and billing members get an e-mail when the payment fails, with the date Zigbongo would stop choosing, and another when it stops. A banner on the organization's pages says so too: during the 30 days to owners and billing members, and to everyone once Zigbongo has stopped choosing. Zigbongo can stop choosing up to an hour after the 30 days end. The [terms](https://zigbongo.com/terms/) set out the rest. ## When the month passes the free allowance Without a subscription, each calendar month's live sessions are free up to the free allowance ([Pricing](https://zigbongo.com/pricing/)). Past it, Zigbongo stops choosing for your organization in every environment, test environments included, until you subscribe or the next month starts: - **Your customers see your default choices, and your product keeps working,** as when a payment fails: every flow answers with your default and `arm: "paused"`, flows created later included, your own pauses are kept apart, and your data is kept. - **Adding a card restores it.** Zigbongo starts choosing again within seconds of Stripe confirming your subscription. Otherwise it starts again on the 1st, in UTC, with the new month's allowance. - **You're told.** Owners and billing members get an e-mail when 80% of the allowance is used, and another when Zigbongo stops choosing, each once a month. The usage page says how much is left, and a banner on the organization's pages says when Zigbongo has stopped choosing. Zigbongo can stop choosing up to an hour after the month passes the allowance, and start again up to an hour after midnight on the 1st. Zigbongo never stops choosing for an organization with a subscription: what's past the allowance is billed. --- The Markdown of https://zigbongo.com/docs/pausing-flows/. Every docs page: https://zigbongo.com/llms.txt # Erasing a customer's data > When one of your customers asks to be forgotten, one call deletes their sessions, decisions, outcomes and events, in every flow, before it answers. ## Erase from your code `eraseSubject()` takes the customer's subject id, exactly as your code sends it to Zigbongo, and erases them in every flow of the key's environment: ```js const erased = await zb.eraseSubject(user.id); // { subjectId: "u_81723", sessions: 2, decisions: 7, outcomes: 1 } ``` ```php $erased = $zb->eraseSubject($user->id); // $erased->sessions, $erased->decisions, $erased->outcomes ``` Over HTTP it's `POST /v1/subjects:erase`: ```sh curl -X POST "https://zigbongo.com/v1/subjects:erase" \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -d '{"subjectId": "u_81723"}' ``` The erasure is done before the call answers: what's stored goes first, then, two seconds later, whatever was still on its way. A key belongs to one environment, so a customer in both your live and test environments needs a call with each key, or the dashboard (below). ## The counts it returns The counts are the stored records it erased: - `sessions`: the customer's sessions erased. - `decisions`: the decisions in those sessions. - `outcomes`: their outcomes, both those reported by session and those reported by subject, in any flow. A call about the customer still on its way when the erasure runs isn't counted, and is discarded when it arrives. ## Safe to repeat Erasing is idempotent. Erasing again, or erasing an id Zigbongo never saw, answers with zeros, never an error, since you can't know whether there was anything. When the SDK had to retry, the counts are the last attempt's, so zeros can mean an earlier attempt did the erasing. ## It never falls back Unlike a decision, an erasure has no default to show: it succeeds, or it throws a `ZigbongoError` (`ZigbongoException` in PHP). An empty id throws before anything is sent. - **Its own timeout.** An erasure may wait for Zigbongo to finish learning from the customer's flows, and Zigbongo gives it up to 60 seconds. The SDK waits a little longer, up to 65 seconds an attempt (`erasureTimeoutMs`), so that a slow erasure ends with Zigbongo's own answer. A client that gives up first may leave the erasure part done; erasing again finishes it, as the SDK's next attempt does. - **Retried like outcomes.** Timeouts, `429` and `5xx` are retried, up to 3 attempts (`outcomeAttempts`), waiting for `Retry-After` within `maxRetryWaitMs`. Erasure counts against the `other` allowance, 20 calls a second by default, so a batch of erasures will meet `429`s ([Retries and rate limits](https://zigbongo.com/docs/retries-and-rate-limits.md)). - **Run it from a job,** not a page someone waits on: with retries, a call can take over three minutes when Zigbongo is struggling. Under PHP-FPM, `request_terminate_timeout` counts the wait. - **The id stays out of logs.** It travels in the request body, never the URL, and no error names it, so neither your logs nor anything between you and Zigbongo records whom you erased. ## Erase from the dashboard Owners and admins can erase a customer without an engineer: Organization settings, Privacy. 1. Enter the customer's id exactly as your systems send it. It isn't trimmed: `" ada"` and `"ada"` are different ids. 2. Choose the projects. All are ticked to start with; if two of your products use the same id for different people, untick the one where it's someone else. 3. Add a reference if you like, such as a ticket number. Never put the customer's id there. 4. Confirm. The confirm step shows the id between quotes, with its length, so stray spaces show. It erases in each chosen project's live and test environments, and shows what went in each: "2 sessions, 3 decisions, 1 outcome", "Nothing held", or "Didn't finish", in which case erase again: what's already gone is skipped. The organization's audit log records the erasure with the projects, the counts and your reference, never the customer's id. ## What's erased - The customer's sessions, with the inputs they carried, and their decisions, with the results reported (such as answers). - Their outcomes, by session and by subject, in every flow. - The fallback reports for their decisions. - Every event about them in Zigbongo's event log. - Their sessions whose window is still open, which are dropped from learning so they're never learned from. ## What isn't erased These hold no record of the person: - **What Zigbongo has learned.** The models, including what they learned from the customer's sessions whose windows had already closed. A model is a set of statistics about everyone, not a record of anyone, and old evidence fades over time. - **Daily counts:** usage for billing, and the traffic per option the dashboard shows. - **Lift numbers already tallied.** Sessions whose window closed over an hour before the erasure are part of the lift comparison's daily totals, which are kept. - **Zigbongo's statistics about inputs,** which an erasure doesn't search. If you send identifying values as inputs, such as an e-mail address, one can end up there; so don't ([Context inputs](https://zigbongo.com/docs/inputs.md)). - **Fallback reports for calls that never reached Zigbongo,** which nothing links to the customer. Nothing records the erasure itself with the id: Zigbongo's log line names only the counts. ## After the erasure - **New calls are new data.** If your code keeps sending decisions or outcomes for the same id, Zigbongo keeps them. Stop sending them first, then erase. A session the erasure removed answers `404`, so a decide that continues it falls back to your default. - **Retention applies to everyone anyway.** Inputs and step results are forgotten after each flow's retention period, 90 days unless you set another, and sessions, decisions, outcomes and events are deleted 180 days after their last activity. - **Backups.** Erasure works on Zigbongo's database. Its backups are kept for about five weeks, as the [DPA](https://zigbongo.com/dpa/) describes. For other requests from your customers, such as for a copy of their data, the [DPA](https://zigbongo.com/dpa/) says how we help. --- The Markdown of https://zigbongo.com/docs/erasing-customers/. Every docs page: https://zigbongo.com/llms.txt # Environments and API keys > Every project has a live environment for real traffic and a test environment for development, and each has its own API keys. The key decides where a call goes. ## Live and test environments Each project in the dashboard has two environments: | Environment | For | Billed | |---|---|---| | Live | Real traffic | Yes: live sessions count towards your monthly usage | | Test | Development and staging | No: test sessions are free | - **They work the same.** A test environment behaves like a live one: decisions, outcomes, holdouts, reports, pausing and rate limits. - **They're kept apart.** Each environment has its own flows, data, learning and keys. Nothing learned in test carries over to live, so a flow you take live starts from your defaults there. Data is never pooled across projects or customers either. - **The key decides.** Both use the same base URL, `https://zigbongo.com`; the key you call with decides which environment the call goes to. - **Use the test key while you build.** A flow is created the first time your code asks about it, in whichever environment the key belongs to. The dashboard shows each environment's flows apart (switch between Live and Test on the project's pages), and the organization's Usage page shows the month's live sessions against the free allowance, with the test sessions beside them. The first 10,000 live sessions each month are free ([Pricing](https://zigbongo.com/pricing/)). ## API keys A key looks like this, here as a line in an `.env` file: ```sh ZIGBONGO_KEY=zb_7k2mq9xrtv4h_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef ``` - `zb_` says it's a Zigbongo key, which makes it easy to spot, for you and for a secret scanner. - Then the key id: 12 characters, public, safe to name in a support request. The dashboard lists keys by it (`zb_7k2mq9xrtv4h…`). - Then the secret: 64 hexadecimal characters. The whole key is 80 characters long. A test key and a live key look alike: what makes a key test or live is the environment you created it in. Label your keys so you can tell them apart. Zigbongo stores only a hash of each key, so it can't show you a key again or recover a lost one: create a new one. ## Creating a key On the project's API keys page, each environment has its own list: 1. Under the environment you want, give the key a label if you like, such as "production server", and select "Create key". 2. Copy the key at once: it's shown only this one time. 3. Put it on your server, for example in an environment variable, `ZIGBONGO_KEY`: ```js import { Zigbongo } from "@zigbongo/sdk"; const zb = new Zigbongo({ apiKey: process.env.ZIGBONGO_KEY, baseUrl: "https://zigbongo.com" }); ``` ```php use Zigbongo\Zigbongo; $zb = new Zigbongo(apiKey: getenv('ZIGBONGO_KEY'), baseUrl: 'https://zigbongo.com'); ``` Anyone who can open the project can create and revoke its keys, and the organization's audit log records each one by its key id and label, never the secret. ## Revoking and rotating keys Select "Revoke" next to a key, and again to confirm. Calls with it get `401 unauthorized` on every server within a few seconds, usually about one. A decide call with a revoked key falls back to your default, so watch `onError` ([Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md)). To rotate a key without a gap: 1. Create a new key in the same environment. 2. Deploy it everywhere the old one was used. 3. Check the old key's "Last used" column, which also names the SDK and version that made the last call, until it stops moving. 4. Revoke the old key. Revoke at once any key that may have leaked. ## Keep keys on your server A key acts for your environment: it can make decisions, report outcomes, pause flows and erase customers. So it never leaves your servers: - **Call Zigbongo from your back end only,** never from a browser, a mobile app or a desktop app. The Node.js SDK refuses to load where `window` exists. - **Keep it out of your code,** in an environment variable or your secrets manager, and out of version control and logs. - **One key per server or service,** labelled, so you can revoke one without touching the others. Under the [terms](https://zigbongo.com/terms/), you're responsible for keeping your keys secret, and what's done with them counts as done by you. --- The Markdown of https://zigbongo.com/docs/environments-and-keys/. Every docs page: https://zigbongo.com/llms.txt # HTTP API reference > Every call your server can make to Zigbongo, with its fields, limits and error codes. The Node.js and PHP SDKs make these same calls for you; use this page when you call the API directly or want to know exactly what goes over the wire. ## Conventions ### Base URL The API lives at `https://zigbongo.com/v1`, and every path on this page starts with `/v1`. A dedicated deployment has its own address: your project's quickstart in the app shows it, and the API is under its `/v1`. Call the API from your server only, never from a browser or a mobile app. Anyone holding a key can make every call on this page. ### Authentication Send an API key with every call: ```http Authorization: Bearer $ZIGBONGO_KEY ``` Keys start with `zb_`. Each key belongs to one environment of one project, test or live, and everything a call reads or writes belongs to that environment: flows, sessions, outcomes and reports are never shared between environments or projects. You create and revoke keys on your project's page in the app (see [environments and keys](https://zigbongo.com/docs/environments-and-keys.md)). A missing, unknown or revoked key answers `401 unauthorized`. ### Requests - Bodies are JSON, sent with `Content-Type: application/json`. A body without that header is refused with `400 invalid_input`. - Field names are camelCase. A field a call doesn't know is refused with `400 invalid_input`, so a typo never passes unnoticed. The one exception is the erasure call, which ignores fields it doesn't know. - Optional fields can be left out. - A request body is at most 2 MiB (2,097,152 bytes); a larger one is `413 body_too_large`. Within that, there's no limit on the number of options, nodes, items, inputs or outcomes, or on the length of keys and values, except where this page names one. - Flow keys, node keys and input names travel in paths, so percent-encode them there. A flow key is 1 to 128 characters of `A-Z`, `a-z`, `0-9`, `-`, `_` and `.`. Node keys, input names and subject ids are any non-empty string. None of them may be `.` or `..`: browsers, Node.js and curl drop those from paths. `...`, `.a` and `v2.1` are fine. ### Answers and errors A call that works answers `200` (`201` where this page says so) with a JSON body. A call that fails answers with this body: ```json { "error": { "code": "invalid_input", "message": "options must not be empty" } } ``` Act on `code`; `message` explains the problem in words. These are the codes, and each call below lists the ones it can give for its own reasons: | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | The body, a header or a query parameter is malformed or breaks a rule on this page | | 400 | `invalid_flow` | A flow definition can't be used | | 401 | `unauthorized` | A missing, unknown or revoked key | | 404 | `not_found` | An unknown flow, session, decision, version or node | | 409 | `decision_already_reported` | A decision reported again, differently | | 409 | `session_done` | A registered flow's session has ended | | 413 | `body_too_large` | A body over 2 MiB | | 429 | `rate_limited` | Over a rate limit; see `Retry-After` | | 500 | `internal` | An unexpected error on our side | | 503 | `starting` | Zigbongo has just restarted and hasn't loaded your keys and flows yet: "Zigbongo is starting; try again shortly"; `Retry-After: 1` | | 503 | `overloaded` | Zigbongo is too far behind in storing what it has been sent, such as during a brief outage on our side, so it turns away decide, session, outcome and fallback calls until it catches up: "Zigbongo is overloaded; try again shortly". Nothing of the call is kept; `Retry-After: 1` | | 503 | `timeout` | Zigbongo is too busy to answer in time: "Zigbongo is busy; try again shortly"; `Retry-After: 1`. Never on a decide, session, outcome or fallback call | | 503 | `unavailable` | Zigbongo couldn't take the call for a moment, such as during a restart, or couldn't store it: "Zigbongo couldn't take this call just now; try again shortly", or "Zigbongo is restarting; send this call again"; `Retry-After: 1` | | 503 | `report_timeout` | A report took too long to compute; try again shortly | On a decision call, don't wait for a retry: show your default and report the fallback (see [fallbacks](#post-v1fallbacks)). Every answer carries an `X-Request-Id` header, which names the call in Zigbongo's logs. Include it when you report a problem. ### Rate limits Each environment has three allowances, counted per second, so one kind of traffic never holds up another: | Allowance | Calls | Default limit | | --- | --- | --- | | `decide` | Decide, session start, steps, session events | 1,000 calls a second | | `outcomes` | Outcomes (each outcome in a batch counts), fallbacks | 1,000 a second | | `other` | Everything else: flows, settings, pause and resume, versions, reports, inputs, erasure; and each new flow, whether a decide makes it or a new definition is registered | 20 a second | Each allowance holds one second's worth of calls, so a burst up to the limit passes at once, and it refills at the limit. A call over it answers `429 rate_limited` with a `Retry-After` header in whole seconds (at least 1), and nothing about it is stored. A batch of outcomes needs one call left, then counts all its outcomes, so the calls after a large batch may wait. Registering a definition Zigbongo doesn't have yet counts once more against `other`, whether with [`PUT`](#put-v1flowsflowkey) or inline at a [session start](#post-v1flowsflowkeysessions), and so does a [decide](#post-v1flowsflowkeydecide) for a flow key Zigbongo hasn't seen, which makes the flow: over `other` it answers `429`, and your default shows. These are the defaults: if your traffic needs more, [ask](mailto:hello@zigbongo.com) and we can raise an environment's limits. See [retries and rate limits](https://zigbongo.com/docs/retries-and-rate-limits.md). ### Idempotency Every write can be repeated safely, each in its own way: - **Decisions.** Send an `Idempotency-Key` header with each decide, session start and step: 1 to 200 visible ASCII characters, new for each call (a UUID works well). A call repeated with the same key within 30 seconds answers what it answered the first time, with no new effect, whatever the body says: the decision it made, the session it started, the step it gave. A key already used by another call within those 30 seconds answers `400 invalid_input`. A repeat that reaches another of Zigbongo's servers is decided again; Zigbongo then learns from neither call and counts the session once. The key is also what you name when you report a fallback. - **Outcomes.** `outcomeId` is unique in the environment. The first report with an id is kept, and a repeat changes nothing, even with another value. A repeat usually answers `duplicate`, but may answer `accepted` when it reaches another of Zigbongo's servers or comes more than 10 minutes later; either way it counts once. - **Fallbacks.** A repeated `requestId` is kept once, and may answer `duplicate`. - **Steps.** A step reported again, with the same report, answers what it answered the first time. - **Registration.** Registering the same definition again gives the same version. - **Erasure.** Erasing a subject again finds nothing and answers zeros. Ids are kept with the records they belong to, which are deleted 180 days after their last activity. After that, an old `outcomeId` counts as new and an old `sessionId` is unknown. ### A person's calls Each decide, session start, step and session event about a person can carry a `Zigbongo-Affinity` header: the first 16 hex digits of the SHA-256 of their `subjectId` in UTF-8, so `7593cd8a644e7f9b` for `user_8172`. It lets Zigbongo send all of a person's calls to the same server. It's optional and not used yet; the SDKs send it for you. ### Timestamps, durations and ids - Timestamps in answers are RFC 3339 in UTC, with as many fractional-second digits as needed: `2026-10-11T09:30:00.123456Z`. Days are UTC days, written `2026-10-11`. - A timestamp you send (an outcome's `at`) is RFC 3339 with a time-zone offset: `2026-10-11T11:30:00+02:00` or `2026-10-11T09:30:00Z`. - Durations are ISO 8601, in weeks, days, hours, minutes and seconds: `P1D`, `P30D`, `PT6H`, `P1DT12H`, `P2W`. Years and months are refused, since their length varies, and a duration must be above zero. Answers write days and time only (`P14D` for `P2W`). - The ids Zigbongo makes, `sessionId` and `decisionId`, are UUIDs. Version numbers are integers from 1. ## All endpoints | Method and path | What it does | Allowance | | --- | --- | --- | | [`POST /v1/flows/{flowKey}/decide`](#post-v1flowsflowkeydecide) | Chooses an option at a decision point | `decide` | | [`POST /v1/outcomes`](#post-v1outcomes) | Reports an outcome | `outcomes` | | [`POST /v1/outcomes:batch`](#post-v1outcomesbatch) | Reports many outcomes | `outcomes` | | [`POST /v1/fallbacks`](#post-v1fallbacks) | Reports that you showed your default | `outcomes` | | [`PUT /v1/flows/{flowKey}`](#put-v1flowsflowkey) | Registers a flow definition | `other` | | [`GET /v1/flows/{flowKey}/versions`](#get-v1flowsflowkeyversions) | Lists a registered flow's versions | `other` | | [`GET /v1/flows/{flowKey}/versions/{version}`](#get-v1flowsflowkeyversionsversion) | Reads one version | `other` | | [`POST /v1/flows/{flowKey}/sessions`](#post-v1flowsflowkeysessions) | Starts a session on a registered flow | `decide` | | [`POST /v1/sessions/{sessionId}/steps`](#post-v1sessionssessionidsteps) | Reports a step and gets the next | `decide` | | [`POST /v1/sessions/{sessionId}/events`](#post-v1sessionssessionidevents) | Ends a session as abandoned | `decide` | | [`GET /v1/flows`](#get-v1flows) | Lists your flows | `other` | | [`GET /v1/flows/{flowKey}`](#get-v1flowsflowkey) | Reads a flow's settings and state | `other` | | [`PATCH /v1/flows/{flowKey}`](#patch-v1flowsflowkey) | Changes a flow's settings | `other` | | [`POST /v1/flows/{flowKey}:pause`](#post-v1flowsflowkeypause) | Pauses a flow: everyone sees your default choices | `other` | | [`POST /v1/flows/{flowKey}:resume`](#post-v1flowsflowkeyresume) | Resumes a paused flow | `other` | | [`PATCH /v1/flows/{flowKey}/inputs/{input}`](#patch-v1flowsflowkeyinputsinput) | Switches an input off or on | `other` | | [`GET /v1/flows/{flowKey}/report`](#get-v1flowsflowkeyreport) | The flow's lift, both sides (Zigbongo's choices and the holdout), traffic and fallbacks | `other` | | [`GET /v1/flows/{flowKey}/report/nodes/{node}`](#get-v1flowsflowkeyreportnodesnode) | One decision point in detail | `other` | | [`GET /v1/flows/{flowKey}/report/rules`](#get-v1flowsflowkeyreportrules) | Learned rules and input types | `other` | | [`GET /v1/flows/{flowKey}/report/timeseries`](#get-v1flowsflowkeyreporttimeseries) | Both sides per day, per hour or per minute, with the lift to date | `other` | | [`POST /v1/subjects:erase`](#post-v1subjectserase) | Erases everything about one person | `other` | ## Decisions ### POST /v1/flows/{flowKey}/decide Asks which option to show at one decision point (a node) of a flow. The first call for a person starts a session: one run of the flow for that person, however many decision points it has. Later calls in the same run send its `sessionId`. The flow is created by its first call, with the default settings (see [`PATCH /v1/flows/{flowKey}`](#patch-v1flowsflowkey)); creating it counts against the `other` [rate limit](#rate-limits), so a flow key made per person or per order is refused once past it. Headers: `Authorization: Bearer `, `Content-Type: application/json`, and `Idempotency-Key` (optional, and recommended: it's how a retry stays one decision, and how a [fallback](#post-v1fallbacks) finds its decision). | Field | Type | Description | | --- | --- | --- | | `subjectId` | string | Your stable id for the person. Required to start a session (without `sessionId`). On a later call it may be left out; if sent, it must be the session's. | | `sessionId` | string | The session to continue, from an earlier answer. Leave it out to start a session. | | `node` | string | Required. The decision point's key, the same at every call for it. | | `options` | array of objects | Required, at least one. Each is `{ "key": "..." }`: keys non-empty and unique in the call. An option may carry a `payload` (any JSON), which is accepted and not used. | | `default` | string | Required. The key of the option you'd show today. It must be one of `options`. | | `holdoutPercent` | number | Optional, 0 to 100. The share of people who get your default at this node. Remembered for the node until you send another; 5 until you send one. | | `inputs` | object | Optional. Context about the person: a flat object of strings, numbers, booleans and nulls (null means unknown). Nested objects and arrays are refused. Inputs add up over a session: a later call's value replaces an earlier one of the same name. See [inputs](https://zigbongo.com/docs/inputs.md). | | `result` | object | Optional, on a call that continues a session: what happened at one of the session's decisions. `decisionId` is required in it; any other fields (such as `answer`) are stored as you send them. | The answer is `200`: | Field | Type | Description | | --- | --- | --- | | `sessionId` | string | The session: send it with the run's later calls and its outcome. | | `decisionId` | string | This decision: send it as `result.decisionId` to report what happened. | | `option` | string | The key of the option to show. | | `arm` | string | `optimised`: Zigbongo chose. `holdout`: the person is in the flow's holdout or this node's, and gets your default. `paused`: the flow, or the whole environment, is paused, and everyone gets your default. | Who gets your default: - **The flow's holdout.** When a session starts, its person lands in the flow's holdout or not, by the flow's `holdoutPercent` (5 by default). A person in it gets your default at every node of the session. The draw is a hash of the subject id, so the same person lands on the same side while the share stays the same. The lift is the outcomes of the customers Zigbongo chooses for against the holdout's (see [holdout and lift](https://zigbongo.com/docs/holdout-and-lift.md)). - **A node's holdout.** A further share of people, the node's `holdoutPercent`, get your default at that node. - **A pause.** While the flow is paused, or Zigbongo has stopped choosing for the whole environment (see [terms](https://zigbongo.com/terms/)), every call answers your default with `arm: "paused"`. Ordered sets: to let Zigbongo choose the order of a set of items, ask at the same node again within the session, offering only the items not picked yet. Each pick is learned at its own position: the first at the node, the second at `{node}:2`, the third at `{node}:3`, and the reports list those as decision points of their own. Each session started counts once towards your monthly sessions (see [pricing](https://zigbongo.com/pricing/)). | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | The flow key isn't valid; `node` is empty, `.` or `..`; `options` is empty, or a key is empty or repeated; `default` isn't one of the options; `holdoutPercent` is outside 0 to 100; an input is nested or its name is empty, `.` or `..`; `subjectId` is missing or empty when starting a session, is `.` or `..`, or isn't the session's; `Idempotency-Key` isn't 1 to 200 visible ASCII characters; the session belongs to a registered flow (continue it with its [steps](#post-v1sessionssessionidsteps)) | | 404 | `not_found` | `sessionId` is unknown or belongs to another flow; `result.decisionId` isn't a decision of this session (a call that starts a session has none yet) | | 409 | `decision_already_reported` | `result` reports a decision that already has a different result. The same result again changes nothing. | | 429 | `rate_limited` | Over the `decide` allowance; for a flow key Zigbongo hasn't seen, over `other` | The first call of a session: ```sh curl https://zigbongo.com/v1/flows/checkout/decide \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 9f164011-c7a2-4f1f-801a-a8397535f96e" \ -d '{ "subjectId": "user_8172", "node": "upsell", "options": [{ "key": "none" }, { "key": "annual" }, { "key": "bundle" }], "default": "none", "inputs": { "plan": "monthly", "country": "LT" } }' ``` ```json { "sessionId": "2f488bbe-3503-4f46-9191-7bd56e7d8fbc", "decisionId": "835485ee-cae0-455e-8c3d-4864b6764ced", "option": "annual", "arm": "optimised" } ``` A later call in the same session, reporting what the person did at the previous decision: ```json { "sessionId": "2f488bbe-3503-4f46-9191-7bd56e7d8fbc", "node": "trial_length", "options": [{ "key": "7_days" }, { "key": "14_days" }], "default": "7_days", "result": { "decisionId": "835485ee-cae0-455e-8c3d-4864b6764ced", "answer": "accepted" } } ``` ## Outcomes Outcomes are what Zigbongo optimizes: revenue, margin, a renewal, a cancellation, any number. Each flow has one objective, which says whether higher or lower is better and how a session's outcomes add up (see [`PATCH /v1/flows/{flowKey}`](#patch-v1flowsflowkey) and [sessions and outcomes](https://zigbongo.com/docs/sessions-and-outcomes.md)). ### POST /v1/outcomes Reports one outcome, for a session or for a person. Headers: `Authorization: Bearer ` and `Content-Type: application/json`. | Field | Type | Description | | --- | --- | --- | | `outcomeId` | string | Required, non-empty. Your id for this outcome, such as an invoice id, unique in the environment. | | `flowKey` | string | Required. The flow it's for. | | `sessionId` | string | The session it belongs to, a session of this flow. Send `sessionId` or `subjectId`, not both. | | `subjectId` | string | The person it belongs to: it counts for each of their sessions of this flow whose attribution window holds `at`. Not empty, `.` or `..`. | | `value` | number | Required. Any finite number: money, a count, 1 for a yes. | | `at` | string | Optional. When it happened, as an RFC 3339 timestamp with an offset, from 400 days before Zigbongo receives it to a day after. By default, when Zigbongo receives it. | An outcome counts for a session when `at` falls between the session's first decision and the end of its attribution window: the flow's `objective.window` (one day by default) after that first decision. Up to a minute before the first decision still counts, for clocks that differ. Within a session, outcomes add up by the flow's `aggregate`: `sum` (the default), `max` or `last`. A session with no outcome by the end of its window counts as 0. An outcome outside every window is stored and changes nothing. Outcomes aren't checked against your flows and sessions as they arrive: one for a flow or session Zigbongo doesn't know is accepted and stored, and changes nothing. So a typo in `flowKey` isn't refused; the flow's report shows whether its sessions get their outcomes. The answer is `200`: ```json { "outcomeId": "inv_2041", "status": "accepted" } ``` `status` is `accepted`, or `duplicate` when this `outcomeId` was reported before. A repeat may also read `accepted` (see [idempotency](#idempotency)); either way it counts once. | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | `outcomeId` is empty; `flowKey` isn't a valid flow key; `value` isn't a finite number; neither or both of `sessionId` and `subjectId` are sent, or `subjectId` is empty; `subjectId` is `.` or `..`; `at` isn't a timestamp with an offset, or is more than 400 days before now or more than a day after | | 404 | `not_found` | `sessionId` isn't a UUID, so names no session | ```sh curl https://zigbongo.com/v1/outcomes \ -H "Authorization: Bearer $ZIGBONGO_KEY" \ -H "Content-Type: application/json" \ -d '{ "outcomeId": "inv_2041", "flowKey": "checkout", "subjectId": "user_8172", "value": 119.0, "at": "2026-10-11T09:30:00Z" }' ``` ### POST /v1/outcomes:batch Reports many outcomes in one call, such as a nightly backfill of renewals. Headers: `Authorization: Bearer ` and `Content-Type: application/json`. | Field | Type | Description | | --- | --- | --- | | `outcomes` | array of objects | Required. Each as [`POST /v1/outcomes`](#post-v1outcomes) takes it. As many as fit in 2 MiB: about 25,000. | Each outcome is stored on its own, so one that fails doesn't stop the others. The answer is `200`, with one result per outcome in the order sent: ```json { "results": [ { "outcomeId": "inv_2041", "status": "accepted" }, { "outcomeId": "inv_2042", "status": "duplicate" }, { "outcomeId": "inv_2043", "error": { "code": "invalid_input", "message": "at must be within 400 days before now and a day after" } } ] } ``` A result has `status` (`accepted` or `duplicate`) or `error`, with the `code` and `message` a single report would have answered. An outcome that isn't the right shape (a missing or unknown field, a wrong type) fails the whole batch with `400 invalid_input`. The batch counts each of its outcomes against the `outcomes` allowance. ## Fallbacks ### POST /v1/fallbacks Reports that you showed your default because a decide, session start or step call timed out or failed. The decisions that call made, if it reached Zigbongo, are never learned from, and the reports count the fallback against the node. A fallback that arrives before its decision is matched when the decision lands. The SDKs send these for you (see [fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md)). Headers: `Authorization: Bearer ` and `Content-Type: application/json`. | Field | Type | Description | | --- | --- | --- | | `flowKey` | string | Required, non-empty. The flow of the call. | | `requestId` | string | Required, 1 to 200 characters. The `Idempotency-Key` the call sent. Without one, there's nothing to match. | | `node` | string | Optional. The node you asked about, for the reports when the call never reached Zigbongo. | | `reason` | string | Optional. Why, in a word, such as `timeout`, `network` or `http_503`, as the SDKs send it. | The answer is `200`: ```json { "status": "recorded" } ``` A `requestId` reported before is kept once, and may answer `{ "status": "duplicate" }`. | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | `flowKey` is empty, or `requestId` is empty or over 200 characters | ## Registered flows Registering a flow is optional. A registered flow is a definition of its nodes, their options and defaults, and the routes between them. You start a session on it, and each step is one call that reports the step and gets the next, with Zigbongo following the routes. See [registered flows](https://zigbongo.com/docs/registered-flows.md). ### PUT /v1/flows/{flowKey} Registers a definition and makes it the flow's current version. The flow is created if it's new. New content becomes the next version and answers `201`; content registered before (once its defaults are filled in) is that version again and answers `200`. Either way, the flow's objective, `holdoutPercent` and `explorationFloor` become the definition's, defaults included, replacing what a `PATCH` set; `retentionDays` is kept. Sessions already running stay on the version they started on. New content counts once more against the `other` allowance. Headers: `Authorization: Bearer ` and `Content-Type: application/json`. | Field | Type | Description | | --- | --- | --- | | `key` | string | Required. The flow key, the same as in the path. | | `objective.direction` | string | Required. `maximize` or `minimize`. | | `objective.window` | string | Optional. The attribution window, an ISO 8601 duration. `P1D` by default. | | `objective.aggregate` | string | Optional. How a session's outcomes add up: `sum` (the default), `max` or `last`. | | `holdoutPercent` | number | Optional, 0 to 100, 5 by default. The flow's holdout. | | `explorationFloor` | number | Optional, at least 0 and below 1, 0.02 by default. The smallest share of traffic an option keeps until it's confidently beaten. | | `start` | string | Required. The key of the first node. | | `nodes` | array of objects | Required, at least one. The nodes, as below. | Every node has a `key` (required: non-empty, unique in the flow, not `.` or `..`) and a `type`, and may have `holdoutPercent` (0 to 100: its own holdout, as a decide call's) and `optional` (below). Each type has fields of its own: | `type` | Decides | Its fields | | --- | --- | --- | | `variant` | Which version of a step to show | `options` (required), `next` (required), `defaultRules` | | `branch` | Which node comes next | `options` (required), each with `to` (required); `defaultRules`. No `next`. | | `sequence` | Which item from a set to show next, until all are shown | `items` (required), `defaultOrder` (required), `next` (required). No `defaultRules`. | - **`options`**: `[{ "key": "...", "default": true, "payload": ... }]`. Keys are non-empty and unique in the node, and exactly one option has `"default": true`. `payload` is any JSON, returned with the step. A branch's options each have `to`: the key of the node they lead to, or null to end the flow. - **`items`** and **`defaultOrder`**: a sequence's items are `[{ "key": "...", "payload": ... }]`, and `defaultOrder` lists every item's key exactly once. Each step offers the items not shown yet, in `defaultOrder`, the first of them being the default. The first pick is decided at the node and the `k`-th at `{node}:{k}`. - **`next`**: a node key; null to end the flow; or routing by the step's answer, which Zigbongo follows and never optimizes: `{ "byAnswer": { "yes": "injury", "no": null }, "else": "goal" }`. The answer is `result.answer` at the step: a string as is, a number or boolean as its JSON text (`"3"`, `"true"`). `else` is required, and takes any other answer, or none. - **`optional`**: `{ "default": "include" }` or `{ "default": "skip" }`. Zigbongo decides whether to show the node, at the decision point `{node}:optional`, starting from your default. A skipped node costs no round trip: a variant or sequence goes on to `next` as with no answer (its `else`, when it routes by answer), a branch to where its default option leads. - **`defaultRules`**: your current rules, as the node's starting point: `[{ "when": { "country": "DE", "age": [30, null] }, "option": "14_days" }]`. Top to bottom, the first rule whose every condition matches the session's inputs names the default; when none matches, the option marked default is. A condition is a string (an exact text value), a boolean, or `[min, max]` (numbers, both ends included, null for an open end). A missing or null input matches no condition. An example: ```json { "key": "onboarding", "objective": { "direction": "maximize", "window": "P30D" }, "start": "welcome", "nodes": [ { "key": "welcome", "type": "variant", "options": [ { "key": "short", "default": true }, { "key": "story", "payload": { "slides": 3 } } ], "next": "plan" }, { "key": "plan", "type": "branch", "options": [ { "key": "monthly_first", "to": "trial", "default": true }, { "key": "annual_first", "to": null } ] }, { "key": "trial", "type": "variant", "optional": { "default": "include" }, "options": [ { "key": "7_days", "default": true }, { "key": "14_days" } ], "defaultRules": [{ "when": { "country": "DE" }, "option": "14_days" }], "next": null } ] } ``` The answer, `201` or `200`: | Field | Type | Description | | --- | --- | --- | | `version` | integer | The version number, from 1. | | `hash` | string | The SHA-256 of the definition, defaults filled in, in hex. | | `createdAt` | timestamp | When this content was first registered. | | `registeredAt` | timestamp | When it was last registered. | | `current` | boolean | Whether it's the flow's current version: always true here. | | `definition` | object | The definition as stored: every setting filled in, the window in normal form. | | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | The flow key in the path isn't valid; the body isn't JSON | | 400 | `invalid_flow` | The definition can't be used. The message lists every problem found, each naming where it is: `key` differs from the path's; `objective.window` isn't a duration; `holdoutPercent` or `explorationFloor` is out of range; a node has a missing, unknown or repeated field, or a wrong type; `nodes`, `options` or `items` is empty; a key is empty or repeated; a node hasn't exactly one default option; `defaultOrder` doesn't list each item once; a rule names an option the node hasn't, tests no input, tests an input named `""`, `.` or `..`, has `[null, null]`, or a minimum above its maximum; `start`, a `next`, a `to` or an answer route names a key that isn't a node; a node can't be reached from `start`; the nodes form a cycle (a flow is a directed acyclic graph); a node key is `.` or `..`; a node key is another node's decision point (`{node}:optional` of an optional node, or `{node}:2` up to `{node}:{n}` of a sequence of `n` items) | ### GET /v1/flows/{flowKey}/versions Headers: `Authorization: Bearer `. Lists the flow's versions, oldest first, without their definitions: ```json { "current": 2, "versions": [ { "version": 1, "hash": "3bfc269594ef649228e9a74bab00f042efc91d5acc6fbee31a382e80d42388fe", "createdAt": "2026-10-01T08:12:44.512830Z", "registeredAt": "2026-10-01T08:12:44.512830Z" }, { "version": 2, "hash": "9f785dc763e5bbe60963fc4e7ba26152f17de39c5be86eb69dd42e1fbeab3925", "createdAt": "2026-10-09T14:03:10.020114Z", "registeredAt": "2026-10-11T07:55:31.877406Z" } ] } ``` `current` is null when the flow was never registered. `404 not_found` for an unknown flow. ### GET /v1/flows/{flowKey}/versions/{version} Reads one version, with its definition. `{version}` is a version number. Headers: `Authorization: Bearer `. The answer is `200`, in the shape [`PUT`](#put-v1flowsflowkey) answers, where `current` says whether it's the flow's current version. `404 not_found` for an unknown flow or version. ### POST /v1/flows/{flowKey}/sessions Starts a session on a version of a registered flow, and decides its first step. Headers: `Authorization: Bearer `, `Content-Type: application/json`, and `Idempotency-Key` (optional: the same key again within 30 seconds answers the session it started, with no new session; see [idempotency](#idempotency)). | Field | Type | Description | | --- | --- | --- | | `subjectId` | string | Required. Your stable id for the person: non-empty, not `.` or `..`. | | `version` | integer or string | Optional. A version number, or `"latest"` (the default): the current version. | | `flow` | object | Optional. A definition, and the session runs on it. Content Zigbongo already has runs as that version, and nothing is written: it doesn't become the current version or set the flow's settings again, so you can send it with every session. New content is registered as [`PUT`](#put-v1flowsflowkey) registers it, as the current version, and counts against the `other` allowance; that start answers once the version is stored, which can take longer than your SDK waits, so the first session with new content may follow the definition's defaults. Not together with `version`. | | `inputs` | object | Optional. As in [decide](#post-v1flowsflowkeydecide). | | `segment` | string | Optional. Short for the input `segment`; send it one way, not both. | The answer is `201`: ```json { "sessionId": "64ead2e3-8890-4ddc-8e93-4339f7ff22e6", "version": 2, "arm": "optimised", "step": { "decisionId": "10fcadbd-feed-4a71-a0b7-87a4067751aa", "node": "welcome", "option": "story", "arm": "optimised", "payload": { "slides": 3 } }, "done": false } ``` | Field | Type | Description | | --- | --- | --- | | `sessionId` | string | The session. | | `version` | integer | The version it runs on, to its end. | | `arm` | string | `paused` when the flow (or the environment) was paused at the start, `holdout` when the person is in the flow's holdout (every step gets your default), otherwise `optimised`. | | `step` | object or null | The first step: `decisionId`, `node` (the node's key; a sequence's for each of its items), `option`, `arm` (each step has its own, since a node can have its own holdout) and `payload` (the option's, or null). Null when Zigbongo skipped every node to the end. | | `done` | boolean | True when the flow has ended. | | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | `subjectId` is missing, empty, `.` or `..`; `version` isn't a number or `"latest"`; `version` and `flow` are both sent; `segment` is sent both ways; an input is nested or badly named; the flow key isn't valid; `Idempotency-Key` is malformed, or was used by another call | | 400 | `invalid_flow` | The inline `flow` can't be used (as for `PUT`); the version can't run, because a node key is another node's decision point | | 404 | `not_found` | The flow is unknown, has never been registered, or has no such version | | 429 | `rate_limited` | Over the `decide` allowance; with new `flow` content, over `other` | | 503 | `unavailable` | New `flow` content couldn't be registered within 2 seconds; a later start with it tries again | ### POST /v1/sessions/{sessionId}/steps Reports the session's open step and decides the next one, or ends the session where the flow ends. Headers: `Authorization: Bearer `, `Content-Type: application/json`, and `Idempotency-Key` (optional, for fallbacks). | Field | Type | Description | | --- | --- | --- | | `decisionId` | string | Required. The step you're reporting: the last step's `decisionId`. | | `shown` | boolean | Optional, true by default. False when you didn't show the step's option, such as after a fallback: the decision isn't learned from, nor is the node's inclusion when Zigbongo decided it with this step. The session still routes by Zigbongo's choice. | | `result` | object | Optional, `{}` by default. What happened, stored as you send it. Its `answer` drives `byAnswer` routing. | | `inputs` | object | Optional. As in [decide](#post-v1flowsflowkeydecide); added to the session's. | | `state` | object | Optional. The run at the step you're reporting, as you keep it: `flowKey`, `version` (the session's), `subjectId`, `node` and `option` (the step's), `shown` (the items of a sequence shown so far at this node, this step's included) and `inputs` (the session's so far, this call's included). Every field is required in it. The SDKs send it with every step. Zigbongo checks it and doesn't use it yet; a later release will continue the session from it on whichever server takes the call, and require it. | The answer is `200`: `{ "step": ..., "done": false }`, with `step` as the session start's. At the end of the flow, `step` is null and `done` is true. A decision reported again with the same `shown` and `result` answers what it answered the first time, with no further effect. A step that reports a decision made more than 30 minutes before finds the session abandoned: it answers `409 session_done`, the session ends then, at that step, and you carry on with your defaults or start a new session. | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | The session runs step by step (continue it with [decide](#post-v1flowsflowkeydecide)); an input is nested or badly named; `state` is malformed; `Idempotency-Key` is malformed, or was used by another call | | 404 | `not_found` | The session is unknown; `decisionId` isn't a step of this session | | 409 | `decision_already_reported` | The step was reported before, with a different `shown` or `result` | | 409 | `session_done` | The session has ended, or the step reports a decision made more than 30 minutes before | ### POST /v1/sessions/{sessionId}/events Tells Zigbongo the person left: the session ends, abandoned at its last step. Headers: `Authorization: Bearer ` and `Content-Type: application/json`. | Field | Type | Description | | --- | --- | --- | | `type` | string | Required. `abandoned`, the only type. | | `state` | object | Optional. The run at the step the person left, as for a [step](#post-v1sessionssessionidsteps). | The answer is `200`: ```json { "sessionId": "64ead2e3-8890-4ddc-8e93-4339f7ff22e6", "status": "abandoned", "node": "plan", "endedAt": "2026-10-11T09:41:07.204551Z" } ``` `node` is the step it ended at. `endedAt` is now, or when the session ended before, such as when a step found it quiet. Abandoning it again answers the same. | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | `type` isn't `abandoned`; `state` is malformed; the session runs step by step | | 404 | `not_found` | The session is unknown | | 409 | `session_done` | The session has already finished: it reached the end of the flow | ## Flows ### GET /v1/flows Headers: `Authorization: Bearer `. Lists the environment's flows, by key: ```json { "flows": [ { "key": "checkout", "status": "learning", "createdAt": "2026-09-14T10:02:31.118204Z", "lastDecisionAt": "2026-10-11T09:29:58.903117Z" }, { "key": "onboarding", "status": "paused", "createdAt": "2026-10-01T08:12:44.512830Z", "lastDecisionAt": null } ] } ``` `status` is `learning` or `paused`. `lastDecisionAt` is when the flow last made a decision, accurate to about a minute; null before the first. ### GET /v1/flows/{flowKey} Headers: `Authorization: Bearer `. Reads a flow's settings and state: | Field | Type | Description | | --- | --- | --- | | `key` | string | The flow key. | | `status` | string | `learning`: Zigbongo chooses (the dashboard's "optimizing"). `paused`: everyone sees your default choices. | | `direction` | string | `maximize` or `minimize`. | | `attributionWindow` | string | The attribution window, an ISO 8601 duration. | | `aggregate` | string | `sum`, `max` or `last`. | | `holdoutPercent` | number | The flow's holdout. | | `explorationFloor` | number | The exploration floor. | | `excludedInputs` | array of strings | The inputs switched off, sorted. | | `retentionDays` | integer | Days after which inputs and step results are forgotten. | | `currentVersion` | integer or null | The version registered last; null for a flow never registered. | | `createdAt` | timestamp | When the flow was created. | | `lastDecisionAt` | timestamp or null | As in [`GET /v1/flows`](#get-v1flows). | | `snapshot` | object or null | What Zigbongo currently decides from: its `version`, and `createdAt`, when Zigbongo last updated it. Null until Zigbongo first updates it. | | `nodes` | array of objects | Every decision point seen, by key: `key`, `holdoutPercent` (5 when none was set) and `createdAt`. Includes the points of optional nodes (`{node}:optional`) and of ordered sets (`{node}:2` and on). | `404 not_found` for an unknown flow. ### PATCH /v1/flows/{flowKey} Changes a flow's settings. Only the fields you send change. The flow is created if it's new, with these defaults: `maximize`, a window of `P1D`, `sum`, a 5% holdout, an exploration floor of 0.02 and a retention period of 90 days. Headers: `Authorization: Bearer ` and `Content-Type: application/json`. | Field | Type | Description | | --- | --- | --- | | `objective.direction` | string | `maximize` or `minimize`. | | `objective.window` | string | The attribution window: an ISO 8601 duration above zero, such as `P30D` for renewals. | | `objective.aggregate` | string | How a session's outcomes add up: `sum`, `max` or `last`. | | `holdoutPercent` | number | 0 to 100. The share of people who get your defaults at every node, to measure the lift. | | `explorationFloor` | number | At least 0 and below 1. The smallest share of traffic an option keeps until it's confidently beaten. | | `retentionDays` | integer | 1 to 36,500. Days after which a session's inputs (from its last call) and step results (from when they were reported) are forgotten. | The answer is `200`, with the flow's settings: ```json { "key": "checkout", "status": "learning", "direction": "maximize", "attributionWindow": "P30D", "aggregate": "sum", "holdoutPercent": 5.0, "explorationFloor": 0.02, "excludedInputs": [], "retentionDays": 90 } ``` The fields are as [`GET`](#get-v1flowsflowkey) answers them. A change applies on every server within a few seconds, usually about one. A new window applies to the sessions already open, not only to new ones: with a shorter one, those whose new window has passed close within seconds; with a longer one, they stay open longer. A session whose window had closed stays closed. Registering a definition sets the objective, `holdoutPercent` and `explorationFloor` back to the definition's. | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | The flow key isn't valid; a value is outside what the table allows; the window isn't a duration | ### POST /v1/flows/{flowKey}:pause Pauses the flow: within a few seconds, usually about one, every decision in it answers your default, on every server, with `arm: "paused"`, and those decisions aren't learned from. Sessions that see the flow paused are left out of the lift comparison. See [pausing flows](https://zigbongo.com/docs/pausing-flows.md). Headers: `Authorization: Bearer `. No body. The answer is `200`, with the flow's settings as [`PATCH`](#patch-v1flowsflowkey) answers them, `status` `paused`. Pausing a paused flow changes nothing. `404 not_found` for an unknown flow: pausing doesn't create one. ### POST /v1/flows/{flowKey}:resume Resumes a paused flow: Zigbongo starts choosing again. Headers: `Authorization: Bearer `. No body. The answer is `200`, with the flow's settings, `status` `learning`. `404 not_found` for an unknown flow. ### PATCH /v1/flows/{flowKey}/inputs/{input} Switches an input off, or back on, for the flow, on every server within a few seconds. A switched-off input is left out of every decision from then on, so nothing learns from it; its values are still stored, and counted in the [rules report](#get-v1flowsflowkeyreportrules). Any input name works, sent yet or not. The flow is created if it's new. Headers: `Authorization: Bearer ` and `Content-Type: application/json`. | Field | Type | Description | | --- | --- | --- | | `use` | boolean | Required. `false` switches the input off, `true` back on. | The answer is `200`: ```json { "input": "age", "use": false } ``` | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | The input name is `.` or `..`; the flow key isn't valid; `use` is missing or not a boolean | ## Reports Some of a report's numbers are counts Zigbongo keeps, so they trail the calls a little: `covers.countedThrough` in the flow report says up to when. "Recent" means today (UTC) and the six days before. Every report answers `404 not_found` for an unknown flow, and may answer `503 report_timeout` when it takes too long; try again shortly. See [holdout and lift](https://zigbongo.com/docs/holdout-and-lift.md). ### GET /v1/flows/{flowKey}/report The flow's lift against its holdout, both sides' sessions, traffic per node and option, and fallback rates. Headers: `Authorization: Bearer `. | Field | Type | Description | | --- | --- | --- | | `flowKey` | string | The flow. | | `computedAt` | timestamp | When the report was computed. | | `direction`, `aggregate`, `attributionWindow`, `holdoutPercent` | | The flow's settings. | | `outcome` | string or null | `binary` when every closed session's outcome is 0 or 1, `numeric` otherwise; null before any session has closed. | | `outcomeOutage` | object or null | Set while the flow's outcomes have stopped arriving, as when a purchase webhook fails: `since` (timestamp), when it began; `usualShare`, the share of sessions that usually have an outcome; `recentShare`, the share since. Zigbongo doesn't learn from the sessions that end meanwhile, so the missing outcomes don't count against the options shown, and keeps choosing from what it had learned. Null otherwise. | | `arms.optimised`, `arms.holdout` | object | Each side's sessions, below. | | `lift` | object | The comparison, below. | | `fallbacks`, `recentFallbacks` | object | `count`: the fallbacks reported; `rate`: over the decide calls (decisions, plus calls that never reached Zigbongo), null without any. | | `nodes` | array of objects | Each decision point, below. | | `covers` | object | What the report covers, below. | Each side, `arms.optimised` and `arms.holdout`: | Field | Type | Description | | --- | --- | --- | | `sessions` | integer | Sessions in the comparison. | | `closed` | integer | Sessions whose attribution window has ended: their outcome is final, and no outcome counts as 0. | | `pending` | integer | Sessions still in their window, counted neither as 0 nor in the comparison. | | `pendingWithOutcome` | integer | Pending sessions with an outcome so far. | | `withOutcome` | integer | Closed sessions with an outcome other than 0. | | `outcomeRate` | number or null | `withOutcome` over `closed`; null while none has closed. | | `outcomeSum` | number | The closed sessions' outcomes, added up. | | `outcomeMean` | object or null | The mean outcome per closed session, `{ "estimate", "low", "high" }`, with a 95% interval (Wilson for 0 or 1 outcomes, t otherwise). `low` and `high` are null until there's an interval; the whole is null while none has closed. | `lift`: | Field | Type | Description | | --- | --- | --- | | `status` | string | `collecting` (the dashboard's "Gathering data") until each side has 20 closed sessions with an outcome other than 0; then `significant` ("Clearly better" or "Clearly worse") when the difference's interval excludes zero, `not_significant` ("No clear difference yet") when it doesn't. | | `minimumOutcomes` | number | 20. | | `test` | string or null | `two_proportions` for 0 or 1 outcomes, `welch` otherwise; null while collecting. | | `sequential` | boolean | Always true: the intervals hold however often you read the report, so acting the moment `status` is `significant` is sound. | | `difference` | object or null | The mean of the customers Zigbongo chooses for (`arms.optimised`) minus the holdout's, in the outcome's units (for 0 or 1 outcomes, a difference of rates), as `{ "estimate", "low", "high" }`. While collecting, an estimate without an interval, once both sides have closed sessions. | | `relative` | object or null | Their mean over the holdout's, minus one, the same way. Its interval comes from the same test as `status`, so it excludes zero exactly when `status` is `significant`. `high` is null while the holdout's mean is too uncertain to bound the ratio, as with revenue just past 20 outcomes: every value above `low` is then possible. Null when it can't be computed, such as when the holdout's mean is 0. | | `better` | string or null | `optimised` or `holdout`, by the flow's direction, once `status` is `significant`; null until then. | Each of `nodes`: | Field | Type | Description | | --- | --- | --- | | `node` | string | The decision point. | | `holdoutPercent` | number | Its holdout. | | `decisions`, `recentDecisions` | object | Decisions by kind: `optimised` (Zigbongo chose), `holdout`, `paused`. | | `fallbacks`, `recentFallbacks` | object | `count` and `rate`, as for the flow. | | `inconsistencies` | array of strings | For decision points asked step by step: `options_vary` when recent sessions were offered different options, `default_varies` when they had different defaults. Notices, not errors. | | `options` | array of objects | Each option's traffic: `option`, `allTime` and `recent`, each `{ "decisions": { "optimised", "holdout", "paused" }, "share" }`, where `share` is the option's share of the decisions Zigbongo chose at the node (null when there are none). | `covers`: | Field | Type | Description | | --- | --- | --- | | `sessions` | integer | Sessions in the comparison: those that never saw the flow paused. | | `pausedSessions` | integer | Sessions left out because they saw it paused. | | `firstSessionAt`, `lastSessionAt` | timestamp or null | The first and last session's start. | | `recentFrom` | date | The first day counted as recent. | | `countedThrough` | timestamp | The decision counts include everything logged before this instant. | ### GET /v1/flows/{flowKey}/report/nodes/{node} One decision point in detail: what Zigbongo believes about each option, what happened after it, and its traffic per day. `{node}` is any decision point the flow lists, such as `trial`, `trial:optional` or `quiz:2`; `404 not_found` for another. Headers: `Authorization: Bearer `. | Query parameter | Type | Description | | --- | --- | --- | | `days` | integer | Optional, 1 to 90, 30 by default: how many days `days` covers. | | Field | Type | Description | | --- | --- | --- | | `flowKey`, `node`, `computedAt`, `holdoutPercent` | | As in the flow report. | | `model` | string or null | `cells` for a node learned without inputs, `probit` for one learned from inputs; null before Zigbongo first updates what it decides from. | | `snapshot` | object or null | What Zigbongo decided from, as in the flow's settings: `version` and `createdAt`. | | `outcome` | string or null | `binary` or `numeric`, as in the flow report. | | `sessions` | object | `allTime` and `recent`: sessions that asked at this point step by step, counted at their first call at it. | | `inconsistencies` | array of strings | As in the flow report. | | `options` | array of objects | Each option, below. | | `days` | array of objects | Its traffic per day (UTC), for the last `days` days, every day present, today included: each `{ "date", "options" }`, where `options` lists every option with decisions on any of those days, in key order, each `{ "option", "decisions": { "optimised", "holdout", "paused" }, "share" }`, `share` being its share of the decisions Zigbongo chose that day (null on a day with none). | Each option: | Field | Type | Description | | --- | --- | --- | | `option` | string | The option's key. | | `allTime`, `recent` | object | Its traffic, as in the flow report. | | `posterior` | object or null | For a `cells` node: Zigbongo's belief about the option's outcome, on a 0 to 1 scale (for 0 or 1 outcomes, the rate; otherwise, the outcome's rank among recent positive outcomes): `mean`, `low` and `high` (a 95% interval), `trials` (the evidence behind it, after older evidence fades, open sessions included) and `pBest` (the probability that it's the best option). | | `predicted` | object or null | For a `probit` node: `rate` (the predicted success rate, averaged over the node's recent contexts), `low` and `high` (its 95% interval), `trials`, `pBest` (the probability that it's the best option on average over those contexts, as `rate` is) and `bestFor` (the probability that it's the best option for one of those contexts, picked at random: about the share of people it suits, once Zigbongo is sure). Where an input decides the answer, an option can be best for half the people and still be unlikely to be best on average. `rate` is over everyone, unlike `observed`, which counts only the people Zigbongo chose the option for. | | `observed` | object or null | What happened after the decisions Zigbongo learned from, once their sessions closed: `closed`, `withOutcome`, `outcomeRate`, `outcomeMean` (`{ "estimate", "low", "high" }`, as in the flow report) and `dropOff` (the share of those sessions that ended at this decision without an outcome). | | `offered` | object or null | For decision points asked step by step: `allTime` and `recent`, each `{ "sessions", "share", "asDefault" }` (the sessions whose first call here offered the option, their share of the node's sessions, and those in which it was the default), and `firstDay` and `lastDay` it was offered. Null when it never was. | `400 invalid_input` when `days` isn't a whole number from 1 to 90. ### GET /v1/flows/{flowKey}/report/rules What Zigbongo found about inputs: each input's type, and for each node learned from inputs, readable rules such as "for `country` `DE`, `14_days` is best". See [inputs](https://zigbongo.com/docs/inputs.md). Headers: `Authorization: Bearer `. | Field | Type | Description | | --- | --- | --- | | `flowKey`, `computedAt` | | As in the flow report. | | `snapshot` | object or null | What Zigbongo decided from, as in the node report; null before Zigbongo first updates it, when `nodes` is empty. | | `inputs` | array of objects | Every input seen or switched off, below. | | `nodes` | array of objects | Each node learned from inputs, below. | Each of `inputs`: | Field | Type | Description | | --- | --- | --- | | `input` | string | Its name. | | `use` | boolean | False once [switched off](#patch-v1flowsflowkeyinputsinput). | | `type` | string or null | `number`, `boolean` or `text`, fixed by its first 1,000 values; null until then. | | `observations` | integer | Decisions that carried it (a session's inputs count at each of its decisions). | | `byType` | object | The same, by type: `{ "number": 980, "text": 20 }`. | | `ignored` | integer | Values of another type since its type was fixed, which learning leaves out. | | `lastIgnoredAt` | timestamp or null | When the last of those arrived. | Each of `nodes`: | Field | Type | Description | | --- | --- | --- | | `node` | string | The decision point. | | `options` | array of objects | Each option's `option`, `rate`, `low`, `high`, `trials`, `pBest` and `bestFor`, as `predicted` in the node report. | | `overall` | object or null | The option predicted best on average over everyone: `best`, and `confidence`, the probability that it beats the runner-up. | | `rules` | array of objects | One per input value: `input`; `equals` for a text or boolean value (booleans as `"true"` and `"false"`), or `from` (included) and `to` (excluded) for a numeric bin learned from the input's values, null for an open end; `best`, the option predicted best for people with that value; `confidence`, the probability that it beats the runner-up; `standsOut`, true when that value changes the answer: `best` isn't `overall`'s, and `confidence` is at least 95%, more for an input with many values (`1 − 0.2 / values`); and `options`, each with `option`, `rate` (the predicted success rate for those people) and `support` (the evidence behind it). | | `combinations` | array of objects | Rules about two inputs together, listed where they point to another option than the single rules would: `when` (two conditions, each as in a rule; a number's bin here is two of its single bins together), `best`, `confidence` and `options`. | Switched-off inputs have no rules or combinations. ### GET /v1/flows/{flowKey}/report/timeseries Both sides of the flow per day of the sessions' start (UTC), for the last `days` days, every day present, today included; or per hour, for the last `hours` hours; or per minute, for the last `minutes` minutes. Each day, hour or minute carries the lift to date: the comparison over the sessions started up to its end. Headers: `Authorization: Bearer `. | Query parameter | Type | Description | | --- | --- | --- | | `days` | integer | Optional, 1 to 90, 30 by default. | | `hours` | integer | Optional, 1 to 72, instead of `days`: per clock hour (UTC), the current one last. | | `minutes` | integer | Optional, 1 to 480, instead of `days`: per clock minute (UTC), the current one last. | | Field | Type | Description | | --- | --- | --- | | `flowKey`, `computedAt` | | As in the flow report. | | `from` | date, or timestamp | The first day, or with `hours` or `minutes` the first hour's or minute's start. | | `days` | array of objects | Each `{ "date", "optimised", "holdout", "liftToDate" }`. Each side has `sessions`, `closed`, `pending`, `pendingWithOutcome`, `withOutcome`, `outcomeSum`, `outcomeRate` and `outcomeMean` (a number, without an interval), as in the flow report's two sides (`arms`). `liftToDate` is the flow report's `lift` over the sessions started up to the end of the day, since the flow's first: the last day's is the flow report's. Its interval holds however often you read it, so it holds at every day. | | `hours` | array of objects | With `hours`, instead of `days`: each `{ "start", "optimised", "holdout", "liftToDate" }`, as a day. | | `minutes` | array of objects | With `minutes`, instead of `days`: each minute as an hour. | `400 invalid_input` when `days` isn't a whole number from 1 to 90, `hours` from 1 to 72, `minutes` from 1 to 480, or more than one of them is given. ## Subjects ### POST /v1/subjects:erase Erases everything Zigbongo holds about one person, in every flow of the environment, at once: their sessions and decisions, the fallbacks reported for those, their outcomes (by session or by subject), every logged event that names them, and their sessions still open for learning, so they're never learned from. What Zigbongo already learned from closed sessions, and the daily counts, stay: they're statistics about no one. The id goes in the body, so no URL, and no log of URLs, ever holds it. See [erasing customers](https://zigbongo.com/docs/erasing-customers.md). Headers: `Authorization: Bearer ` and `Content-Type: application/json`. | Field | Type | Description | | --- | --- | --- | | `subjectId` | string | Required, non-empty. The person's id, as you sent it. | The answer is `200`, with the stored records it erased: ```json { "subjectId": "user_8172", "sessions": 3, "decisions": 7, "outcomes": 2 } ``` An unknown subject answers zeros, so a repeat is harmless. A call about the person still on its way when the erasure runs isn't counted, and is discarded when it arrives. Erasure waits for any learning in progress on the person's flows, so it can take up to a minute. Give your HTTP client a timeout over 60 seconds (the SDKs wait 65). An erasure that gives up part way may have erased some of what it found, so when the client gives up before the answer, or gets `503 timeout` or any other error, erase again: that finishes it. | Status | `code` | When | | --- | --- | --- | | 400 | `invalid_input` | `subjectId` is missing or empty | --- The Markdown of https://zigbongo.com/docs/api/. Every docs page: https://zigbongo.com/llms.txt