How to create thousands of endpoints for a post or a page or a custom post type programatically?

It’s not clear from your question if you actually want the word/number structure or you merely use numbers to distinguish endpoints as different.

Natively in WordPress there is no concept of endpoint with variable name. You can use add_rewrite_endpoint() to create a endpoint endpoint, which will match requests like .../endpoint/123, .../endpoint/124, and so on to convert them into endpoint=123 query variable (where left name part is fixed and right value part is variable).

If you only want the variable part (without the fixed name preceding it) it won’t be endpoint as WP understands it. You might still be able to achieve it by constructing completely custom rewrite rule, using add_rewrite_rule(). However that will be more challenging and less reliable, especially with structures that have few elements and can easily interfere with native rewrite rules.

tech