How to Use Gemini 2.5 Flash in Apps Script with Vertex AI

Google Workspace Developers · Beginner ·📰 AI News & Updates ·5mo ago

Key Takeaways

This video demonstrates how to use the Vertex AI advanced service in Apps Script to prompt the Gemini 2.5 Flash model and generate text. It covers setting up a Google Cloud project, enabling the Vertex AI API, and using the advanced service to call the API's generate content method.

Full Transcript

In this video, I'm going to show you how to use our Vertex AI advanced service to prompt the Gemini 2.5 flash model directly from an Appcript project. But first, what is Vertex AI and what makes it interesting to AppScript and Google Workspace developers? Google Cloud's Vertex AI is a machine learning platform that lets you train and deploy ML models and AI applications. There are a few reasons why you might be interested in using Vertex AI as an appcript developer. First, the Vertex AI's model garden provides Appcript developers with enterprisegrade access to Gemini and thirdparty models. The platform also supports advanced agentic features like function calling and fine-tuning while offering enhanced security and access control. These models and features ultimately make Vert.exai the preferred choice for scalable professional Google Workspace solutions that you can share with others in your organization or publicly on the Google Workspace marketplace. To use AppScript's Vertex AI advanced service, you need to have a Google Cloud project. In the cloud project, you must also enable billing and the Vert.ex AI API. Now that we have what we need, let's set up an Appcript project with Vert.Exai. If you'd like to try this out yourself, the instructions and code sample I'll be using are available in the AppScript documentation, which I'll link in the video description. Okay, so here's my Appcript project, which has some sample code. I'll start by enabling the Vertex AI service. From the editor, I click add a service. And then from the drop-own menu, I select Vertex AI API. After I click add, you can see that Vertex AI now appears under my enabled services. Now, let's look at the code. First, we're using the main function as the entry point to trigger the advanced service. This function includes the prompt we'll use and handles any errors if the connection to Vertex AI fails. Our prompt asks what is AppScript in one sentence. The main function triggers the function callver vertex AI which handles the API request by specifying an AI model and the cloud project ID and region. I've set my cloud project ID here as a script property, but you can also just specify the ID as a string. Here's where we specify the Gemini 2.5 flash model. This is the model we'll prompt with our question about AppScript. And here's the payload for the request to Vert.ex AI API, which includes the prompt and some other configurations, including the maximum output tokens for the response. In this line, you can see we're using the Vert.Ex AI advanced service to call the API's generate content method. The advanced service acts as a built-in authenticated wrapper that sends your request directly to the Vert.Ex AI API. To test this code, I go to the top menu and click run to run the main function. A window may pop up asking you to give permissions for the function to run, but otherwise it'll run right away as you see here. And in the execution log, the service has answered our prompt and generated some text explaining what Appcript is. And that's all there is to getting started with Vert.Exai. To try it out yourself, check out our quick start in the Appcript documentation. The quick start shows you how to configure your Google Cloud and Appcript projects and includes the code sample that I demoed for you today. For more advanced examples showing you how to use Vertex AI to build AI agents and add-ons for Google Workspace, check out our samples gallery. Thanks for watching.

Original Description

Learn how to get started with the Vertex AI advanced service in Apps Script. This video shows you how to set up and use the service to prompt the Gemini 2.5 Flash model to generate text. For more details, visit our documentation: https://developers.google.com/apps-script/quickstart/vertex-ai Subscribe to our YouTube channel: https://www.youtube.com/@googleworkspacedevs/ Subscribe to our Google Workspace Developer Newsletter: https://developers.google.com/workspace/newsletters #gemini #googleworkspace #appsscript #vertexai
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Playlist UUUcg6az6etU_gRtZVAhBXaw · Google Workspace Developers · 36 of 48

