Tokens are mainly the way what billing is based on for the OpenAI API platform.

For calculating an estimate of required tokens for a prompt, the python library tiktoken can help.

For image tokens, the Python library image_token provides a close estimate of token usage:

from image_token import get_token
 
num_tokens = get_token(model_name="gpt-4o-mini", path=r"image.jpg")