code: def infer_endpoint(rule_payload):
      
      bucket = (rule_payload if isinstance(rule_payload, dict)
                else json.loads(rule_payload)).get("bucket")
      return "counts" if bucket else "search"
docs: Infer which endpoint should be used for a given rule payload.