Skip to content

Services · by Google

Gemini API

Use Google’s Gemini models in your app to interpret text or images, such as turning a photo of a menu into a list of dishes.

Suppose you want to make a printed menu easier to read on a phone. Your app can send a photo and an instruction to Gemini and use the response to build a list with larger text.

Try a clear photo in Google AI Studio first. Ask for dish names and prices and tell it to mark anything unreadable. Compare every price with the photo before using the same request in your app.

When to use it
When your app needs to answer questions, read documents or write text with Google’s models, or you want to start on a free tier.
When to skip it
If you only want an AI tool to write your code. You need it only when your finished app uses AI itself.
What it costs
A free tier with limits covers some models. Gemini 4 Argon is paid only. It costs $2 per million input tokens and $10 per million output tokens through November 30, 2026. After that, it costs $4 and $20.

Add AI features with the Gemini API

Add one AI feature from your plan, like a summary or a helper chat, using Google’s Gemini API. You can start on the free tier, and your key stays on your app’s server.

You’ll need

  • A website or app you started, open in your AI tool.
  • PLAN.md from the Plan your idea guide.
  • Google account. You sign in to Google AI Studio with it.

Your part

  • Sign in to Google AI Studio and choose the free or paid tier.
  • Create the API key and paste it into your .env file.
  • Try the feature and check your usage.

Copy the prompt for these steps

All 5 steps, in one prompt
I’m following “Add AI features with the Gemini API” on BuildLadder.
What the guide says I’ll end up with: One AI feature from your plan, working in your app, with your key kept out of your code and your costs under control.
This comes from https://buildladder.com/tools/gemini-api#ai-features. If you can open web pages, read https://buildladder.com/tools/gemini-api.md for the current version. BuildLadder guide, tool, concept, answer and setup pages all work this way: add .md to the address.

How to work with me:
- Go through the steps below in order, one at a time.
- Do what you can yourself in this folder: write code, run commands, check settings. If a service has an official command-line tool, like the Vercel CLI, you can offer to use it. Ask me before you install anything, sign in to anything or spend money.
- When a step needs me, like making an account or clicking in a dashboard, tell me exactly what to do in small steps. Then wait until I say it’s done.
- The actions, checks and fixes in each step were written for me, the reader. Where one says “your AI tool”, that means you, and “Say:” means something I would say to you.
- Never ask me to paste passwords or secret keys into this chat. I type those into the service’s own settings.
- After each step, tell me how to check it worked. Once Git is set up, save a version each time a step works. Then ask if I’m ready for the next one.
- Use plain words. I may never have coded before.

## Step 1 of 5: Sign in and choose free or paid

This step is mine to do. Walk me through it, one action at a time:
- Go to aistudio.google.com and sign in with your Google account.
- Start on the free tier. Google uses what you send on the free tier to improve its products, so test with made-up examples.
- To pay instead, open the Projects page. Find your Free Tier project and click Set up billing in the Billing Tier column.
- Choose or create a billing account, then add your country, contact details and card. You may be asked to prepay at least $5.
- If you pay, leave auto-reload off. Then open the Spend page, find Monthly spend cap, and click Edit spend cap.
- Set up billing before real people use the feature. On the paid tier, Google doesn’t use your requests to improve its products.

It worked when: You’re signed in to Google AI Studio, on the free tier or with a spend cap set.

Before we move on, check with me:
- Does the Projects page show your project and its billing tier?

If something goes wrong:
- You’re offered Postpay instead of Prepay. Google is still rolling Prepay out, so some accounts get Postpay. Either works. Set a spend cap either way.
- The spend cap let you go slightly over. That can happen. Google says the cap can run about 10 minutes behind. Set it a little below your real limit.

## Step 2 of 5: Create a key and save it in .env

This step is mine to do. Walk me through it, one action at a time:
- In Google AI Studio, open the API Keys page and click Create API key.
- Copy the key. Paste it only into your .env file, never into the chat.
- In your product’s folder, open the file named .env. If there isn’t one, ask your AI tool to create an empty one, then open it yourself.
- Add the line GEMINI_API_KEY=your-key, with your real key and no spaces. Save the file.
- Don’t save a version yet. “Add one AI feature” first checks that Git leaves your .env file out.

