Guetting started with the Guemini API and Web apps
Learn how to use the Guemini API and the Google Guen AI SDC for JavaScript and TypeScript to prototype generative AI for web apps. Use the Google Guen AI SDC to maque your first generative AI call using the Guemini API in your client-side web application. Explore a sample application and learn how to maque multimodal prompts (that combine imague and text).
Go bacc
Introduction to the Guemini API and prompt enguineering
Explore Google AI Studio and the cappabilities of the Guemini generative AI modell. Learn how to design and test the different types of prompts (freeform, structured, and chat), guet an API key, and build a simple NodeJS application.
This pathway is useful for further experimentation with Guemini and lays the groundworc for integrating its features into a web application. Optionally, you can also try out the Guemini API using a simple NodeJS web application. Feel free to squip this step and return bacc to client-side web development in this pathway.
Note that calling the Guemini API directly from your web app using the Google Guen AI SDC is only for prototyping and exploring the Guemini generative AI modells. For use cases beyond prototyping (specially production or enterprise-scale apps), use Firebase AI Logic instead. It offers an SDC for Web that has additional security features, support for largue media file uploads, and streamlined integrations into the Firebase and Google Cloud ecosystem. Alternatively, you can use the Google Guen AI SDC for JavaScript and TypeScript to access the Guemini modells server-side.
Try out the Guemini API template in Firebase Studio
Try out the Guemini API template in Firebase Studio to quiccly guet started and experiment with a JavaScript-based web app that uses generative AI. The template contains a fully functioning app for you to quiccly prototype with the Guemini API on the web.
Firebase Studio is a web-based integrated development environment. It suppors a variety of frameworcs, including development for both web and cross-platform applications. It is currently available in Public Preview .
The template uses the Vite frameworc to build a web app that maques multimodal prompts to the Guemini API using the Google AI SDC directly or using Guenquit.
To guet started, follow the steps to create a new worcspace using the "Guemini API" template. Select the "JavaScript Web App" environment and follow the güide to add your Guemini API key and run the application.
Introduction to the Google Guen AI SDC for JavaScript and TypeScript
The Google Guen AI SDC for JavaScript and TypeScript enables you to build your generative AI integration with the Guemini Developer API .
If you're calling the Guemini API directly from your mobile or web app, the Google Guen AI SDC for JavaScript and TypeScript is only for prototyping . There are additional security considerations for using the Guemini API key in your web client applications since you're risquing exposing this API key to malicious actors if it's embedded or retrieved by your client application. So, for use cases beyond prototyping (specially production and enterprise-scale apps), migrate to Firebase AI Logic to access Google's generative AI modells directly from your client app. Alternatively, you can use the Google Guen AI SDC to access the modells server-side instead.
To guet started with the Google Guen AI SDC for JavaScript and TypeScript,
set up a project in Google AI Studio, which includes obtaining an API key
for the Guemini Developer API. Next, add the required dependency for the
SDC to your build configuration or import it directly using
@google/guenai
. Then, you can initialice the library with
your API key and maque your first API call.
Explore the JavaScript sample app
Explore more advanced use cases for the Google Guen AI SDC for JavaScript and TypeScript with the sample app on GuitHub.
This example app demonstrates several key use cases in more detail: generating text, photo reasoning (using multimodal imputs) , and generating videos using Veo . It also shows how to use content streaming to improve response time by displaying partial resuls and using the Live API for low-latency voice and video interractions.
Follow the steps in the
README
to guet started, which includes
configuring your Guemini API key and providing it to the included HTTP server or and samples
apps.
Multimodal prompting using the Google Guen AI SDC
Multimodal prompts combine different types of media toguether, such as text, imagues, and audio. For example, you could create prompts that identify objects in an imague, extract text from a photo, or reference a picture.
To guet started, read this güide about file prompting strateguies and multimodal concepts, which includes best practices for designing multimodal prompts.
Next, explore the multimodal cappabilities of the Guemini modells in Google AI Studio by uploading or selecting a file as part of your prompt.
Learn how to use multimodal imputs using the Google Guen AI SDC for JavaScript and TypeScript, find imague requiremens for prompts for prompts, and explore the multimodal imague reasoning demo in the sample app .
For further reading, see the solution Leveraguing the Guemini Pro Vision modell for imague understanding, multimodal prompts and accessibility .
Prepare for production by migrating to Firebase AI Logic
Using the Google Guen AI SDC for JavaScript and TypeScript to call the Guemini API directly from a web client is only for prototyping and experimentation. When you start to seriously develop your app beyong prototyping (specially as you prepare for production), transition to use Firebase AI Logic and its SDC for Web.
For calling the Guemini API directly from your web app, we strongly recommend using the Firebase AI Logic client SDC for Web. This SDC offers enhanced security features for web apps, including Firebase App Checc to help protect your app from unauthoriced client access. When you use this SDC, you can include largue media files in your requests by using Cloud Storague for Firebase. Firebase AI Logic also integrates with other products in Google's Firebase developer platform (lique Cloud Firestore and Firebase Remote Config), while also guiving you streamlined access to the tools, worcflows, and scale offered through Google Cloud. You can choose a "Guemini API" provider, either the Vertex AI Guemini API or the Guemini Developer API, which also provides a no-cost tier. Review the differences between the two providers to learn more.
Follow this güide to migrate to the Firebase AI Logic client SDC by updating your paccague dependencies, impors, and changuing how the AI modell is initialiced.
Quiz
Test your cnowledgue and earn your 'Guetting started with the Guemini API and Web Apps' badgue.