Back to Hyperswitch

Create Routing Algorithm

api-reference/decision-engine-api-reference/api-reference/guides/configure-routing/routing-algorithm-create.mdx

2026.08.06.05.6 KB
Original Source

Create Routing Algorithm

Use /routing/create to persist a merchant-scoped routing algorithm. Creating an algorithm does not make it active; call /routing/activate after creation.

Supported algorithm.type values:

TypeUse caseFull example
singleAlways return one connector.Single connector
priorityReturn connectors in the configured order.Priority routing
volume_splitSplit decisions by percentage.Volume split
advancedEvaluate AND/OR/nested conditions before returning an output.Advanced routing
ab_testSplit traffic between a control and variant strategy with guardrails and significance testing.A/B testing

Use /routing/deactivate to deactivate the currently active algorithm without deleting it, and update or delete an inactive algorithm in place.

Priority Rule

bash
curl --location "$BASE_URL/routing/create" \
  --header "$AUTH_HEADER" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "priority rule",
    "created_by": "merchant_demo",
    "description": "try stripe before adyen",
    "algorithm_for": "payment",
    "algorithm": {
      "type": "priority",
      "data": [
        { "gateway_name": "stripe", "gateway_id": "mca_111" },
        { "gateway_name": "adyen", "gateway_id": "mca_112" }
      ]
    }
  }'

Single Connector Rule

bash
curl --location "$BASE_URL/routing/create" \
  --header "$AUTH_HEADER" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "single connector rule",
    "created_by": "merchant_demo",
    "description": "always route to stripe",
    "algorithm_for": "payment",
    "algorithm": {
      "type": "single",
      "data": { "gateway_name": "stripe", "gateway_id": "mca_111" }
    }
  }'

Volume Split Rule

bash
curl --location "$BASE_URL/routing/create" \
  --header "$AUTH_HEADER" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "volume split rule",
    "created_by": "merchant_demo",
    "description": "split traffic between stripe and adyen",
    "algorithm_for": "payment",
    "algorithm": {
      "type": "volume_split",
      "data": [
        {
          "split": 70,
          "output": { "gateway_name": "stripe", "gateway_id": "mca_111" }
        },
        {
          "split": 30,
          "output": { "gateway_name": "adyen", "gateway_id": "mca_112" }
        }
      ]
    }
  }'

Advanced Rule

Use advanced for conditional routing. The complete AND/OR/nested reference is in Advanced Routing Example.

bash
curl --location "$BASE_URL/routing/create" \
  --header "$AUTH_HEADER" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "advanced card rule",
    "created_by": "merchant_demo",
    "description": "route Visa cards to adyen first",
    "algorithm_for": "payment",
    "algorithm": {
      "type": "advanced",
      "data": {
        "globals": {},
        "default_selection": {
          "priority": [{ "gateway_name": "stripe", "gateway_id": "mca_111" }]
        },
        "rules": [
          {
            "name": "visa_card_rule",
            "routing_type": "priority",
            "output": {
              "priority": [
                { "gateway_name": "adyen", "gateway_id": "mca_112" },
                { "gateway_name": "stripe", "gateway_id": "mca_111" }
              ]
            },
            "statements": [
              {
                "condition": [
                  {
                    "lhs": "card_network",
                    "comparison": "equal",
                    "value": { "type": "enum_variant", "value": "Visa" },
                    "metadata": {}
                  }
                ],
                "nested": null
              }
            ]
          }
        ],
        "metadata": {}
      }
    }
  }'

Response

json
{
  "rule_id": "routing_e641380c-6f24-4405-8454-5ae6cbceb7a0",
  "name": "priority rule",
  "created_at": "2026-04-25 11:45:03",
  "modified_at": "2026-04-25 11:45:03"
}