AI Costs: Tokens, Energy, Model Choice & API Keys | Stanford CS193T Lecture 7 with Cynthia Bailey
Explore AI courses and programs from Stanford Online: https://stanford.io/4BYTekhWhat does it cost to use AI in tokens, dollars, electricity, and water? In this Stanford CS193T: Thinking with AI lecture recording, Senior Lecturer Cynthia Bailey reads a real Claude Code usage report line by line, shows how caching saves money by reusing attention-mechanism calculations, and reviews estimates of AI's electricity and water use and how they vary by task and context size. She then covers model selection, including why bigger is not always better once latency compounds across a multi-step agentic workflow, and API keys: what they are, why they matter for billing and security, and a hands-on demonstration of how one leaks. The lecture closes with a current-events look at how the real-world costs of AI became a factor in the 2026 midterm elections.
Key questions answered in this lecture:
Q: What do the numbers in a Claude Code usage report mean?
A: Bailey walks through total cost, API duration (time spent waiting on the model, including network transit and data center load), wall-clock time since the session began, and input versus output tokens. Input tokens cover everything the model reads, including the system prompt, settings, and connectors. Output tokens include the model's reasoning.
Q: How does caching reduce the cost of using an AI model?
A: Much of the context window repeats from prompt to prompt, so a precomputed version is saved instead of being reprocessed. Because the attention calculation is done once and reused, cache reads can be discounted by up to about 90% compared with raw input tokens.
Q: Do unused skills still add to token costs?
A: Yes. Every enabled skill places its text in the context window on each prompt, so unused skills still add cost. Bailey recommends removing skills an agent does not need and starting a fresh session when you switch tasks.
Q: How much electricity and water does an AI prompt use?
A: Bailey cites Google's self-reported 2025 figures for a median Gemini text prompt, about 0.26 mL of water and 0.24 Wh of electricity, and notes that public data is limited. She also covers research estimates that image generation costs 20 to 40 times more than text and video 1,000 to 3,000 times more, with reasoning modes averaging about 30 times more.
Q: How should you choose a model for an AI agent?
A: Bigger is not automatically better, because larger models bring higher latency, and that delay repeats at every step of a multi-agent workflow. A narrow check against an objective rule can suit the smallest, cheapest model, while a guardrail that must interpret policy with nuance calls for a stronger one.
Q: What is an API key, and how can one leak?
A: An API key works like login credentials for a program, letting it call an AI model and bill the usage to your account, so it deserves the same care as a password. If a key is written into a web page's code, anyone can view the page source, copy it and run up charges, so it must be kept out of public view.
Chapters:
0:00 Introduction and agenda
2:34 Reading a Claude Code usage report
5:01 Input and output tokens
6:33 Prompt caching
10:07 Skills, plugins and token overhead
13:20 Electricity and water use of AI
16:07 Image, video and reasoning multipliers
18:39 Agent model selection and latency
21:07 Case study: AI tutor guardrail agents
26:11 Case study: policy Q&A chatbot
29:54 What API keys are and who pays
34:43 Security risk: leaking an API key
36:45 Demo: how an API key leaks
42:20 AI data centers in the 2026 elections
About the speaker:
Cynthia Bailey is a Senior Lecturer in the Computer Science Department at Stanford University. In 2023-2024, she served as an AI Policy Fellow in the United States Senate through the American Association for the Advancement of Science (AAAS). Her scholarship focuses on computer science education, AI/machine learning, and the social impacts of technology. This work includes creating groundbreaking courses such as Equity and Governance for Artificial Intelligence and Race and Gender in Silicon Valley. Her teaching and research awards include the Lloyd W. Dinkelspiel Award for exceptional contributions to undergraduate education at Stanford, the Lasting Impact Award from the International Computing Education Research conference, a "Top 10 Papers of All Time" award at the 50th anniversary of the ACM SIGCSE Technical Symposium, and the Stanford Society of Women Engineers' Professor of the Year. She has consulted for Apple, NASA, law firms, and machine learning startups. She holds a Ph.D. in Computer Science from UC San Diego.
Course website: https://web.stanford.edu/class/archive/cs/cs193t/cs193t.1272/
Watch the full CS193T playlist: https://www.youtube.com/playlist?list=PLDrJO3v_iAZY
Recorded November 10, 2026, in CS193T: Thinking with AI, a Stanford University course taught by Cynthia Bailey.
#AI #LLM #ResponsibleAI Receive SMS online on sms24.me
TubeReader video aggregator is a website that collects and organizes online videos from the YouTube source. Video aggregation is done for different purposes, and TubeReader take different approaches to achieve their purpose.
Our try to collect videos of high quality or interest for visitors to view; the collection may be made by editors or may be based on community votes.
Another method is to base the collection on those videos most viewed, either at the aggregator site or at various popular video hosting sites.
TubeReader site exists to allow users to collect their own sets of videos, for personal use as well as for browsing and viewing by others; TubeReader can develop online communities around video sharing.
Our site allow users to create a personalized video playlist, for personal use as well as for browsing and viewing by others.
@YouTubeReaderBot allows you to subscribe to Youtube channels.
By using @YouTubeReaderBot Bot you agree with YouTube Terms of Service.
Use the @YouTubeReaderBot telegram bot to be the first to be notified when new videos are released on your favorite channels.
Look for new videos or channels and share them with your friends.
You can start using our bot from this video, subscribe now to AI Costs: Tokens, Energy, Model Choice & API Keys | Stanford CS193T Lecture 7 with Cynthia Bailey
What is YouTube?
YouTube is a free video sharing website that makes it easy to watch online videos. You can even create and upload your own videos to share with others. Originally created in 2005, YouTube is now one of the most popular sites on the Web, with visitors watching around 6 billion hours of video every month.