When you make an image in Google AI Studio, as the first module's exercises do, you are signed in to a Google account and a person is sitting at the screen. An API is the same service offered to programs, and a program cannot sign in or tick a box, so the service gives you a long string of characters to send with every request instead. Google calls it an . Hugging Face calls it an access token and Replicate calls it an API token, but they are one idea with three names.
An API lets a program ask for work without anybody clicking, so a short script can request forty variations of a product shot overnight, render a storyboard frame by frame, or hand the whole job to a coding agent while you do something else. A request is a small bundle of text that holds the model's name, your prompt, a few settings such as the length or the aspect ratio, and the key. The later parts of this course all work this way, including calling Veo directly, running open models from Hugging Face and briefing Claude Code or Codex to batch a film. Each of those calls has to prove which account it belongs to. The key is that proof.
Each request carries the key in a , a labelled line of text that travels with the request but is not part of the prompt. Google's is called x-goog-api-key, OpenAI and Replicate use Authorization with the word in front, and fal uses Authorization with the word Key. The service reads the string, finds the project it belongs to, checks what that key is allowed to do, runs the job and adds the cost to that project's bill. The request never says who typed it.
Every key is tied to a bill. Google says every Gemini API key is associated with a Google Cloud project, and that project holds the billing, the collaborators and the permissions; other providers attach keys to an account, a team or a project in much the same way. Many keys can also be narrowed. Google lets you restrict a key to the Gemini API alone and to particular websites, apps or IP addresses, Hugging Face offers read, write and fine-grained tokens, the last limited to specific models or organisations, and OpenAI recommends giving every project key an expiry date. A narrow key does less damage when it escapes, which is why a careful studio makes the narrowest key the job allows.
Every official library looks for its key under a fixed name, held in an , which is a named value your terminal hands to every program it starts. Spell the names exactly. The Google GenAI SDK reads GEMINI_API_KEY, OpenAI's reads OPENAI_API_KEY, Hugging Face's reads HF_TOKEN, Replicate's reads REPLICATE_API_TOKEN and fal's reads FAL_KEY. Google's SDK also reads GOOGLE_API_KEY, and if both are set that one wins, which can make a brand-new key seem to be ignored. That is why no code in this course ever contains a key, only a name, and the value itself lives in a file or a vault on your own machine, which a later lesson in this module sets up.
Some providers show you a key only once. fal says its keys cannot be retrieved after they are created, so a new key has to go straight into safe storage, and the habit is a good one everywhere. A careful studio treats each key as a small asset with a record kept beside it, noting what the key is for, which project pays, where it is stored, when it expires and who can see it. That record takes two minutes to write. It is also what makes a leak quick to deal with, because you know exactly which key to switch off and what will stop working when you do.

A real case
Twelve thousand live keys in a public web crawl
Truffle Security · 2025
What they did
The security firm scanned Common Crawl's December 2024 archive, 400 TB taken from 2.67 billion web pages and used to train AI models, and counted only the keys and passwords that still worked.
What happened
It found 11,908 live secrets on 2.76 million pages. One WalkScore key alone appeared 57,029 times, and nearly 1,500 Mailchimp keys had been written straight into pages' HTML and JavaScript. Rather than write to some 12,000 site owners, Truffle asked the worst-hit vendors to revoke their users' keys, and several thousand were switched off.
What to take from it
A key pasted into a web page is published to everyone who opens it, and to every archive that copies the page. Keep keys in the console that made them and in a secrets store on your own machine.
The words, in plain language
- API
- The door a service leaves open for programs rather than people.
- API key
- A long secret string sent with every request to say which account pays.
- Header
- A labelled line of text that travels with a request, outside the prompt. The key rides in one.
- Bearer
- The header style most providers use. Whoever holds the string is trusted.
- Scope
- What a key is allowed to do. The narrower it is, the less a leak costs.
- Environment variable
- A named value your terminal hands to every program it starts.
- Rotation
- Making a new key, moving everything to it, then switching the old one off.
Why it matters
Google's own documentation says to treat a Gemini key like a password, and it is a password that spends money. At Veo 3.1 Standard prices, 40 cents a second, one eight-second 1080p clip costs $3.20, and a script running on somebody else's machine with your key can ask for clips as fast as Google will render them. Three hundred of them come to $960. The only limits that stop it are the ones you set up in advance, such as the spending limits and billing alerts that a later lesson in this module walks you through. Most people set none.
Keys leak because they are built to be pasted. They end up in a message to a colleague, a screenshot in a deck, a code file pushed to GitHub, a prompt typed into a chatbot, or a web page's JavaScript, where Google warns that users can extract them. Providers know this happens. Replicate scans public GitHub repositories for its tokens and disables any it finds, and Hugging Face lets anyone switch off a leaked token they come across, but both of those happen after the leak. A key belongs in two places only, the console that made it and a secrets store on your own computer, and anywhere else counts as a leak.
Make one key per job, and name it after the job. Hugging Face recommends a separate token for each app or use, such as one for your laptop and one for a notebook, OpenAI recommends project keys with an expiry date and a regular , and Replicate suggests separate tokens for development, staging and production. When one leaks you switch off one thing rather than your whole working week, and the name tells you where it was used. The common mistake is the opposite. One all-powerful key, made on the first day and pasted into everything, turns a small slip into a morning of rebuilding every tool you own.
The rest of this module sets up the kit that the later parts of the course depend on. It starts with a short, practical introduction to the terminal, enough to run everything that follows. Then it walks through making a key for Google's video model click by click, then the keys for OpenAI, Hugging Face, Replicate and fal, and then where keys should live on a Mac, in files that never reach a chat window or a Git repository. After that it shows how to cap what each account can spend and get an alert before the bill arrives, and what to do in the first minutes after a key escapes. Nothing in it needs coding experience.
Elsewhere
- Type
- technique
- Period
- ongoing