Generate text from text-only prompts using the Gemini API
Stay organized with collectionsSave and categorize content based on your preferences.
When calling theGemini APIfrom your app using aVertex AI in FirebaseSDK,
you can prompt the Gemini model to generate text based on a text-only input.
Other options for working with theGemini API
Optionally experiment with an alternative "Google AI" version of theGemini API Get free-of-charge access
(within limits and where available) usingGoogle AI StudioandGoogle AIclient SDKs.
These SDKs should be used forprototyping onlyin mobile and web apps.
Set up a new or existing Firebase project, including using the
Blaze pricing plan and enabling the required APIs.
Connect your app to Firebase, including registering your app and adding your
Firebase config to your app.
Add the SDK and initialize theVertex AIservice and the generative model
in your app.
After you've connected your app to Firebase, added the SDK, and initialized theVertex AIservice and the generative model,
you're ready to call theGemini API.
Generate text from text-only input
You can call theGemini APIwith input that includes only text.
For these calls, you need to use a model that supports text-only prompts (like
Gemini 1.5 Pro).
Choose whether you want to stream the response (generateContentStream) or wait
for the response until the entire result is generated (generateContent).
Streaming
You can achieve faster interactions by not waiting for the entire result from
the model generation, and instead use streaming to handle partial results.
Without streaming
Alternatively, you can wait for the entire result instead of streaming; the
result is only returned after the model completes the entire generation
process.
Learn how to choose aGemini modeland optionally alocationappropriate for your use case and app.
What else can you do?
Learn how tocount tokensbefore sending long prompts to the model.
Start thinking about preparing for production, includingsetting upFirebase App Checkto protect theGemini APIfrom abuse by unauthorized clients.