← ClaudeAtlas

gemini-best-practiceslisted

Review and fix Gemini API usage against Google's official best practices. Use when modifying src/core/gemini.ts, adding new API calls, or auditing Gemini integration quality.
takeshy/obsidian-llm-hub · ★ 14 · AI & Automation · score 84
Install: claude install-skill takeshy/obsidian-llm-hub
# Gemini API Best Practices When reviewing or modifying Gemini API integration code, ensure compliance with Google's official best practices from `google-gemini/gemini-skills`. ## SDK and Package - **Correct SDK**: `@google/genai` (npm) - **NEVER use deprecated**: `@google/generative-ai` (old package) - Prefer environment variables for API keys over hard-coding ## Safety Settings All API calls (`generateContent`, `generateContentStream`, `chats.create`) MUST include `safetySettings` in the config: ```typescript import { HarmCategory, HarmBlockThreshold, type SafetySetting } from "@google/genai"; const DEFAULT_SAFETY_SETTINGS: SafetySetting[] = [ { category: HarmCategory.HARM_CATEGORY_HARASSMENT, threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE }, { category: HarmCategory.HARM_CATEGORY_HATE_SPEECH, threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE }, { category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE }, { category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE }, ]; ``` ## Response Validation (finishReason) Always check `finishReason` on response candidates: - `SAFETY` - Response blocked by safety filters; inform user to rephrase - `RECITATION` - Blocked due to potential copyrighted content recitation - `MAX_TOKENS` - Output truncated; consider informing user - `STOP` - Normal completion ```typescript import { FinishReason } from "@google/g