|
|
Gemini API Basics - Getting Started with google-genai
Author: Venkata Sudhakar
Google Gemini is Google's family of multimodal AI models available through the Gemini API. The Python SDK is google-genai and the interface is clean and modern. Gemini comes in several tiers: Gemini 2.0 Flash is the workhorse - fast, cheap, and capable enough for the vast majority of business tasks like Q&A, classification, and summarisation. Gemini 2.5 Pro is Google's most powerful reasoning model for complex analysis. Flash Lite is the cheapest option for high-volume simple tasks. All are accessed through the same SDK with just a model name change. Unlike OpenAI where the system prompt is a separate parameter, Gemini uses a system_instruction parameter at the client or model level. The main call is client.models.generate_content() which takes a model name and a contents list. For multi-turn conversations you use a chat session via client.chats.create() which maintains the message history automatically. The API key is obtained free from Google AI Studio (aistudio.google.com) and supports generous free tier limits, making it an excellent choice for prototyping and small to medium business applications. The below example shows an electronics retailer building three Gemini-powered features: product Q&A, customer message tone classification, and a multi-turn shopping assistant conversation.
It gives the following output,
=== Product Q&A ===
Yes, the Sony WH-1000XM5 supports multipoint Bluetooth connection, allowing
you to connect to two devices simultaneously - for example, a laptop and a
smartphone. You can seamlessly switch audio between them. This feature is
enabled by default and can be configured in the Sony Headphones Connect app.
Finish reason: FinishReason.STOP
It gives the following output,
[POSITIVE] I love my new laptop, the screen is gorgeous and battery last...
[NEGATIVE] This is absolutely terrible. Third time I am calling and nobody...
[NEUTRAL ] Hi, what time does the Andheri branch close on Saturdays?
[MIXED ] The delivery was fast but the box was slightly dented. Product...
=== Shopping Assistant Chat ===
Customer: I need a good pair of wireless earbuds
Gemini: I would love to help you find the perfect earbuds! To recommend
the best option, could you tell me: What will you mainly use them
for - music, calls, gym, or commuting? And do you have a budget range?
Customer: Mainly for gym workouts, budget around Rs 5000
Gemini: For gym workouts at Rs 5000, I would recommend looking at the
boAt Airdopes 141 or JBL Reflect Mini NC. Both offer secure fit,
sweat resistance (IPX4/IPX5), and good battery life for workouts.
The JBL adds active noise cancellation which is great for focus
during exercise. Would you like to compare them in detail?
# chat.send_message() automatically maintains conversation history
# Gemini remembered "gym workouts" when answering the budget follow-up
Gemini model selection guide: use gemini-2.0-flash for the vast majority of business tasks - it is fast (under 1 second for short responses), affordable, and handles Q&A, classification, summarisation, and multi-turn chat very well. Use gemini-2.5-pro when you need deep reasoning: complex document analysis, multi-step problem solving, or tasks where output quality matters more than speed. Use gemini-2.0-flash-lite for very high volume simple tasks like single-label classification or short extraction where cost per call is the primary concern. The free tier for Gemini 2.0 Flash offers 15 requests per minute and 1 million tokens per day, making it genuinely free for prototyping and small business use.
|
|