{
  "id": "route-matrix-optimize",
  "name": "Exact supplied-matrix route",
  "description": "Find an exact minimum-cost directed route visiting every supplied stop once, as a fixed-start cycle or open path with optional fixed end. Null arcs are forbidden; no maps, geocoding, traffic, vehicle capacity, time windows or dispatch.",
  "category": "workflow-assurance",
  "priceUsd": "0.010",
  "pricingStatus": "proposed-unverified",
  "pricing": {
    "unit": "one successful operation call",
    "proposedNominalUsd": "0.010",
    "sixDecimalTokenBaseUnits": "10000",
    "subscription": false,
    "includesPayerWalletOrNetworkFees": false,
    "liveQuoteVerified": false,
    "condition": "Actual SDK challenge is authoritative only within the caller's explicit authorization; configured six-decimal token peg is an operator assertion, not a conversion guarantee."
  },
  "intents": [
    "Optimize a small directed travelling-salesperson tour from a supplied cost matrix",
    "Choose the least-cost order for visiting every supplied stop exactly once"
  ],
  "whenToUse": [
    "All leg costs and allowed arcs are supplied in one declared unit; at most 12 stops including the start"
  ],
  "whenNotToUse": [
    "Shortest paths that may skip/revisit stops, real routing data, multiple vehicles, capacity or time windows",
    "General route search beyond the exact bounded Hamiltonian model",
    "Investment advice, high-impact decisions about people, or validating the truth of caller assumptions"
  ],
  "capabilities": [
    "Exact decimal BigInt subset dynamic programming with lexical optimal ties",
    "Explicit cycle, free-end path or fixed-end path; valid infeasible results have no route",
    "A one-stop request produces its start only, no self-loop and exact zero cost",
    "Complete computation and result sizing before payment challenge",
    "Exact bounded supplied-data arithmetic; no network, clock, randomness or external action"
  ],
  "related": [
    "assignment-cost-optimize",
    "workflow-resource-plan"
  ],
  "limits": {
    "inputBytes": 48000,
    "outputBytes": 192000,
    "jsonNodes": 8000,
    "depth": 12,
    "stops": 12,
    "matrixCells": 144,
    "allocatedDpCells": 24576,
    "maximumTransitionChecks": 135168,
    "decimalIntegerDigits": 12,
    "decimalFractionDigits": 6
  },
  "errorCodes": [
    "INPUT_LIMIT",
    "OUTPUT_LIMIT",
    "COMPLEXITY_LIMIT",
    "INVALID_JSON",
    "INVALID_NUMBER",
    "INVALID_UNICODE",
    "UNSAFE_KEY",
    "INVALID_INPUT",
    "DUPLICATE_ID",
    "MATRIX_SHAPE",
    "UNKNOWN_STOP",
    "INVALID_ENDPOINTS",
    "INVALID_DIAGONAL",
    "INTERNAL_ROUTE"
  ],
  "requirementsProfile": {
    "format": "declared-requirements-v1",
    "facts": {
      "execution.suppliedCode": false,
      "execution.remoteMutation": false,
      "execution.llmInference": false,
      "execution.paidMcp": false,
      "verification.semanticTruth": false,
      "verification.sourceAuthenticity": false,
      "verification.liveVulnerabilities": false,
      "numbers.arbitraryPrecisionJson": false,
      "numbers.model": "bounded-exact-decimal-strings-and-integer-quantities",
      "privacy.requestBodyPersisted": false,
      "execution.deterministic": true,
      "execution.networkAccess": false,
      "privacy.resultBodyPersisted": false,
      "payment.x402": true,
      "payment.mpp": true,
      "operation.id": "route-matrix-optimize",
      "operation.category": "workflow-assurance",
      "limit.httpRequestBytes": 131072,
      "limit.requestBytes": 48000,
      "limit.responseBytes": 524288,
      "limit.resultBytes": 192000,
      "limit.jsonDepth": 12,
      "limit.jsonNodes": 8000,
      "decision.exactSuppliedDataArithmetic": true,
      "decision.assumptionsVerified": false,
      "decision.externalAction": false,
      "decision.forecastsGenerated": false,
      "decision.realWorldOptimalityGuaranteed": false,
      "decision.maxDecimalIntegerDigits": 12,
      "decision.maxDecimalFractionDigits": 6,
      "decision.profile": "exact-directed-hamiltonian-route-v1",
      "route.maxStops": 12,
      "route.exactFiniteOptimum": true,
      "route.liveTravelData": false,
      "route.multipleVehicles": false,
      "route.capacityConstraints": false,
      "route.timeWindows": false,
      "route.dispatch": false,
      "route.mandatoryEveryStopExactlyOnce": true,
      "input.stopIds.maxItems": 12,
      "input.stopIds.minItems": 1,
      "input.costs.maxItems": 12,
      "input.costs.minItems": 1,
      "input.costUnit.maxLength": 64,
      "input.costUnit.minLength": 1
    },
    "unknownPolicy": "Undeclared requirements are unknown, never compatible. Matching declared facts does not establish semantic fit or input validity.",
    "preflight": "/preflight"
  },
  "documentation": "/reference/tools/route-matrix-optimize.md",
  "serviceContract": "/reference/services/route-matrix-optimize.json",
  "errors": [
    {
      "status": 400,
      "meaning": "Malformed JSON, missing/invalid idempotency key, or payment identifier mismatch",
      "retry": "Correct the request before payment"
    },
    {
      "status": 402,
      "meaning": "Payment challenge or rejected payment",
      "retry": "Use official protocol SDK; inspect payment outcome before another payment"
    },
    {
      "status": 409,
      "meaning": "Idempotency conflict, duplicate proof, or PAYMENT_UNCERTAIN",
      "retry": "Keep original key, body, and proof; reconcile uncertainty with operator; never blindly repay"
    },
    {
      "status": 413,
      "meaning": "Input or generated output too large",
      "retry": "Reduce input; no payment attempted for validation failure"
    },
    {
      "status": 415,
      "meaning": "Unsupported media type or compression",
      "retry": "Send uncompressed application/json"
    },
    {
      "status": 422,
      "meaning": "Schema or service-specific semantic validation failure",
      "retry": "Correct input using returned error code; no payment attempted"
    },
    {
      "status": 429,
      "meaning": "Request/payment-attempt rate exceeded",
      "retry": "Wait for rate limit window; preserve existing payment identity"
    },
    {
      "status": 503,
      "meaning": "Payment configuration/provider/state unavailable, or live DNS preparation failed before settlement",
      "retry": "Check readiness; DNS preparation failures may retry the identical key/body/credential only; uncertainty requires reconciliation"
    }
  ],
  "numericPrecision": "JavaScript IEEE-754 numbers; use strings for large integer IDs/exact decimals where the schema accepts strings. No lossless numeric parsing.",
  "paymentWorkflow": {
    "discoveryOnly": false,
    "supportedProtocols": [
      "x402",
      "mpp"
    ],
    "x402": {
      "credentialHeader": "PAYMENT-SIGNATURE",
      "challengeHeader": "PAYMENT-REQUIRED",
      "receiptHeader": "PAYMENT-RESPONSE",
      "version": 2,
      "scheme": "exact",
      "paymentIdentifier": "payment-identifier extension MUST equal the HTTP Idempotency-Key",
      "sdk": "@x402/core with @x402/evm"
    },
    "mpp": {
      "supported": true,
      "credentialHeader": "Authorization",
      "challengeHeader": "WWW-Authenticate",
      "receiptHeader": "Payment-Receipt",
      "method": "tempo",
      "intent": "charge",
      "sdk": "mppx",
      "tokenDecimals": 6
    },
    "steps": [
      "Check configured readiness and the exact service schema",
      "Generate a fresh random Idempotency-Key for this operation; never use a discovery probe fixture for purchases",
      "Send valid input without a credential to obtain the official protocol challenge",
      "Use the official SDK and authorized wallet to fulfill the challenge",
      "Retry only with identical key, body, protocol and credential",
      "On PAYMENT_UNCERTAIN stop and request operator reconciliation; never blindly pay again"
    ],
    "versionedRetries": "Request fingerprint includes service release version. Retries across a version upgrade can conflict; coordinate upgrades outside the 24-hour replay window and reconcile pending attempts.",
    "docs": "/llms.txt"
  },
  "method": "POST",
  "paths": {
    "x402": "/v1/x402/route-matrix-optimize",
    "mpp": "/v1/mpp/route-matrix-optimize"
  },
  "inputSchema": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "stopIds": {
        "minItems": 1,
        "maxItems": 12,
        "type": "array",
        "items": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        }
      },
      "costs": {
        "minItems": 1,
        "maxItems": 12,
        "type": "array",
        "items": {
          "minItems": 1,
          "maxItems": 12,
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^(?:0|[1-9][0-9]{0,11})(?:\\.[0-9]{1,6})?$"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "route": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "cycle"
              },
              "startId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              }
            },
            "required": [
              "kind",
              "startId"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "path"
              },
              "startId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "endId": {
                "anyOf": [
                  {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "kind",
              "startId",
              "endId"
            ],
            "additionalProperties": false
          }
        ]
      },
      "costUnit": {
        "type": "string",
        "minLength": 1,
        "maxLength": 64
      }
    },
    "required": [
      "stopIds",
      "costs",
      "route",
      "costUnit"
    ],
    "additionalProperties": false
  },
  "outputSchema": {
    "type": "object",
    "required": [
      "operation",
      "version",
      "result",
      "provenance"
    ],
    "properties": {
      "operation": {
        "const": "route-matrix-optimize",
        "type": "string"
      },
      "version": {
        "const": "0.29.0",
        "type": "string"
      },
      "result": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "profile": {
                "type": "string",
                "const": "exact-directed-hamiltonian-route-v1"
              },
              "externalRequests": {
                "type": "number",
                "const": 0
              },
              "execution": {
                "type": "boolean",
                "const": false
              },
              "assumptionsVerified": {
                "type": "boolean",
                "const": false
              },
              "costUnit": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "stopIds": {
                "minItems": 1,
                "maxItems": 12,
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                }
              },
              "route": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "cycle"
                      },
                      "startId": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 64
                      }
                    },
                    "required": [
                      "kind",
                      "startId"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "path"
                      },
                      "startId": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 64
                      },
                      "endId": {
                        "anyOf": [
                          {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          {
                            "type": "null"
                          }
                        ]
                      }
                    },
                    "required": [
                      "kind",
                      "startId",
                      "endId"
                    ],
                    "additionalProperties": false
                  }
                ]
              },
              "algorithm": {
                "type": "string",
                "const": "subset-dynamic-programming"
              },
              "work": {
                "type": "object",
                "properties": {
                  "statesEvaluated": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 24576
                  },
                  "transitionsConsidered": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 135168
                  }
                },
                "required": [
                  "statesEvaluated",
                  "transitionsConsidered"
                ],
                "additionalProperties": false
              },
              "status": {
                "type": "string",
                "const": "optimal"
              },
              "visitOrder": {
                "minItems": 1,
                "maxItems": 13,
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                }
              },
              "legs": {
                "maxItems": 12,
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "fromId": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 64
                    },
                    "toId": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 64
                    },
                    "cost": {
                      "type": "object",
                      "properties": {
                        "numerator": {
                          "type": "string",
                          "pattern": "^(?:0|[1-9][0-9]*)$"
                        },
                        "denominator": {
                          "type": "string",
                          "pattern": "^[1-9][0-9]*$"
                        }
                      },
                      "required": [
                        "numerator",
                        "denominator"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "fromId",
                    "toId",
                    "cost"
                  ],
                  "additionalProperties": false
                }
              },
              "totalCost": {
                "type": "object",
                "properties": {
                  "numerator": {
                    "type": "string",
                    "pattern": "^(?:0|[1-9][0-9]*)$"
                  },
                  "denominator": {
                    "type": "string",
                    "pattern": "^[1-9][0-9]*$"
                  }
                },
                "required": [
                  "numerator",
                  "denominator"
                ],
                "additionalProperties": false
              },
              "tieBreak": {
                "type": "string",
                "const": "lexicographically-smallest-visit-order-by-UTF-16"
              }
            },
            "required": [
              "profile",
              "externalRequests",
              "execution",
              "assumptionsVerified",
              "costUnit",
              "stopIds",
              "route",
              "algorithm",
              "work",
              "status",
              "visitOrder",
              "legs",
              "totalCost",
              "tieBreak"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "profile": {
                "type": "string",
                "const": "exact-directed-hamiltonian-route-v1"
              },
              "externalRequests": {
                "type": "number",
                "const": 0
              },
              "execution": {
                "type": "boolean",
                "const": false
              },
              "assumptionsVerified": {
                "type": "boolean",
                "const": false
              },
              "costUnit": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "stopIds": {
                "minItems": 1,
                "maxItems": 12,
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                }
              },
              "route": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "cycle"
                      },
                      "startId": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 64
                      }
                    },
                    "required": [
                      "kind",
                      "startId"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "path"
                      },
                      "startId": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 64
                      },
                      "endId": {
                        "anyOf": [
                          {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          {
                            "type": "null"
                          }
                        ]
                      }
                    },
                    "required": [
                      "kind",
                      "startId",
                      "endId"
                    ],
                    "additionalProperties": false
                  }
                ]
              },
              "algorithm": {
                "type": "string",
                "const": "subset-dynamic-programming"
              },
              "work": {
                "type": "object",
                "properties": {
                  "statesEvaluated": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 24576
                  },
                  "transitionsConsidered": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 135168
                  }
                },
                "required": [
                  "statesEvaluated",
                  "transitionsConsidered"
                ],
                "additionalProperties": false
              },
              "status": {
                "type": "string",
                "const": "infeasible"
              },
              "visitOrder": {
                "type": "null"
              },
              "legs": {
                "type": "null"
              },
              "totalCost": {
                "type": "null"
              },
              "reason": {
                "type": "string",
                "const": "No route visits every supplied stop exactly once under the declared endpoints and allowed arcs"
              }
            },
            "required": [
              "profile",
              "externalRequests",
              "execution",
              "assumptionsVerified",
              "costUnit",
              "stopIds",
              "route",
              "algorithm",
              "work",
              "status",
              "visitOrder",
              "legs",
              "totalCost",
              "reason"
            ],
            "additionalProperties": false
          }
        ]
      },
      "provenance": {
        "type": "object",
        "required": [
          "inputSha256",
          "outputSha256",
          "deterministic",
          "externalRequests"
        ],
        "properties": {
          "inputSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "outputSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "deterministic": {
            "const": true
          },
          "externalRequests": {
            "const": 0
          }
        }
      }
    },
    "additionalProperties": false
  },
  "exampleInput": {
    "stopIds": [
      "depot",
      "alpha",
      "beta",
      "gamma"
    ],
    "costs": [
      [
        "0",
        "4",
        "2",
        "8"
      ],
      [
        "3",
        "0",
        "5",
        "2"
      ],
      [
        "7",
        "1",
        "0",
        "6"
      ],
      [
        "3",
        "4",
        "2",
        "0"
      ]
    ],
    "route": {
      "kind": "cycle",
      "startId": "depot"
    },
    "costUnit": "declared travel minutes"
  },
  "exampleResponse": {
    "operation": "route-matrix-optimize",
    "version": "0.29.0",
    "result": {
      "profile": "exact-directed-hamiltonian-route-v1",
      "externalRequests": 0,
      "execution": false,
      "assumptionsVerified": false,
      "costUnit": "declared travel minutes",
      "stopIds": [
        "alpha",
        "beta",
        "depot",
        "gamma"
      ],
      "route": {
        "kind": "cycle",
        "startId": "depot"
      },
      "algorithm": "subset-dynamic-programming",
      "work": {
        "statesEvaluated": 20,
        "transitionsConsidered": 24
      },
      "status": "optimal",
      "visitOrder": [
        "depot",
        "beta",
        "alpha",
        "gamma",
        "depot"
      ],
      "legs": [
        {
          "fromId": "depot",
          "toId": "beta",
          "cost": {
            "numerator": "2",
            "denominator": "1"
          }
        },
        {
          "fromId": "beta",
          "toId": "alpha",
          "cost": {
            "numerator": "1",
            "denominator": "1"
          }
        },
        {
          "fromId": "alpha",
          "toId": "gamma",
          "cost": {
            "numerator": "2",
            "denominator": "1"
          }
        },
        {
          "fromId": "gamma",
          "toId": "depot",
          "cost": {
            "numerator": "3",
            "denominator": "1"
          }
        }
      ],
      "totalCost": {
        "numerator": "8",
        "denominator": "1"
      },
      "tieBreak": "lexicographically-smallest-visit-order-by-UTF-16"
    },
    "provenance": {
      "inputSha256": "69efa70491b7b083786ef5f6071ee2963cb1eaaf0be6d0d27dec7bc05b2648d2",
      "outputSha256": "49ae8abe2fd859ad0e439a60afe82b5b38520337afe6da77ca7d9d5e80942e9d",
      "deterministic": true,
      "externalRequests": 0
    }
  },
  "requiredHeaders": {
    "Content-Type": "application/json",
    "Idempotency-Key": "random 16–128 character operation identifier"
  },
  "fixedExample": "/reference/examples/route-matrix-optimize.json",
  "execution": {
    "deterministic": true,
    "externalRequests": 0,
    "maxExternalRequests": 0,
    "resultSnapshotPersisted": false,
    "fixedExampleIsIllustrativeSnapshot": false,
    "requiresPayment": true,
    "supportsMcpExecution": false
  },
  "releaseSnapshot": {
    "format": "static-release-reference-v1",
    "sourceVersion": "0.29.0",
    "sourceRegistrySha256": "a2b5ec09bf6c38b9d2879d746a4fded374f5928b445377b0270ef6aa8e6cac65",
    "generatedAt": "2026-10-06T15:38:00Z",
    "releaseAcceptance": "not-verified-by-generator",
    "runtimeReadiness": "not-evaluated",
    "livePaymentsVerified": false,
    "indexingVerified": false,
    "apiOrigin": null,
    "notice": "Build-time release reference. Runtime readiness, deployment, payment settlement and external indexing are not evaluated here. Prices are proposed; this file cannot authorize execution or payment."
  }
}