1 Jump start your Apps Script project with a starter template
Jump start your Apps Script project with a starter template
Google Workspace Developers
2 Format and fix code with the Apps Script command palette
Format and fix code with the Apps Script command palette
Google Workspace Developers
3 Join the Google Workspace Developer Summit 2025
Join the Google Workspace Developer Summit 2025
Google Workspace Developers
4 Simplify your code using Apps Script libraries and services
Simplify your code using Apps Script libraries and services
Google Workspace Developers
5 Quote other messages via Chat API, rollout of granular OAuth consent for Editor add ons, and more!
Quote other messages via Chat API, rollout of granular OAuth consent for Editor add ons, and more!
Google Workspace Developers
6 Developer Spotlight with Taylor Lykins, Product Manager at Lucid Software
Developer Spotlight with Taylor Lykins, Product Manager at Lucid Software
Google Workspace Developers
7 Rollout of granular OAuth consent for Editor add-ons
Rollout of granular OAuth consent for Editor add-ons
Google Workspace Developers
8 Why did Lucid create Google Workspace integrations?
Why did Lucid create Google Workspace integrations?
Google Workspace Developers
9 Use the Apps Script project dashboard
Use the Apps Script project dashboard
Google Workspace Developers
10 Generate Apps Script code using Google AI Studio
Generate Apps Script code using Google AI Studio
Google Workspace Developers
11 Updates to the Gmail API, the Reports API, Chat app capabilities, and more!
Updates to the Gmail API, the Reports API, Chat app capabilities, and more!
Google Workspace Developers
12 Create Deal Card via the Gmail API
Create Deal Card via the Gmail API
Google Workspace Developers
13 Check out the interview Taylor from Lucid Software
Check out the interview Taylor from Lucid Software
Google Workspace Developers
14 Google Workspace Development Crash Course in Paris
Google Workspace Development Crash Course in Paris
Google Workspace Developers
15 How to use variables in Workspace Flows
How to use variables in Workspace Flows
Google Workspace Developers
16 Develop custom steps for Workspace Flows
Develop custom steps for Workspace Flows
Google Workspace Developers
17 Calendar API update for secondary calendars, create Workspace Flows custom steps, and more!
Calendar API update for secondary calendars, create Workspace Flows custom steps, and more!
Google Workspace Developers
18 Google Workspace Developer Summit - Behind the scenes
Google Workspace Developer Summit - Behind the scenes
Google Workspace Developers
19 From Signal to Success  Lucid Software’s Journey as an Early Google Chat Integration Partner
From Signal to Success Lucid Software’s Journey as an Early Google Chat Integration Partner
Google Workspace Developers
20 Beyond the Build: Navigating the Google Workspace Marketplace Review Process
Beyond the Build: Navigating the Google Workspace Marketplace Review Process
Google Workspace Developers
21 Prepare for Granular OAuth Consent in Apps Script powered Add-ons and Chat Apps
Prepare for Granular OAuth Consent in Apps Script powered Add-ons and Chat Apps
Google Workspace Developers
22 Demystifying Service Accounts  When, Why, and How to Use Them
Demystifying Service Accounts When, Why, and How to Use Them
Google Workspace Developers
23 Supercharge collaboration with Meet APIs
Supercharge collaboration with Meet APIs
Google Workspace Developers
24 Apps Script in Google Workspace
Apps Script in Google Workspace
Google Workspace Developers
25 Leveraging AI Tools in Workspace Development
Leveraging AI Tools in Workspace Development
Google Workspace Developers
26 Google Workspace Developer News: Granular OAuth rollout, Drive Events, Meet API, and more!
Google Workspace Developer News: Granular OAuth rollout, Drive Events, Meet API, and more!
Google Workspace Developers
27 Granular OAuth consent for web apps and Workspace add-ons
Granular OAuth consent for web apps and Workspace add-ons
Google Workspace Developers
28 Developer Spotlight: The State of AI in Workspace Development
Developer Spotlight: The State of AI in Workspace Development
Google Workspace Developers
29 What's your AI-assisted developer workflow?
What's your AI-assisted developer workflow?
Google Workspace Developers
30 Developer Spotlight: Service Accounts need to know & using AI isn't cheating
Developer Spotlight: Service Accounts need to know & using AI isn't cheating
Google Workspace Developers
31 Using AI is not cheating!
Using AI is not cheating!
Google Workspace Developers
32 Developer Spotlight: Granular OAuth consent and publishing to the Workspace Marketplace
Developer Spotlight: Granular OAuth consent and publishing to the Workspace Marketplace
Google Workspace Developers
33 Developer Spotlight: Suraj Iyer - Apps Script Product Manager
Developer Spotlight: Suraj Iyer - Apps Script Product Manager
Google Workspace Developers
34 Google Workspace Developer News: December 2025 Updates
Google Workspace Developer News: December 2025 Updates
Google Workspace Developers
35 Automate Your Tasks in 5 Minutes: Apps Script + Gemini for Beginners
Automate Your Tasks in 5 Minutes: Apps Script + Gemini for Beginners
Google Workspace Developers
How to Use Gemini 2.5 Flash in Apps Script with Vertex AI
How to Use Gemini 2.5 Flash in Apps Script with Vertex AI
Google Workspace Developers
37 Get started with Vertex AI in Apps Script
Get started with Vertex AI in Apps Script
Google Workspace Developers
38 Google Workspace Developer News: January 2026 Updates
Google Workspace Developer News: January 2026 Updates
Google Workspace Developers
39 Get started with Google Workspace Studio
Get started with Google Workspace Studio
Google Workspace Developers
40 Check out how to get started with Google Workspace Studio
Check out how to get started with Google Workspace Studio
Google Workspace Developers
41 How to use variables in Google Workspace Studio
How to use variables in Google Workspace Studio
Google Workspace Developers
42 Why you sometimes can't add variables in Google Workspace Studio
Why you sometimes can't add variables in Google Workspace Studio
Google Workspace Developers
43 Google Workspace Studio: Extract PDF Data to Sheets Automatically
Google Workspace Studio: Extract PDF Data to Sheets Automatically
Google Workspace Developers
44 Let's build an invoice assistant in Workspace Studio
Let's build an invoice assistant in Workspace Studio
Google Workspace Developers
45 Google Workspace Developer News: February 2026 Updates
Google Workspace Developer News: February 2026 Updates
Google Workspace Developers
46 Google Workspace Studio: Understanding Starters and Steps
Google Workspace Studio: Understanding Starters and Steps
Google Workspace Developers
47 Check out templates in Google Workspace Studio
Check out templates in Google Workspace Studio
Google Workspace Developers
48 Get data from an email attachment with Workspace Studio
Get data from an email attachment with Workspace Studio
Google Workspace Developers

