惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
S
SegmentFault 最新的问题
D
DataBreaches.Net
H
Help Net Security
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
Martin Fowler
Martin Fowler
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
罗磊的独立博客
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Vercel News
Vercel News
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
博客园 - 三生石上(FineUI控件)

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
GCP in Action: Migrating a LINE Bot from AI Studio to Ver...
Evan Lin · 2026-05-02 · via DEV Community

image-20260421011411264

Background

Recently, the LINE business card assistant robot (linebot-namecard-python) deployed on Google Cloud Run suddenly went down. After checking the logs with gcloud logging read, the following ruthless error appeared:

google.api_core.exceptions.ResourceExhausted: 429 Your billing account has exceeded its monthly spending cap.

It turned out that we used the API Key provided by Google AI Studio (google.generativeai package) for rapid development, and as a result, we silently maxed out the monthly free quota.

As a developer who needs to launch a service, it's time to "level up" the architecture and migrate the model calls to the enterprise-grade Google Cloud Vertex AI, directly using GCP's IAM permissions and billing system. This article will share the migration process and the various pitfalls encountered along the way.


Technical Upgrade: From AI Studio to Vertex AI

To migrate a project from the Google AI Studio SDK to Vertex AI, there are three main steps:

  1. Replace the dependency package: In requirements.txt, remove the old google.generativeai and replace it with google-cloud-aiplatform.

  2. Update environment variable settings: In config.py, we no longer need GEMINI_API_KEY, but instead use GCP's PROJECT_ID and LOCATION:

PROJECT_ID = os.getenv("PROJECT_ID", None)
LOCATION = os.getenv("LOCATION", "global") # Default to global

Enter fullscreen mode Exit fullscreen mode

  1. Core code rewriting (gemini_utils.py): Although the SDK interface of Vertex AI is similar, the handling of multimodal data (such as images) is slightly stricter. We need to convert PIL.Image to the vertexai.generative_models.Part format:

Pitfall 1: Residual Old SDK Causing Cloud Run Startup Failure

Happily, I updated the environment variables with gcloud run services update, but the Cloud Run deployment failed, and the container couldn't even start.

After checking the logs, I found:

ModuleNotFoundError: No module named 'google.generativeai'

Reason: Although gemini_utils.py has been rewritten, the main program app/main.py still contains import google.generativeai as genai and the initialization code genai.configure(api_key=...). Since the package has been removed from requirements.txt, the container will naturally fail to find the module and crash during startup.

Solution: Globally grep the project, completely remove all references to the old SDK, and then repackage the Docker image using Cloud Build and push it again.


Pitfall 2: Vertex AI Model Name and Region Restrictions (404 Not Found)

Google Chrome 2026-04-21 01.12.46

The code is cleaned up, and the container also starts successfully, but when I send a business card image on LINE, the robot throws a 500 error. After reviewing the logs again, this time it's:

google.api_core.exceptions.NotFound: 404 Publisher Model ... gemini-1.5-flash was not found or your project does not have access to it.

This is the biggest pit I encountered this time! In Google AI Studio, you can casually use the alias gemini-1.5-flash; but in certain regions of Vertex AI (such as asia-east1 Taiwan), you must specify the exact version number, such as gemini-1.5-flash-002, otherwise the API will directly tell you that the model cannot be found.

Advanced Challenge: I want to try Gemini 3.0 Flash Preview!

To solve this problem, I had an idea. Since I'm going to change it, why not upgrade directly to the latest gemini-3-flash-preview!

As a result, I wrote a test script and found:

  • asia-east1 (Taiwan): 404 Not Found
  • us-central1 (Central US): 404 Not Found
  • global (Global): SUCCESS!

That's right, currently this preview model on Vertex AI is only available in the global region.

Final Solution:

  1. Change the default region in config.py to global.
  2. Call vertexai.init(project="line-vertex", location="global").
  3. The Cloud Run environment variable --update-env-vars="LOCATION=global" must also be aligned.

Summary: Changes Brought by Vertex AI

After some effort, the business card robot finally came back to life and used the latest Gemini 3 Flash model. After migrating from AI Studio to Vertex AI, several significant benefits have been brought:

  1. Get rid of Quota Anxiety: No longer limited by AI Studio's free quota or Spending Cap, directly deduct through GCP billing, suitable for production environments.
  2. Security Enhancement: Removed the plaintext API Key in the environment variables and used GCP's Default Application Credentials (IAM) for authentication, making the architecture more secure.
  3. Stability: Enterprise-grade SLA guarantee.

This experience also reminded me that when using Vertex AI on GCP, you must first check the official documentation to confirm the correspondence between "Region" and "Model Name" to avoid being overwhelmed by 404 errors after deployment.

If you also have a project that is about to move from AI Studio to Vertex AI, I hope this pitfall record can help you avoid some detours!