improved token generation api method