It worked when: Your .env file holds your key, and it is saved only on your computer.

Before we move on, check with me:
- Does the line start with GEMINI_API_KEY= and have no spaces?

If something goes wrong:
- Your key has an Unrestricted label. Gemini rejects unrestricted keys. Hover over the label, click Add restrictions, and choose Restrict to Gemini API only.
- Your key has a Blocked tag. Google blocks unrestricted keys that sat unused. Create a new key and update the line in your .env file.

## Step 3 of 5: Add one AI feature

Read PLAN.md in this folder. It has my plan and the tools I chose.

I want to add one AI feature that uses the Gemini API. Pick the one feature from my plan that fits best, like a summary or a helper chat. Tell me which one and wait for my OK.

Before you write code:
- Check that .env is listed in .gitignore. If it isn’t, add it. Don’t open or print .env.
- Create .env.example with only the variable name GEMINI_API_KEY and no value.
- Check Google’s current official docs for the right library and a current, low-cost model that has a free tier.

Then build the feature:
- Call Gemini only from server code, like an API route or a server function. Never call it from the browser or the phone app.
- Read the key from the GEMINI_API_KEY environment variable. Never put the key in code, logs or Git.
- Never use a variable name the browser or app can read, such as one starting with NEXT_PUBLIC_ or EXPO_PUBLIC_.
- If my app has no server part yet, suggest the simplest one for my setup and ask me first.
- Cap the answer length with the API’s maximum output setting, so each answer stays short and cheap.

Keep everything that already works.

It worked when: Your app shows an answer from Gemini when you try the feature on your computer.

Before we move on, check with me:
- Does your AI tool say the file that calls the API is server code, not a page or screen?

If something goes wrong:
- It says the API key is missing or invalid. Check that the line in your .env file starts with GEMINI_API_KEY= and has no spaces. Then restart your app so it reads the file again.
- It uses a different key than the one in your .env file. If GOOGLE_API_KEY is also set on your computer, Gemini’s library uses that one first. Remove it, or ask your AI tool to check.
- You get a 429 RESOURCE_EXHAUSTED error on the free tier. You hit the free tier’s limit. Wait a minute and try again. Daily limits reset at midnight Pacific time.

## Step 4 of 5: Handle waiting, errors and limits

My AI feature works. Now make it safe and friendly to use.

Check Google’s current official Gemini API docs for the errors the API can return, including 429 RESOURCE_EXHAUSTED. Then:
- Show a clear loading message while the answer is on its way, and stop people from sending the same request twice.
- Show a short, friendly message when something fails. Keep the real error in the server logs only, and never log the key.
- Give these cases their own plain message: too many requests (a rate limit), out of credits or over my spend cap, and the service being busy.
- Limit how long a person’s input can be, and keep the answer length capped.
- Add a simple limit on how many times one person can use the feature in a short time, so nobody can use up my free limit or run up my bill.

Keep everything that already works. Make only these changes. Then give me a short list of things to try, and what I should see for each one.

It worked when: Your feature shows a loading message and friendly errors, and stops one person from using it too often.

Before we move on, check with me:
- When you send an empty box, is the message helpful?
- When you paste in a very long text, does it stop you politely?

If something goes wrong:
- You can’t make an error happen to test it. Ask your AI tool to show you how to fake each error for a moment on your computer, then undo it.

## Step 5 of 5: Try it and check the cost

This step is mine to do. Walk me through it, one action at a time:
- Use the feature five times with made-up examples that match your plan.
- Make a mistake on purpose, like sending an empty box. Check the message makes sense.
- Ask your AI tool to build the app and check that your key is in no file a visitor’s browser or phone downloads.
- On the free tier, open the Rate Limit page in Google AI Studio to see your limits. On the paid tier, open the Spend page to see what those tries cost.
- Write the cost of one use into PLAN.md. If it’s too high, ask your AI tool for a cheaper model or shorter answers.
- When you put your app online, add the same key in your host’s settings. The .env file doesn’t go online.

It worked when: The feature works with made-up examples, your key stays hidden, and you know your limits or roughly what one use costs.

