Nearby lessons

19 of 30

Tokens & Cost

Concept in One Line

In real API usage, you are charged based on the number of tokens processed, not by questions, time, or answers.

Why This Concept Is Important

  • Helps students understand real-world AI cost.
  • Very important for developers and startups.
  • Common interview question for AI roles.

Key Points to Remember

  • API cost depends on token count.
  • Both input tokens and output tokens are charged.
  • Longer prompts mean higher cost.
  • Longer answers mean higher cost.
  • Token cost is model-dependent.

What Is Charged in API Usage?

When you use GPT API, you pay for:

  1. Input tokens (your prompt)
  2. Output tokens (model response)

Total cost = input tokens + output tokens

Simple Example

Example 1: Short Prompt

Prompt: Explain AI

Few input tokens

Short output

Low cost

Example 2: Long Prompt

Prompt: Explain AI with history, examples, advantages, disadvantages, interview questions

Many input tokens

Long output

Higher cost

More words = more tokens = more money

Why Companies Care About Tokens

  • Millions of users means millions of tokens.
  • Small increase per request can create a huge cost.
  • Token optimization saves real money.

Simple Flow

Prompt Length -> Token Count -> API Computation -> Cost

Interview / Exam Points

Q1: How is GPT API pricing calculated?

GPT API pricing is calculated based on the number of input and output tokens processed.

Q2: Is API cost based on number of questions?

No. It is based only on token usage.

Common Confusions to Avoid

  • Cost is not per question.
  • Cost is not per minute.
  • Cost is not per response.
  • Cost is per token.

One Line to Remember

In APIs, every token has a cost.

Quick Self-Check

For Students

API cost depends on token usage - Yes / No?

Short prompts always cost more - Yes / No?

(Correct answers: Yes, No)

🧠 Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!Encoding and Decoding