Overview
This guide will walk you through setting up your Gemini API key and sending your first message. You’ll be chatting with AI in under 5 minutes.Before starting, make sure you have installed GemAI on your device or emulator.
Get your Gemini API key
Launch GemAI
Open the GemAI app on your Android device. On first launch, you’ll see the API key setup screen:

Navigate to Google AI Studio
Tap the Get Key button in the app. This will open your browser and redirect you to Google AI Studio:Alternatively, visit Google AI Studio directly in your browser.
Onboarding.kt
Generate your API key
In Google AI Studio:
- Sign in with your Google account
- Click Get API key or Create API key
- Select an existing Google Cloud project or create a new one
- Copy the generated API key to your clipboard
Enter and save your API key
Return to the GemAI app and:Once validated, you’ll automatically navigate to the chat screen.
- Paste your API key into the text field
- Tap the Save button
- The app will validate your API key
Onboarding.kt
Send your first message
Explore startup prompts
After API key validation, you’ll see the chat screen with suggested prompts:
These prompts help you get started quickly. Tap any prompt to begin a conversation, or write your own message.

Type your message
In the chat input field at the bottom of the screen, type your question or message.For example:
- “What is Clean Architecture in Android?”
- “Explain Kotlin coroutines with examples”
- “Write a poem about technology”
Send and receive
Tap the send button to submit your message. GemAI will:
- Create a new conversation (if this is your first message)
- Save your message to the local database
- Stream the AI’s response in real-time
ChatViewModel.kt
Understanding the chat flow
Here’s how GemAI processes your messages:Send to Gemini AI
The message is sent to the Gemini AI model through the The
GemAIModel class:GemAIModel.kt
sendMessageStream method returns a Flow, enabling real-time streaming responses.Store in database
All messages are persisted in the Room database:This ensures your conversation history persists across app sessions.
AppDatabase.kt
Key features to explore
Multiple conversations
Create multiple chat threads and switch between them using the side navigation
Conversation history
All your conversations are saved locally and accessible anytime
Dark mode
Toggle between light and dark themes for comfortable viewing
Markdown rendering
AI responses support markdown formatting for code blocks and rich text
How data is stored
GemAI uses a clean architecture approach with three layers:Data layer
The API key is stored securely using DataStore with Protocol Buffers:Domain layer
Business logic is encapsulated in use cases:SendMessageUseCase.kt
Presentation layer
ViewModels manage UI state and coordinate use cases:ChatViewModel.kt
Troubleshooting
API key validation fails
API key validation fails
If your API key is rejected:
- Verify you copied the entire key without extra spaces
- Check that the key is from Google AI Studio (not Google Cloud Console)
- Ensure your Google Cloud project has the Generative AI API enabled
- Try generating a new API key
Messages not sending
Messages not sending
If messages aren’t sending:
- Check your internet connection
- Verify your API key is still valid
- Check the Android Logcat for error messages
- Ensure the app has network permissions (already configured in manifest)
Conversation history not persisting
Conversation history not persisting
If your chats disappear:
- Check app storage permissions
- Verify the app isn’t being force-stopped by battery optimization
- Check if device storage is full
- Database is stored at:
/data/data/com.sarath.gem/databases/gemai.db
Slow response times
Slow response times
If responses are slow:
- Check your internet connection speed
- Large messages may take longer to process
- Google’s API may experience high traffic during peak hours
- Consider using a different Gemini model (if customization is added)
Next steps
Now that you’re up and running, explore more advanced features:Architecture overview
Understand how GemAI is structured with Clean Architecture
Database schema
Learn about the Room database structure and relationships
System prompts
Customize the AI’s behavior with system prompts
Extending GemAI
Learn how to add new features to GemAI
Remember to star the project on GitHub if you find GemAI useful!
