How to use OpenAI GPT tokens?

What are OpenAI GPT tokens?

Tokens are the basic unit that OpenAI GPT models (including ChatGPT) use to compute the length of a text. They are groups of characters, which sometimes align with words, but not always. In particular, it depends on the number of characters and includes punctuation signs or emojis. This is why the tokens count is usually different from the word count.

Video tutorial

Video preview

How to count tokens in my text?

In order to know exactly, you need to tokenize your text, which means running a tokenizer algorithm that will count all the tokens. Sounds difficult? It’s actually as easy as copy/pasting. You can use OpenAI’s official tokenizer.

Rule of thumb for word to token ratio

Since all characters count, the ratio of words to tokens is language dependent.

Typically some good rules of thumb ratios are:

In English: 1 word ≈ 1.3 tokens In Spanish: 1 word ≈ 2 tokens In French: 1 word ≈ 2 tokens

See real examples here

How many tokens for punctuation marks, special characters and emojis?

Punctuation marks (,:;?!) = 1 token Special characters (∝√∅°¬) = 1 to 3 tokens Emojis (😁🙂🤩) = 2 to 3 tokens

Word and token counts examples

Write a tagline for an ice cream shop A scoop of happiness in every cone! ⮑ 15 words · 19 tokens

Generate 3 subject lines for a cold email about Instagram growth

1. "9 Ways to Boost Your Instagram Reach & Engagement" 2. "Explode Your Instagram Following - Log in to Find Out How" 3. "Maximize Your Instagram Presence - Learn How Now" ⮑ 40 words · 58 tokens

Write a thank you email to my grandmother

Dear Grandma, I hope this letter finds you well and happy. I wanted to thank you for the thoughtful and generous gift that you sent my way. It was so thoughtful of you and I truly appreciate it. Your gift was so lovely and will certainly be used and enjoyed. It was a perfect way to brighten up my day. Thank you for all the love and support you continue to give me.It means more to me than anything else. With love and gratitude, ⮑ 93 words · 107 tokens

Check out more examples

What is the price of a token?

The price of a token depends on the model. The price is per 1000 tokens. Find the pricing table below:

Model name
Technical name
Price for 1000 tokens (prompt)
Price for 1000 tokens (completion)
GPT-4 32k
gpt-4-32k
USD 0.0600
USD 0.1200
GPT-4 8k
gpt-4
USD 0.0300
USD 0.0600
GPT-3.5 16k
gpt-3.5-turbo-16k
USD 0.0030
USD 0.0040
GPT-3.5 16k
gpt-3.5-turbo
USD 0.0015
USD 0.0020
Davinci
text-davinci-003
USD 0.0200
USD 0.0200
Curie
text-curie-001
USD 0.0020
USD 0.0020
Babbage
text-babbage-001
USD 0.0005
USD 0.0005
Ada
text-ada-001
USD 0.0004
USD 0.0004

Check out our pricing calculator.

What is the max_tokens parameter?

max_tokens is the maximum of tokens that should be generated in any request to OpenAI ChatGPT and GPT-3 APIs. This applies to requests made through GPT for Sheets and Docs. It should always obey the following constraint: prompt_tokens + max_tokens ≤ model limit In the case of Davinci, that means prompt_tokens + max_tokens ≤ 4096

Model name
Technical name
Max tokens
GPT-4 32k
gpt-4-32k
32768
GPT-4
gpt-4
8192
GPT-3.5 16k
gpt-3.5-turbo-16k
16384
GPT-3.5
gpt-3.5-turbo
4096
Davinci
text-davinci-003
4096
Curie
text-curie-001
2049
Babbage
text-babbage-001
2049
Ada
text-ada-001
2049

What to do if the response from GPT is cut?

If your response is cut, it means you didn’t provide a large enough max_tokens value. You should increase the max_tokens parameter.