# Get a Routing Recommendation

This endpoint recommends which of **your own provider accounts** to route a payment to, based on the outcome history you send WHITELABEL through the [Transaction Reporting API](/reference/reporting/report-transactions). You send the payment context and the candidates you can actually use; WHITELABEL returns the recommended candidate, a full ranking with per-candidate metrics, and a `recommendation_id`.

The transaction itself never passes through WHITELABEL. **WHITELABEL recommends; you decide and process.**

<Note>
**Enabled per organization** — this API requires activation for your organization. Contact your Key Account Manager (KAM) to enable it. Until then every call returns `403 PRODUCT_NOT_ENABLED`.
</Note>

## How it works

1. You report your off-WHITELABEL transaction outcomes through the [Transaction Reporting API](/reference/reporting/report-transactions). Only payments with `origin: REPORTED` feed the statistics — WHITELABEL-processed traffic is a different population and is deliberately kept out.
2. Before routing a payment, you call this endpoint with the payment context and your candidate providers.
3. WHITELABEL computes statistics per candidate — approval rate, average provider latency, sample size — over a rolling **30-day** window of your reported payments, segmented by provider, country and payment method — by card BIN when you send one (see [BIN-level statistics](#bin-level-statistics)), and by `CIT`/`MIT` initiation when you send one (see [initiation-level statistics](#initiation-level-statistics)) — and returns the ranking ordered by your objective.
4. You route the payment yourself and report its outcome. If the reported event carries the same `merchant_order_id` you sent here, WHITELABEL attributes the outcome to this recommendation automatically — closing the loop without you storing `recommendation_id`.

Only reported payments in a terminal status feed the approval rate: `SUCCEEDED` counts as approved and `SUCCEEDED + DECLINED` as decided. Payments in any other status (e.g. `ERROR`, pending) are ignored for the rate and latency, though they still count toward `sample_size`.

## Request body

<ParamField body="account_id" type="string (UUID)" required>
  The merchant account the recommendation is issued for. Travels in the body; WHITELABEL promotes it to the account header internally. Must belong to the organization of the API credentials.
</ParamField>

<ParamField body="merchant_order_id" type="string">
  Optional merchant-supplied order reference (max 255). Stored with the issued recommendation as the correlation key for closed-loop attribution.
</ParamField>

<ParamField body="payment" type="object" required>
  The payment context the recommendation is scored against.
  <Expandable title="properties">
    <ParamField body="amount" type="object" required>
      <Expandable title="properties">
        <ParamField body="currency" type="string" required>
          ISO 4217 currency code, e.g. `USD`.
        </ParamField>
        <ParamField body="value" type="number" required>
          Transaction amount. Must be `≥ 0`.
        </ParamField>
      </Expandable>
    </ParamField>
    <ParamField body="country" type="string" required>
      ISO 3166-1 alpha-2 country code, e.g. `US`. Selects the statistics segment.
    </ParamField>
    <ParamField body="payment_method" type="object" required>
      <Expandable title="properties">
        <ParamField body="type" type="string" required>
          E.g. `CARD`, `PIX`, `WALLET`. Selects the statistics segment.
        </ParamField>
        <ParamField body="details" type="object">
          Optional. `card.bin` — the card's BIN, exactly **6 or 8 digits**. When that BIN has enough reported history, the ranking is scored on its own statistics (see [BIN-level statistics](#bin-level-statistics)); otherwise, or for any other value, the statistics fall back to country and payment method.
        </ParamField>
      </Expandable>
    </ParamField>
    <ParamField body="initiation" type="enum">
      Optional. `CIT` (cardholder-initiated) or `MIT` (merchant-initiated). When you send it, and the same initiation has enough reported history in the segment, the ranking is scored on that initiation's own statistics (see [initiation-level statistics](#initiation-level-statistics)); otherwise it falls back to the whole segment. Omit it to rank on the whole segment exactly as before.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="candidates" type="object[]" required>
  The providers to rank. Between **2 and 20** items — a recommendation over a single candidate is meaningless.
  <Expandable title="item">
    <ParamField body="provider_id" type="string" required>
      Provider code, e.g. `ADYEN`, `STRIPE`, `DLOCAL`.
    </ParamField>
    <ParamField body="merchant_connection_id" type="string">
      Optional passthrough for your own bookkeeping — returned exactly as sent, not validated.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="optimize_for" type="enum" default="APPROVAL_RATE">
  The objective the ranking optimizes. `APPROVAL_RATE` (default), `LATENCY`, or `BALANCED`.
</ParamField>

## Response

<ResponseField name="recommendation_id" type="string">
  Unique identifier of the issued recommendation. A fresh id is generated on every call.
</ResponseField>
<ResponseField name="merchant_order_id" type="string">
  Echo of the request field, when supplied; `null` otherwise.
</ResponseField>
<ResponseField name="optimized_for" type="enum">
  The objective applied to the ranking.
</ResponseField>
<ResponseField name="decision_source" type="enum">
  How the ranking was decided — `MERCHANT_HISTORY` or `INSUFFICIENT_DATA` (see below).
</ResponseField>
<ResponseField name="recommended" type="object">
  The top of the ranking. Always present.
  <Expandable title="properties">
    <ResponseField name="provider_id" type="string">The recommended provider code.</ResponseField>
    <ResponseField name="merchant_connection_id" type="string">The candidate's `merchant_connection_id`, when it was supplied.</ResponseField>
  </Expandable>
</ResponseField>
<ResponseField name="ranking" type="object[]">
  Every candidate, ordered by the objective.
  <Expandable title="item">
    <ResponseField name="provider_id" type="string">Provider code.</ResponseField>
    <ResponseField name="merchant_connection_id" type="string">The candidate's `merchant_connection_id`, when it was supplied.</ResponseField>
    <ResponseField name="approval_rate" type="number">`SUCCEEDED / (SUCCEEDED + DECLINED)` over the reported history, `0`–`1`. `null` when there is no data.</ResponseField>
    <ResponseField name="avg_latency_ms" type="integer">Average authorization latency in milliseconds over `SUCCEEDED + DECLINED`. `null` when there is no data.</ResponseField>
    <ResponseField name="sample_size" type="integer">Total reported payments in the segment over the window, across all statuses — how much history backs this candidate's metrics.</ResponseField>
  </Expandable>
</ResponseField>

### Reading the response

- **`recommended` is always present** — even without enough history. You never need a special branch: `decision_source` tells you how much to trust it.
- **`decision_source: MERCHANT_HISTORY`** — at least one candidate reached the minimum sample; the ranking reflects real statistics over your reported payments.
- **`decision_source: INSUFFICIENT_DATA`** — no candidate reached the minimum sample of recent reported events. The full ranking still comes back, and the recommendation falls back to the best available data, or to request order as a last resort. Read each candidate's `sample_size` to see how much history backs it before relying on the order.
- **`sample_size`** is the honesty of the recommendation. A high approval rate over 12 events is not the same signal as one over 12,000.
- **The full `ranking` always comes back**, ordered by your objective. If the recommended candidate declines, take the next entry — cascade retry without a second call.

## BIN-level statistics

If you report the card BIN on your `CARD` events (`payment_method_details.card.bin` in the [Transaction Reporting API](/reference/reporting/report-transactions)), send the same BIN here in `payment.payment_method.details.card.bin`. For each candidate, the ranking uses the most specific segment that reaches the minimum sample, in the payment's country:

1. **8-digit BIN** — when you send 8 digits and that exact BIN has enough reported history.
2. **6-digit BIN** — the first 6 digits (also the segment used when you send a 6-digit BIN).
3. **Country** — provider, country and payment method, as without a BIN.
4. **Payment method** — provider and payment method across countries.

A BIN with no reported history simply falls through to the country and payment-method segments: the response is exactly what you would get without sending it. A value that is not exactly 6 or 8 digits is ignored, never rejected.

## Initiation-level statistics

If you report `initiation` (`CIT` or `MIT`) on your events (in the [Transaction Reporting API](/reference/reporting/report-transactions)), send the same `payment.initiation` here. CIT and MIT approve very differently per provider, so — at each segment level above — the ranking first tries the history with the **same initiation**, and only if that does not reach the minimum sample does it use the whole level. The effective order is: BIN8 + initiation → BIN8 → BIN6 + initiation → BIN6 → country + initiation → country → payment method + initiation → payment method.

Events you reported without an initiation count only in the non-initiation (whole-level) statistics. A request **without** `payment.initiation` is scored on the whole segment, exactly as before this field was used — the response is unchanged. `approval_rate`, `avg_latency_ms` and `sample_size` always reflect the segment actually used.

## Choosing an objective

`optimize_for` orders the ranking: `APPROVAL_RATE` (default), `LATENCY`, or `BALANCED` (a weighted blend of both). There is no cost objective yet — the Reporting API does not collect fees, and WHITELABEL does not rank on data it does not have.

`LATENCY` and `BALANCED` rank on the `latency_ms` you report on each event. If your reported events do not carry `latency_ms`, there is no latency to rank on: `LATENCY` returns the candidates in request order, and `BALANCED` weighs approval rate only. Report `latency_ms` (the provider round trip as you measured it) to use either objective.

## Candidates are your constraint layer

The recommendation is always one of the `candidates` you send — WHITELABEL never proposes a provider you did not list. Send only the providers this payment is genuinely allowed to use (eligibility, contracts, committed volumes), and the recommendation respects those constraints by construction.

## Retries

There is no idempotency header on this endpoint, and none is needed: each call computes a fresh recommendation with a new `recommendation_id`, and requesting a recommendation changes no state. Retrying after a network failure is always safe.

## Examples

<CodeGroup>
```bash cURL
curl -X POST 'https://api-sandbox.whitelabel.com/v1/routing/recommendations' \
  -H 'public-api-key: <YOUR_PUBLIC_KEY>' \
  -H 'private-secret-key: <YOUR_SECRET_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
    "account_id": "7825fc5e-e50a-4248-9ae8-5d3786afb0be",
    "merchant_order_id": "order_45678",
    "payment": {
      "amount": { "currency": "USD", "value": 99.00 },
      "country": "US",
      "payment_method": { "type": "CARD", "details": { "card": { "bin": "45717360" } } }
    },
    "candidates": [
      { "provider_id": "ADYEN", "merchant_connection_id": "acct-adyen-us-1" },
      { "provider_id": "STRIPE" },
      { "provider_id": "DLOCAL" }
    ],
    "optimize_for": "APPROVAL_RATE"
  }'
```

```json 200 — MERCHANT_HISTORY
{
  "recommendation_id": "3e37f0c9-e9cd-4d85-9e1a-ec5f09af296d",
  "merchant_order_id": "order_45678",
  "optimized_for": "APPROVAL_RATE",
  "decision_source": "MERCHANT_HISTORY",
  "recommended": { "provider_id": "ADYEN", "merchant_connection_id": "acct-adyen-us-1" },
  "ranking": [
    { "provider_id": "ADYEN",  "merchant_connection_id": "acct-adyen-us-1", "approval_rate": 0.9987, "avg_latency_ms": 180, "sample_size": 767 },
    { "provider_id": "STRIPE", "merchant_connection_id": null, "approval_rate": 0.9167, "avg_latency_ms": 150, "sample_size": 60 },
    { "provider_id": "DLOCAL", "merchant_connection_id": null, "approval_rate": 0.8000, "avg_latency_ms": 210, "sample_size": 60 }
  ]
}
```

```json 200 — INSUFFICIENT_DATA
{
  "recommendation_id": "7249c858-1f0f-4654-93e7-ebe34bc5048f",
  "merchant_order_id": "order_45678",
  "optimized_for": "APPROVAL_RATE",
  "decision_source": "INSUFFICIENT_DATA",
  "recommended": { "provider_id": "ADYEN", "merchant_connection_id": null },
  "ranking": [
    { "provider_id": "ADYEN",  "merchant_connection_id": null, "approval_rate": null, "avg_latency_ms": null, "sample_size": 0 },
    { "provider_id": "STRIPE", "merchant_connection_id": null, "approval_rate": null, "avg_latency_ms": null, "sample_size": 0 }
  ]
}
```

```json 400 — Too Few Candidates
{
  "code": "INVALID_PARAMETERS",
  "messages": ["The field 'candidates' has a value less than allowed."]
}
```
</CodeGroup>

## Errors

Errors return a `code` and a `messages` array.

<div className="code-nowrap-table dense-table">

| HTTP | `code` | When |
| --- | --- | --- |
| `400` | `INVALID_PARAMETERS` | Malformed body, a missing required field, fewer than 2 or more than 20 candidates, a non-ISO `country`/`currency`, or an invalid enum (`optimize_for`, `initiation`). |
| `400` | `INVALID_ACCOUNT_ID` | `account_id` is malformed or does not belong to your organization. |
| `401` | `INVALID_CREDENTIALS` | Missing or invalid `PUBLIC-API-KEY` / `PRIVATE-SECRET-KEY` headers. |
| `403` | `PRODUCT_NOT_ENABLED` | The Routing Recommendations API is not enabled for your organization. Contact your KAM. |
| `502` | `ROUTING_UPSTREAM_ERROR` | The routing service could not be reached. |

</div>

**POST** `/routing/recommendations`

Base URL: `https://api-sandbox.whitelabel.com/v1`

Ranks the candidate providers using the account's own reported off-WHITELABEL payment history and returns the recommended candidate plus the full ranking. Enabled per organization.

## Authorization

- PUBLIC-API-KEY (apiKey in header)
- PRIVATE-SECRET-KEY (apiKey in header)

## Body

Content type: `application/json`

- `account_id` (string<uuid>, required)
- `merchant_order_id` (string)
- `payment` (object, required)
  - `amount` (object, required)
    - `currency` (string, required)
      ISO 4217 currency code.
    - `value` (number, required)
  - `country` (string, required)
    ISO 3166-1 alpha-2 country code.
  - `payment_method` (object, required)
    - `type` (string, required)
    - `details` (object)
      Optional. Payment-method details that refine the statistics segment.
      - `card` (object)
        - `bin` (string)
          The card's BIN — exactly 6 or 8 digits. Selects the BIN statistics segment when it has enough reported history in the payment's country (8-digit BIN first, then the first 6 digits); otherwise the ranking falls back to the country and payment-method segments. Any other value is ignored, never rejected.
  - `initiation` ("CIT" | "MIT")
- `candidates` (object[], required)
  - `provider_id` (string, required)
  - `merchant_connection_id` (string)
- `optimize_for` ("APPROVAL_RATE" | "LATENCY" | "BALANCED")

Example:

```json
{
  "account_id": "7825fc5e-e50a-4248-9ae8-5d3786afb0be",
  "merchant_order_id": "order_45678",
  "payment": {
    "amount": {
      "currency": "USD",
      "value": 99
    },
    "country": "US",
    "payment_method": {
      "type": "CARD",
      "details": {
        "card": {
          "bin": "45717360"
        }
      }
    },
    "initiation": "CIT"
  },
  "candidates": [
    {
      "provider_id": "ADYEN",
      "merchant_connection_id": "acct-adyen-us-1"
    }
  ],
  "optimize_for": "APPROVAL_RATE"
}
```

## Responses

### 200

OK

- `recommendation_id` (string<uuid>)
- `merchant_order_id` (string)
- `optimized_for` ("APPROVAL_RATE" | "LATENCY" | "BALANCED")
- `decision_source` ("MERCHANT_HISTORY" | "INSUFFICIENT_DATA")
- `recommended` (object)
  - `provider_id` (string)
  - `merchant_connection_id` (string)
- `ranking` (object[])
  - `provider_id` (string)
  - `merchant_connection_id` (string)
  - `approval_rate` (number)
  - `avg_latency_ms` (integer)
  - `sample_size` (integer)

Example:

```json
{
  "recommendation_id": "3e37f0c9-e9cd-4d85-9e1a-ec5f09af296d",
  "merchant_order_id": "order_45678",
  "optimized_for": "APPROVAL_RATE",
  "decision_source": "MERCHANT_HISTORY",
  "recommended": {
    "provider_id": "ADYEN",
    "merchant_connection_id": "acct-adyen-us-1"
  },
  "ranking": [
    {
      "provider_id": "ADYEN",
      "merchant_connection_id": "acct-adyen-us-1",
      "approval_rate": 0.9987,
      "avg_latency_ms": 180,
      "sample_size": 767
    }
  ]
}
```

### 400

Bad Request

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "INVALID_PARAMETERS",
  "messages": [
    "The field 'candidates' has a value less than allowed."
  ]
}
```

### 401

Unauthorized

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "INVALID_CREDENTIALS",
  "messages": [
    "Invalid Credentials"
  ]
}
```

### 403

Forbidden

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "PRODUCT_NOT_ENABLED",
  "messages": [
    "The Routing Recommendations API is enabled per organization. Contact your Key Account Manager (KAM) to activate it."
  ]
}
```

### 502

Bad Gateway

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "ROUTING_UPSTREAM_ERROR",
  "messages": [
    "routing service unavailable."
  ]
}
```