Video Summary

Why AI Tokens are so Expensive - Computerphile

Computerphile

Main takeaways
01

A token is a word or piece of a word (including spaces, punctuation, and symbols) defined by a model's tokenizer.

02

LLMs work autoregressively: each new token is predicted using the whole prior context, which makes long contexts costly.

03

Caching key/value activations speeds processing but doesn't eliminate repeated context growth in many workflows.

04

Coding agents add cost by autonomously reading files, making tool calls, and accumulating prior prompts into context.

05

Providers typically charge much less for input tokens than output tokens, so long generated outputs can be especially expensive (example: ~$2–$3/M input vs ~$15/M output).


Key moments
Questions answered

What exactly is a token in LLMs?

A token is a unit of text — a whole word or a piece of a word (including spaces, punctuation and special symbols). Tokenization rules depend on the model's tokenizer and are often based on token frequency in training data.

Why do interactions with LLMs become so expensive?

LLMs are autoregressive: every new token prediction conditions on the entire prior context, so long conversations or large inputs multiply the number of tokens processed. Input and especially output tokens are billed, so large outputs and repeated context increase costs quickly.

How do coding agents drive higher token usage compared to chatbots?

Coding agents autonomously access files, perform tool calls, and reinsert prior prompts and outputs into context. Those file reads, tool calls and iterative reasoning steps add many input and output tokens, rapidly raising the bill.

Do caching and optimization eliminate token costs?

Caching stores key/value activations to avoid recomputing relationships for already-processed tokens, improving speed and costs in some cases. But caching doesn't fully stop context growth or the billing of input/output tokens in workflows that keep re-sending context.

How can users reduce token-related expenses?

Be concise: limit context size, target specific fixes rather than broad multi-step reasoning, reduce unnecessary tool/file calls, and design prompts to minimize large generated outputs. Monitor input vs output token usage and prefer workflows that avoid iterating entire histories.

The Nature of Tokens in AI Models 00:49

A token is either a word or a piece of a word.

  • Tokens are fundamental units used in AI language models, and they can consist of entire words or partial words.

  • For example, in the sentence "the cat sat on the mat," each word could be treated as a token, but spaces and punctuation (like full stops) are also considered tokens in modern AI systems.

  • The number of tokens available can be vast, with modern language models having access to around 100,000 tokens that include common words, tokens from other languages, and symbols from computer code.

Token Representation and Model Efficiency 02:25

The tokenizer is essentially a string parser that goes in front and at the end of a large language model.

  • A tokenizer processes input strings, generating numerical representations called embeddings for each token, enabling the model to interpret and predict language.

  • The way tokens are split relies heavily on their frequency within the training dataset, allowing the model to efficiently encode language patterns.

  • Language models leverage their large size and comprehensive training data to manage predictions across various contexts, including programming languages like JavaScript.

The Cost Structure of AI Token Usage 04:15

The interesting part is when you talk to a model, how much does it cost?

  • The operational cost of using AI models is determined by the number of tokens processed during input and output exchanges.

  • Models operate in an autoregressive manner, where each token generation considers all previous tokens, leading to potential inefficiencies due to the sheer volume of data processed repetitively.

  • For instance, if a user inputs a 500-token question and the model elaborates with a 10,000-token thought process, the overall cost accumulates significantly due to the high number of tokens evaluated.

Understanding Input and Output Token Dynamics 06:22

When you want to put the next statement in, you include everything again, and that gets bigger and bigger.

  • The interaction between user queries and model output is fluid and recursive, as each response builds on prior inputs, inflating the total token count with each iteration.

  • The real cost comes not just from the initial input but from the continuous process of adding prior tokens back into the context, amplifying energy consumption and processing resources.

  • Advanced techniques, such as key-value caching, optimize this process, but a comprehensive understanding of the model's energy use necessitates awareness of how token loops work within language model operations.

Caching Tokens in AI Models 08:35

“When you actually put this through the network to predict the next word, we don't have to calculate the relationship between words we have already processed because we cache those values.”

  • The process of predicting the next word in AI models utilizes previously calculated relationships between tokens, which are stored in a cache. This caching significantly speeds up processing because it avoids recalculating relationships for each new token.

  • While the cache helps with larger context windows, in simpler cases, it may have almost no impact. However, in scenarios involving millions of documents, caching can greatly enhance performance.

  • There is an implementation consideration for how long to keep cached data alive since if the model is inactive for too long, it must discard cached values, leading to a requirement for re-initialization when the model is accessed again.

Impact of Token Count on Costs 09:51

