AI / Google Antigravity Gemini Fundamentals Interview Questions
What are best practices for building production-grade Gemini API applications?
Moving a Gemini prototype to production requires addressing reliability, cost efficiency, safety, and maintainability. These practices apply across model versions and application types.
| Area | Best practice |
|---|---|
| Model selection | Use pinned stable model IDs (e.g. gemini-2.5-flash-001), never -latest in production |
| Cost control | Use Batch API for bulk; enable context caching for repeated prompts; choose right model tier per task |
| Error handling | Exponential backoff for 429 errors; handle 404s (model deprecated); fallback model strategy |
| Safety | Configure appropriate safety thresholds; check block_reason; validate all user inputs |
| Rate limits | Monitor quota in AI Studio; implement client-side rate limiting; use Vertex AI for higher limits |
| Observability | Log all requests and responses with IDs; track token usage; use interaction steps for debugging |
| Testing | Run evals before model upgrades; test edge cases; validate structured output schemas |
| Privacy | Use Vertex AI for regulated data; minimise PII in prompts; understand data retention policy |
# Example production-hardened Gemini call: from google import genai from google.genai import types from google.api_core import exceptions import time, logging logger = logging.getLogger("gemini-app") client = genai.Client() GEMINI_MODEL = "gemini-2.5-flash-001" # PINNED - never use -latest def production_generate(prompt: str, user_id: str) -> str: for attempt in range(4): try: response = client.models.generate_content( model=GEMINI_MODEL, contents=prompt, config=types.GenerateContentConfig( max_output_tokens=2048, # cap output temperature=0.2, # low for predictability safety_settings=[ types.SafetySetting( category="HARM_CATEGORY_DANGEROUS_CONTENT", threshold="BLOCK_MEDIUM_AND_ABOVE" ) ] ) ) if not response.candidates: raise ValueError(f"Blocked: {response.prompt_feedback.block_reason}") logger.info({"user": user_id, "tokens": response.usage_metadata.total_token_count}) return response.text except exceptions.ResourceExhausted: time.sleep(2 ** attempt) raise RuntimeError("Max retries exceeded")
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
