Feature Request: Enable a "Bring Your Own Key" (BYOK) for Apps Built with Google AI Studio

Feature Request for Google AI Studio

Enable a “Bring Your Own Key” (BYOK) for Apps Built with AI Studio

Background: As a developer and consultant, I use the “Build” feature within Google AI Studio to rapidly create AI-powered web applications. My goal is to deploy these generated apps and provide them to my clients for their own use.

The Current Problem: The apps generated by AI Studio are designed to use my developer’s API key by default. When I publish or deploy one of these apps for clients to use, all billable Google API calls made by that client are billed back to my account. That is not my business model: clients should pay for their usage of the API, not me.

There is currently no easy way for these AI Studio-generated apps that allows the end-user (my client) to enter and use their own API key. The current workflow is very cumbersome:

  • I have to export my app code as a zip-file
  • then transfer this file to my clients
  • they need to import it in Google AI Studio, which is quite complex
  • they then deploy it to their own Cloud Run account, and share the URL to their users

This is a critical blocker. It makes AI Studio’s powerful “Build” feature almost unusable for any B2B business model where the end-user is supposed to pay for their own consumption. As other developers have noted, this forces the developer to risk being bankrupted by their own app’s users (https://discuss.ai.google.dev/t/i-need-users-to-provide-their-own-api-key-but-this-isnt-allowed-any-more/107950).

Proposed Solution: Introduce a new setting within the AI Studio “Build” or “Publish” workflow, such as a checkbox: [ ] Enable End-User API Key Mode.

When an app is generated with this setting enabled, the deployed app should:

  1. On first load, automatically check if an API key is present in the user’s environment.

  2. If no key is found, the app should display a simple, standardized, and trusted modal dialog (e.g., “Please enter your Google AI API key to use this application”).

  3. Upon entry, the app should securely save this key.

  4. All API calls from the application should then use this user-provided key, ensuring the end-user is billed for their own usage.

Benefits:

  • Unlocks a Business Model: This immediately makes the “Build” feature viable platform for developers who build tools for clients.

  • Solves the Billing Problem: It correctly assigns API costs to the end-user who is incurring them.

  • Maintains Simplicity: It requires no extra work manual from the developer or client; it’s just a setting that enables a pre-built, secure component in the final app. This aligns with the “vibe coding” ethos of building apps without “juggling with API keys” (https://blog.google/technology/developers/introducing-vibe-coding-in-google-ai-studio/).

1 Like

Hi @paulvancotthem,

Thanks for the background. Based on your response, you are looking for a feature to deploy your app directly from build app and so that users can use it in their own AI Studio environment with their own key..

AI Studio is designed to be an experimental playground where users can build anything on the fly using prompt based approach.. If you want to use it as a consumer app with BYOK, Vertex AI is a great place to deploy it.. You can deploy and enable user provided key as an input to use the app.

I hope this suggestion helps you move ahead with you project. All the best!

1 Like
  • In Google AI Studio, I use the “deploy to Cloud Run” option.
  • I’ve never used Vertex AI and I do not know yet what it is. Where can I find more details about what you mean by “deploy on Vertex AI”?
  • Also, what are the detailed steps I need to follow for deploying my app’s code to Vertex AI? Is there a tutorial for this? Or could you detail the steps for me here?

Thank you.

Sure @paulvancotthem,

Actually there is a simple way that let’s you directly deploy your app without migrating to Vertex AI..

When you click deploy in AI Studio - it automatically injects your API key. Let’s avoid this step.

STRATEGY

  • Export the code
  • Modify the authentication logic to accept user input
  • Dockerize your app - create docker file with requirements.txt
  • Redeploy it to Cloud Run using Google Cloud Shell.

In your main.py file, you will find Gemini_api_key being injected. Replace that code with your user input based key logic. You can use streamlit framework for this step. Here is a sample code.

import streamlit as st
import google.generativeai as genai

# --- BYOK LOGIC START ---
st.sidebar.header("Configuration")
user_api_key = st.sidebar.text_input("Enter your Google API Key", type="password")

if not user_api_key:
    st.warning("Please enter your Google API Key in the sidebar to use this application.")
    st.stop() # Stop execution until key is provided

# Configure the SDK with the USER'S key
try:
    genai.configure(api_key=user_api_key)
except Exception as e:
    st.error(f"Invalid Key or Connection Error: {e}")
    st.stop()
# --- BYOK LOGIC END ---

# ... The rest of your AI Studio generated code goes here ...

Thanks, will try this.