This video teaches you how to use the Vertex AI advanced service in Apps Script to generate text using the Gemini 2.5 Flash model. It covers setting up a Google Cloud project and using the advanced service to call the API's generate content method. By following this tutorial, you can build LLM-based applications and use AI to generate text.

Key Takeaways
  1. Set up a Google Cloud project
  2. Enable the Vertex AI API
  3. Create an Apps Script project
  4. Enable the Vertex AI advanced service
  5. Specify the Gemini 2.5 Flash model
  6. Configure the payload for the API request
  7. Call the API's generate content method
  8. Test the code and view the generated text
💡 The Vertex AI advanced service acts as a built-in authenticated wrapper that sends your request directly to the Vertex AI API, making it easy to integrate AI with Apps Script.

Related AI Lessons

When AI Asks for More Electricity Than a Country Can Imagine
AI's increasing power consumption is causing concerns, learn why it matters for data centers and energy supply
Medium · AI
You Are Not Behind. The World Is.
You're not behind, the world is still adapting to AI, and it's okay to take your time to learn and grow
Medium · AI
Career choice with the advent of AI - pure Computer Science or learn software with a background of core engineering area
Learn how to choose between a Computer Science and Engineering career path or combining programming with a core engineering background in the age of AI
Dev.to AI
The AI Hype Cycle: Calm Before the Next Breakthrough?
Understand the AI hype cycle to anticipate the next breakthrough and make informed decisions
Medium · Programming
Up next
Generative AI
Alea IT Solutions
Watch →