Maximum token length allowed

What? 1.5 million is no model’s context length.

You’re being too obfuscated.

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    max_tokens=12345678,

gets you an exception you can handle and parse as a model probing method:

openai.error.InvalidRequestError: This model’s maximum context length is 4097 tokens. However, you requested 12345875 tokens (120 in the messages, 77 in the functions, and 12345678 in the completion). Please reduce the length of the messages, functions, or completion.

Also note the ability to discover function tokens in the error.