跳到正文

第 16 课 · Google AI Studio

Building Apps in AI Studio

Create prototypes with AI Studio Build mode: write a clear app spec, iterate safely, protect the API key, understand deployment costs and review code.

Build mode in Google AI Studio creates apps from descriptions in plain language. It is a fast way to make a prototype and a good way to learn how apps connect to a model. A prototype is not a finished product, though. This lesson covers how to describe an app, what to review and what deploying means. Facts are as of December 2026.

What it can build

According to Google's documentation:

  • Web apps, by default with a React front end and a Node.js server part for secure API calls, database connections and packages.
  • Native Android apps in Kotlin with Jetpack Compose, with a preview in a browser-based emulator.

An AI agent manages the project files and checks its changes. Full-stack features include secrets, a database and sign-in. You can refine the app by chatting, by annotating the preview or by editing code, and you can sync to GitHub or download a ZIP file.

Write a short specification first

A clear specification saves many rounds of changes:

TEXT
App: Vocabulary practice for adult learners.
Users: one person on their own phone or laptop.
Features:
1. Add a word, its meaning and an example sentence.
2. Quiz mode: show the meaning, the user types the word.
3. A button asks the model for a new example sentence for one word.
Rules: no sign-in. Reject empty fields. Show a clear error when the
model call fails. Label model-written sentences as AI-generated.
Not needed: social features, payments.

Listing what you do not need is useful. It stops the app from growing.

Iterate in small steps

  1. Generate a first version.
  2. Test it yourself before you ask for changes.
  3. Ask for one change at a time and describe what you see: "When I submit an empty form, nothing happens. Show an error under the field."
  4. After each change, test the older features again.
  5. Sync to GitHub or save a copy so you can go back.
Python Stand-in: a regression checklist for each change

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A short list of checks like this tells you when a "small fix" broke something else.

The API key

Google's documentation says AI Studio sets up your GEMINI_API_KEY as a server-side secret, so model calls come from server code and the key stays out of the browser. Keep it that way. When you edit the code:

  • Never move the key into front-end code.
  • Never print it in logs or paste it into a chat.
  • If you download the project, set the key in your own hosting environment.
  • For Android apps, Google's documentation describes Firebase AI Logic with App Check, so no raw key is built into the app.

Who pays when others use it

This is the part that beginners miss:

  • A shared app counts its API calls against your usage limits, and paid models can cost money.
  • An app deployed to Cloud Run includes your key, so all users' Gemini calls are billed to you. Cloud Run itself may also charge by usage.

Before you share, decide who can open the app, set budget alerts and add limits in your own code, such as a maximum number of requests per user per day.

Python Stand-in: a daily request limit per user

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A real server needs persistent storage, a reliable way to identify users and a total limit for the whole app, so that new accounts cannot reset the budget.

Review before you deploy

Area Questions
Security Are secrets on the server? Is user input checked?
Data What is stored, where and for how long? Do users get a privacy notice?
Model output Is it treated as untrusted text and escaped on screen?
Errors What happens when a limit is hit or a call fails?
Accessibility Does it work with a keyboard? Are fields labeled and colors readable?
Cost Who pays, and what caps exist?

If your app can take actions or show one user's content to others, ask someone with security experience to review it.

Ask the builder to explain

You are responsible for code you publish, even if you did not type it. Before you accept a version, ask questions such as: "Which files send data to the model?", "Where is user data stored?", "Which packages did you add and why?" and "What happens when the model call fails?" Then open the named files and confirm the answers, because an explanation can be wrong too.

Check that added packages are real, maintained and needed. Try the app with the network turned off and with unexpected input, such as a very long word or text that looks like HTML. Model replies and user text should appear as plain text, not run as code. If you cannot understand an important part of the app, keep it as a private prototype until someone who can has reviewed it.

Common mistake: sharing a link to a prototype "just to show a friend" and forgetting about it. Other people may use up your quota. Remove or restrict apps that you no longer use.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Where should the Gemini API key live in a web app?

    Users can read anything that is sent to the browser.
  2. 2. You deploy your app to Cloud Run and others use it. Who pays for the model calls?

    Google's documentation says the deployment includes your key, so the calls are billed to you.
  3. 3. Why ask for one change at a time?

    Small changes are easy to check and undo.

Summary

  • Build mode creates web and Android prototypes from a description.
  • Write a specification, change one thing at a time and recheck old features.
  • Keep the API key on the server, and know who pays.
  • Review security, data, errors, accessibility and cost before sharing.

Next: Your First Gemini API Request

你的学习进度保存在此浏览器中,无需账号。