If something goes wrong:
- A second key didn’t give you more free requests. Limits count per project, not per key. Wait for the limit to reset, or set up billing.
- The feature works on your computer but not online. Your host needs the key too. Add GEMINI_API_KEY in its settings, then put your app online again.

The steps

  • Steps marked AI tool are done by your AI tool when you paste the prompt. The rest are yours.
  • Save a version after every step that works.
  • If a screen looks different from a step, ask your AI tool where the setting moved.
  • Never paste a password or secret key into the chat.
  1. Your account and key are ready

    Sign in and choose free or paid

    You

    The Gemini API is how your app talks to Google’s Gemini models. You only pay if you set up billing.

    1. Go to aistudio.google.com and sign in with your Google account.
    2. Start on the free tier. Google uses what you send on the free tier to improve its products, so test with made-up examples.
    3. To pay instead, open the Projects page. Find your Free Tier project and click Set up billing in the Billing Tier column.
    4. Choose or create a billing account, then add your country, contact details and card. You may be asked to prepay at least $5.
    5. If you pay, leave auto-reload off. Then open the Spend page, find Monthly spend cap, and click Edit spend cap.
    6. Set up billing before real people use the feature. On the paid tier, Google doesn’t use your requests to improve its products.

    It worked when: You’re signed in to Google AI Studio, on the free tier or with a spend cap set.

    Check this step
    • Does the Projects page show your project and its billing tier?
    You’re offered Postpay instead of Prepay.

    Google is still rolling Prepay out, so some accounts get Postpay. Either works. Set a spend cap either way.

    The spend cap let you go slightly over.

    That can happen. Google says the cap can run about 10 minutes behind. Set it a little below your real limit.

  2. Create a key and save it in .env

    You

    An API key is a secret code that lets your app use your account. It goes in your .env file, which stays on your computer and out of your shared code.

    1. In Google AI Studio, open the API Keys page and click Create API key.
    2. Copy the key. Paste it only into your .env file, never into the chat.
    3. In your product’s folder, open the file named .env. If there isn’t one, ask your AI tool to create an empty one, then open it yourself.
    4. Add the line GEMINI_API_KEY=your-key, with your real key and no spaces. Save the file.
    5. Don’t save a version yet. “Add one AI feature” first checks that Git leaves your .env file out.

    It worked when: Your .env file holds your key, and it is saved only on your computer.

    Check this step
    • Does the line start with GEMINI_API_KEY= and have no spaces?
    Your key has an Unrestricted label.

    Gemini rejects unrestricted keys. Hover over the label, click Add restrictions, and choose Restrict to Gemini API only.

    Your key has a Blocked tag.

    Google blocks unrestricted keys that sat unused. Create a new key and update the line in your .env file.

  3. Your AI feature works

    Add one AI feature

    AI tool

    Add one AI feature from your plan. Your app’s server calls Gemini, so the key never reaches a visitor’s browser or phone.

    It worked when: Your app shows an answer from Gemini when you try the feature on your computer.

    Check this step
    • Does your AI tool say the file that calls the API is server code, not a page or screen?
    It says the API key is missing or invalid.

    Check that the line in your .env file starts with GEMINI_API_KEY= and has no spaces. Then restart your app so it reads the file again.

    It uses a different key than the one in your .env file.

    If GOOGLE_API_KEY is also set on your computer, Gemini’s library uses that one first. Remove it, or ask your AI tool to check.

    You get a 429 RESOURCE_EXHAUSTED error on the free tier.

    You hit the free tier’s limit. Wait a minute and try again. Daily limits reset at midnight Pacific time.

  4. Handle waiting, errors and limits

    AI tool

    AI answers take a few seconds, and sometimes fail. Without limits, one person could also use up your free limit or your credits.

    It worked when: Your feature shows a loading message and friendly errors, and stops one person from using it too often.

    Check this step
    • When you send an empty box, is the message helpful?
    • When you paste in a very long text, does it stop you politely?
    You can’t make an error happen to test it.

    Ask your AI tool to show you how to fake each error for a moment on your computer, then undo it.

  5. Try it and check the cost

    You

    Use the feature the way a visitor would. Then check your limits or your spend in Google AI Studio, so you know what each use costs.

    1. Use the feature five times with made-up examples that match your plan.
    2. Make a mistake on purpose, like sending an empty box. Check the message makes sense.
    3. Ask your AI tool to build the app and check that your key is in no file a visitor’s browser or phone downloads.
    4. On the free tier, open the Rate Limit page in Google AI Studio to see your limits. On the paid tier, open the Spend page to see what those tries cost.
    5. Write the cost of one use into PLAN.md. If it’s too high, ask your AI tool for a cheaper model or shorter answers.
    6. When you put your app online, add the same key in your host’s settings. The .env file doesn’t go online.

    It worked when: The feature works with made-up examples, your key stays hidden, and you know your limits or roughly what one use costs.

    A second key didn’t give you more free requests.

    Limits count per project, not per key. Wait for the limit to reset, or set up billing.

    The feature works on your computer but not online.

    Your host needs the key too. Add GEMINI_API_KEY in its settings, then put your app online again.

