The Simplest Way to Make Cloud Run and Vertex AI Work Like They Should
Pairing cloud run and vertex ai lets teams host web apps that call machine learning models. Cloud Run handles user traffic while Vertex AI runs predictions and returns results. This setup keeps web scaling separate from model compute. Web containers scale down to zero when idle. Model endpoints stay ready to serve predictions on demand. Teams can update web code without touching model weights. This separation makes daily releases fast and safe for engineering teams. How cloud run and vertex a
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Pairing cloud run and vertex ai lets teams host web apps that call machine learning models. Cloud Run handles user traffic while Vertex AI runs predictions and returns results.
This setup keeps web scaling separate from model compute. Web containers scale down to zero when idle. Model endpoints stay ready to serve predictions on demand. Teams can update web code without touching model weights. This separation makes daily releases fast and safe for engineering teams.
How cloud run and vertex ai share permissions and data
A Cloud Run service needs a clear identity to call a Vertex AI endpoint. Google Cloud uses service accounts to manage this trust between both tools. You assign a dedicated service account to your Cloud Run container revision. Then you grant that account the role needed to run predictions on Vertex AI.
When a user sends a request, the Cloud Run app reads the input payload. The app formats the data into a structure the model expects. Next, the container uses its built-in metadata server to fetch an identity token. It attaches this token to the request and sends it to the Vertex AI endpoint.
Vertex AI checks the token against project roles before running the model. If the role matches, the model processes the input and sends back the output. The Cloud Run app parses that response and returns the final answer to the user. All of this happens over Google Cloud internal networks with low latency.
Common pitfalls with shared roles and network paths
Many teams start by using the default compute service account for their containers. That default account often holds broad editor rights across the entire cloud project. If an attacker finds a bug in the web app, they gain those broad rights. They could read storage buckets, delete databases, or call any model in the project.
To fix this, create one custom service account for each Cloud Run service. Grant only the specific Vertex AI prediction role to that single account. When possible, bind the role at the endpoint level rather than the whole project. This stops a web app from calling models meant for other internal teams.
AI Agent Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Another common issue is sending sensitive user data straight into model prompts. User inputs often hold emails, phone numbers, card numbers, or national IDs. If you log full prompts for debugging, those logs will store raw personal data. Masking tools can rewrite matched fields in results and payloads before they hit storage.
Network paths also need tight rules in production setups. By default, calls may travel over public endpoints even inside the same cloud region. Teams should set up private service access or Virtual Private Cloud connectors. This keeps all traffic between the web container and the model on private links.
How to keep model calls fast and reliable
Model calls take much longer than standard database reads. A large language model might take several seconds to finish a single response. If your Cloud Run timeout is too short, the container will drop the call. Always set the container timeout higher than your slowest expected model response time.
Concurrency settings on Cloud Run also matter a lot for AI workloads. If one container handles too many waiting requests, it can run out of memory. Lower the concurrency limit if your app holds large payloads in memory during calls. You should also stream responses back to users so they see progress right away.
Finally, track costs and usage by adding labels to your services and endpoints. Clear labels show which web app drives the most model compute spend each month. Good logs and metrics help teams spot slow prompts before users complain.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
How should Cloud Run log in to Vertex AI?
Attach a dedicated service account to your Cloud Run service. The Google Cloud client library will fetch short-lived tokens from the metadata server. Never store static JSON key files inside your container image.
How do I stop Cloud Run timeouts during slow model calls?
Increase the request timeout setting on your Cloud Run service to match model latency. Use streaming endpoints in Vertex AI so data flows back to the user in chunks. Set client retry rules with exponential backoff to handle brief quota limits.
Can Cloud Run call Vertex AI inside a different Google Cloud project?
Yes, cross-project calls work well when you configure IAM roles across both projects. Grant the Cloud Run service account from the first project the prediction role in the second project. Make sure your network rules and VPC Service Controls allow traffic between both projects.
Related guides
In this post