“Most of the cost of these models is measured in input tokens and output tokens.”

  • The cost of AI models scales quickly as the number of tokens increases. Simple queries might only use a few tokens, but follow-up questions can lead to significant token growth, resulting in higher costs.

  • As users engage with a model, if they continue to ask follow-up questions, the cumulative token count can escalate dramatically, reaching potentially tens of thousands of tokens for complex queries and responses. This is especially true when files containing vast amounts of data are involved.

  • The difference in costs between chatbots and coding agents is striking; coding agents often incur higher expenses due to their ability to handle more complex tasks involving multiple files and extensive data processing.

Functionality of Coding Agents 11:39

“A coding agent has more autonomy, allowing it to access files and make tool calls rather than simply outputting responses to me.”

  • Unlike standard chatbots, coding agents can autonomously access files and perform operations on the data instead of just responding to user queries. This ability makes them significantly more powerful in certain contexts.

  • When a coding agent processes a request, it may initiate ‘tool calls’ to perform tasks, such as reading or modifying files, which involves additional token usage but provides results that are tailored to the user's specific needs.

  • However, the initial prompt for these tasks—along with the tokens from previous activities—adds up in terms of cost, indicating that while coding agents can streamline processes, they can also lead to increased charges more rapidly than expected.

Understanding Token Pricing for AI Models 12:49

“Modern providers charge somewhere around $2 to $3 for a million input tokens and about $15 for a million output tokens.”

  • Token pricing models for AI tools dictate the financial implications for users, with significant disparities between input and output token costs.

  • Input tokens, as the primary means of command input for the model, generally incur lower costs compared to output tokens, which include all generated responses. This pricing model can catch users off guard, especially in coding contexts where output tokens may quickly accumulate.

  • Users must be mindful of the token economy in order to manage costs efficiently when utilizing these intelligent agents for programming tasks.

The Process of Fixing Code with AI Tokens 17:21

"The model processes input and makes decisions on how to fix the code based on its reasoning."

  • The AI model works by taking the original input and analyzing it to determine the necessary code changes. Throughout this process, it generates tokens for various operations, such as reading files and making tool calls.

  • Initially, the model processes 11,300 tokens from the input query, which entails further reasoning as it seeks to formulate a solution. Each subsequent thought or guess adds additional tokens, reflecting the complexity of the task at hand.

  • As the AI completes its assessment, it formulates commands to patch the code, resulting in a potential output of around 1,500 tokens for the actual code changes required.

Accumulation of Token Costs 18:41

"The total cost of the operation can rapidly escalate, with token counts reaching into the tens of thousands."

  • Following multiple thought processes and tool calls, the total token count increases significantly, with instances of 17,400 or more tokens being logged for a single response.

  • This detailed activity highlights the cost associated with each interaction with the AI, as users might find themselves accumulating tokens without realizing the implications of complex queries.

  • The video illustrates the cumulative effect of these tokens, ultimately resulting in a situation where the model could use nearly 55,000 to 60,000 tokens just to respond to a simple bug-fixing request.

Real-world Application and Token Usage 20:51

"Real scenarios show that prompt complexity can lead to astronomical token usage."

  • The speaker shares a personal experience involving a coding project with GitHub Copilot, where initial simple requests escalated into a vast number of tokens used over several prompts.

  • Despite intending to create a simple classic screensaver, the iterative back-and-forth with the AI led to over 2 million input tokens and 47,000 output tokens, highlighting the significant difference in token consumption depending on the nature of the requests.

  • This example emphasizes a key point: companies are beginning to measure the efficiency of AI models based on token usage, which could be problematic, as it does not accurately reflect successful outcomes or productivity.

Sustainable Practices for AI Token Usage 22:11

"Measuring productivity by token usage is an unsustainable practice, akin to flawed metrics in other industries."

  • The speaker warns against using token counts as a sole metric for productivity, comparing it to measuring driving quality by tire wear—a method that overlooks the broader context.

  • The incentive to create long-winded queries can lead to more costly interactions as users try to extract as much information as possible from the AI, which can also cause the model to get caught in loops of reasoning.

  • The speaker advocates for a shift toward using more concise queries that focus on specific code fixes or enhancements, rather than complex, multi-layered requests.

Financial Implications of Token Spending 23:21

"The rising costs associated with token usage could challenge smaller companies, making it imperative to assess productivity gains."

  • There is skepticism about the ability of typical companies without vast resources to justify the high costs associated with extensive token usage.

  • The speaker suggests that to merit the investment in AI tools, companies should see clear and immediate returns from new features or products developed with the use of AI assistance.

  • A more reasonable approach would involve succinct inquiries that maximize efficiency and minimize unnecessary token consumption, thus making AI tools accessible without prohibitive costs.