Compare Gemini API with the other options

Stuck? Try these, in order
  1. Stop asking it to “fix it”. Say exactly what’s wrong.

    Paste this into the same chat. It asks your AI tool to find the problem with you.

    Troubleshooting prompt
    I’m following “Gemini API” on BuildLadder and something isn’t working.
    This comes from https://buildladder.com/tools/gemini-api. If you can open web pages, read https://buildladder.com/tools/gemini-api.md for the current version. BuildLadder guide, tool, concept, answer and setup pages all work this way: add .md to the address.
    
    Ask me which step I’m on, what I tried and what happened, one question at a time. Look at the files in this folder if you can. Then explain the problem in plain words and suggest the smallest fix. Don’t change anything that already works.

  2. Check the service isn’t down.

    If you use one of these, open its status page before changing any code: Supabase, Vercel, Netlify, Cloudflare, Stripe, Clerk, Firebase, Resend, GitHub, Expo, Claude, OpenAI.

  3. Go back to your last saved version.
    Troubleshooting prompt
    Take my product back to the last saved version that worked. First show me which version that is and what will change. Don’t delete anything else.

  4. Make the change smaller.
    Troubleshooting prompt
    Let’s make a smaller change. Undo what you just tried. Then do only the first part of it, and tell me how to check that part works before we go on.

  5. Ask a person.

    Copy this, fill in each line, and post it in a community like r/vibecoding. Take out any keys or passwords first.

    Problem report
    What I'm building: (one sentence)
    What I asked my AI tool to do: (the last request)
    What I expected: (what should happen)
    What happened instead: (what you see)
    The exact error, if any: (copy it here)
    What I've tried: (each attempt, in order)
    My tools: (AI tool, website or app, hosting)

Look things up

Questions people ask

Words used on this page

API
An API is a set of rules that lets one program ask another for data or actions. Your app uses APIs to talk to outside services, such as maps, payments, or weather.
Spending limit
A spending limit is the most you let a service charge you in a month. When you reach it, the service stops instead of billing more. Some services call it a spend cap.
Auto-reload
Auto-reload buys more credits for you when your balance drops below an amount you choose. It keeps your app running, and it also means a bug that uses too much keeps charging your card until you notice.
API key
An API key is a long code that tells a service your app is allowed to use it. Many keys are secret, so treat them like passwords and keep them out of shared code.
Environment variable
An environment variable is a named setting stored outside your code, such as an API key or a database address. Your app reads it when it runs, so secrets stay out of your shared files.
Backend
The backend is the behind-the-scenes part of an app that visitors never see. It runs on a server, where it saves data and checks who is signed in.
Token
A token is a small chunk of text that an AI model reads and writes, often part of a word. AI tools count tokens to set usage limits, prices, and how much fits in the context window.
Rate limit
A rate limit is the most requests a service lets you make in a set time, like a minute or a day. Go over it and the service turns requests away for a while, often with a 429 error.
Error message
An error message is text a program shows when something goes wrong. It usually says what failed and where, which helps you or your AI tool find the fix.
Production
Production is the live version of your website or app that real people use. Changes there affect everyone, so you test them in a preview first.
Hosting
Hosting is a service that keeps your website on computers that stay online, so anyone can visit anytime. Many hosts have a free plan for small sites.

Official pages

What’s new

  • 13 Oct 2026: Google's Gemini 4 Argon is open to developers. Source

Updated · Google