OpenAI API: How do I count tokens before(!) I send an API request?
OpenAI's text models have a context length, e.g.: Curie has a context length of 2049 tokens. They provide max_tokens and stop parameters to control the length of the generated sequence. Therefore the generation stops either when stop token is obtained, or max_tokens is reached. The issue is: when generating a text, I don't know how many tokens my prompt cont