🎓 A1Learner
🔍
0 of 50 lessons completed

Prompt Engineering: Tokens

A token is the model's unit of text. The model reads prompts in tokens, not in words.

Short words, fewer tokens

A short prompt uses fewer tokens than a long one. The words below say the same job in fewer tokens.

Reply to Maya. Order 1042 is out for delivery.

The same job in more words

More words mean more tokens. The reply is the same job, but the prompt costs more.

Write a polite and friendly reply to our valued customer Maya, letting her know that her order number 1042, which contains the Aurora Ceramic Mug, has been shipped and is currently out for delivery.

A word limit keeps the reply short

A word limit in the prompt keeps the reply short. Short replies use fewer tokens too.

Write a reply to Tom about order 1043 in under 30 words. His lamp is still processing.

Example

Write a reply to Priya about order 1044 in under 30 words. Her order was delivered 5 days ago.

Key points

  • A token is a chunk of text. Short words are often one token and long words split into several.
  • ShopStack costs more tokens than shop. The model splits the longer word into pieces.
  • The prompt and the reply both use tokens. Longer prompts cost more.
  • Counting tokens before you send keeps the prompt inside the model's limits.

This example runs a short prompt against the local model and shows the reply it gave.

Note

A token is not a word. A word can be one token or several.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Why does ShopStack cost more tokens than shop?