[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7165KYRXZX84G4FRKJNQJFR":3,"skill-same:01M7165KYRXZX84G4FRKJNQJFR":75},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":28,"publishedAt":49,"linkOnly":50,"markdownContent":51,"markdownBody":52,"frontMatter":53,"refName":55,"commitSha":56,"skillDirectory":57,"forksCount":14,"repositoryHtmlUrl":58,"repositoryHomepageUrl":6,"ownerHtmlUrl":59,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":60,"install":61,"resources":74},"01M7165KYRXZX84G4FRKJNQJFR","gemini-api-integration",null,"Use when integrating Google Gemini API into projects. Covers model selection, multimodal inputs, streaming, function calling, and production best practices.","sapsapshen\u002Fai-memory-router","sapsapshen","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F20347959?v=4","01M6XDQEF1DP50DKF37H81J3J5","shenmian","01M6XDQEJPE41Y3DT2763X8ZJN",0,"MIT","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fgemini-api-integration\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48],"gemini","gemini api","integration","api","gemini api integration","api integration","2026","safe","when","google gemini api","calling","selection","community","use","function calling","model","projects","streaming","best practices","model selection","2026-11-10 10:12:30",false,"---\nname: gemini-api-integration\ndescription: \"Use when integrating Google Gemini API into projects. Covers model selection, multimodal inputs, streaming, function calling, and production best practices.\"\nrisk: safe\nsource: community\ndate_added: \"2026-03-04\"\n---\n\n# Gemini API Integration\n\n## Overview\n\nThis skill guides AI agents through integrating Google Gemini API into applications — from basic text generation to advanced multimodal, function calling, and streaming use cases. It covers the full Gemini SDK lifecycle with production-grade patterns.\n\n## When to Use This Skill\n\n- Use when setting up Gemini API for the first time in a Node.js, Python, or browser project\n- Use when implementing multimodal inputs (text + image\u002Faudio\u002Fvideo)\n- Use when adding streaming responses to improve perceived latency\n- Use when implementing function calling \u002F tool use with Gemini\n- Use when optimizing model selection (Flash vs Pro vs Ultra) for cost and performance\n- Use when debugging Gemini API errors, rate limits, or quota issues\n\n## Step-by-Step Guide\n\n### 1. Installation & Setup\n\n**Node.js \u002F TypeScript:**\n```bash\nnpm install @google\u002Fgenerative-ai\n```\n\n**Python:**\n```bash\npip install google-generativeai\n```\n\nSet your API key securely:\n```bash\nexport GEMINI_API_KEY=\"your-api-key-here\"\n```\n\n### 2. Basic Text Generation\n\n**Node.js:**\n```javascript\nimport { GoogleGenerativeAI } from \"@google\u002Fgenerative-ai\";\n\nconst genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);\nconst model = genAI.getGenerativeModel({ model: \"gemini-1.5-flash\" });\n\nconst result = await model.generateContent(\"Explain async\u002Fawait in JavaScript\");\nconsole.log(result.response.text());\n```\n\n**Python:**\n```python\nimport google.generativeai as genai\nimport os\n\ngenai.configure(api_key=os.environ[\"GEMINI_API_KEY\"])\nmodel = genai.GenerativeModel(\"gemini-1.5-flash\")\n\nresponse = model.generate_content(\"Explain async\u002Fawait in JavaScript\")\nprint(response.text)\n```\n\n### 3. Streaming Responses\n\n```javascript\nconst result = await model.generateContentStream(\"Write a detailed blog post about AI\");\n\nfor await (const chunk of result.stream) {\n  process.stdout.write(chunk.text());\n}\n```\n\n### 4. Multimodal Input (Text + Image)\n\n```javascript\nimport fs from \"fs\";\n\nconst imageData = fs.readFileSync(\"screenshot.png\");\nconst imagePart = {\n  inlineData: {\n    data: imageData.toString(\"base64\"),\n    mimeType: \"image\u002Fpng\",\n  },\n};\n\nconst result = await model.generateContent([\"Describe this image:\", imagePart]);\nconsole.log(result.response.text());\n```\n\n### 5. Function Calling \u002F Tool Use\n\n```javascript\nconst tools = [{\n  functionDeclarations: [{\n    name: \"get_weather\",\n    description: \"Get current weather for a city\",\n    parameters: {\n      type: \"OBJECT\",\n      properties: {\n        city: { type: \"STRING\", description: \"City name\" },\n      },\n      required: [\"city\"],\n    },\n  }],\n}];\n\nconst model = genAI.getGenerativeModel({ model: \"gemini-1.5-pro\", tools });\nconst result = await model.generateContent(\"What's the weather in Mumbai?\");\n\nconst call = result.response.functionCalls()?.[0];\nif (call) {\n  \u002F\u002F Execute the actual function\n  const weatherData = await getWeather(call.args.city);\n  \u002F\u002F Send result back to model\n}\n```\n\n### 6. Multi-turn Chat\n\n```javascript\nconst chat = model.startChat({\n  history: [\n    { role: \"user\", parts: [{ text: \"You are a helpful coding assistant.\" }] },\n    { role: \"model\", parts: [{ text: \"Sure! I'm ready to help with code.\" }] },\n  ],\n});\n\nconst response = await chat.sendMessage(\"How do I reverse a string in Python?\");\nconsole.log(response.response.text());\n```\n\n### 7. Model Selection Guide\n\n| Model | Best For | Speed | Cost |\n|-------|----------|-------|------|\n| `gemini-1.5-flash` | High-throughput, cost-sensitive tasks | Fast | Low |\n| `gemini-1.5-pro` | Complex reasoning, long context | Medium | Medium |\n| `gemini-2.0-flash` | Latest fast model, multimodal | Very Fast | Low |\n| `gemini-2.0-pro` | Most capable, advanced tasks | Slow | High |\n\n## Best Practices\n\n- ✅ **Do:** Use `gemini-1.5-flash` for most tasks — it's fast and cost-effective\n- ✅ **Do:** Always stream responses for user-facing chat UIs to reduce perceived latency\n- ✅ **Do:** Store API keys in environment variables, never hard-code them\n- ✅ **Do:** Implement exponential backoff for rate limit (429) errors\n- ✅ **Do:** Use `systemInstruction` to set persistent model behavior\n- ❌ **Don't:** Use `gemini-pro` for simple tasks — Flash is cheaper and faster\n- ❌ **Don't:** Send large base64 images inline for files > 20MB — use File API instead\n- ❌ **Don't:** Ignore safety ratings in responses for production apps\n\n## Error Handling\n\n```javascript\ntry {\n  const result = await model.generateContent(prompt);\n  return result.response.text();\n} catch (error) {\n  if (error.status === 429) {\n    \u002F\u002F Rate limited — wait and retry with exponential backoff\n    await new Promise(r => setTimeout(r, 2 ** retryCount * 1000));\n  } else if (error.status === 400) {\n    \u002F\u002F Invalid request — check prompt or parameters\n    console.error(\"Invalid request:\", error.message);\n  } else {\n    throw error;\n  }\n}\n```\n\n## Troubleshooting\n\n**Problem:** `API_KEY_INVALID` error\n**Solution:** Ensure `GEMINI_API_KEY` environment variable is set and the key is active in Google AI Studio.\n\n**Problem:** Response blocked by safety filters\n**Solution:** Check `result.response.promptFeedback.blockReason` and adjust your prompt or safety settings.\n\n**Problem:** Slow response times\n**Solution:** Switch to `gemini-1.5-flash` and enable streaming. Consider caching repeated prompts.\n\n**Problem:** `RESOURCE_EXHAUSTED` (quota exceeded)\n**Solution:** Check your quota in Google Cloud Console. Implement request queuing and exponential backoff.\n","# Gemini API Integration\n\n## Overview\n\nThis skill guides AI agents through integrating Google Gemini API into applications — from basic text generation to advanced multimodal, function calling, and streaming use cases. It covers the full Gemini SDK lifecycle with production-grade patterns.\n\n## When to Use This Skill\n\n- Use when setting up Gemini API for the first time in a Node.js, Python, or browser project\n- Use when implementing multimodal inputs (text + image\u002Faudio\u002Fvideo)\n- Use when adding streaming responses to improve perceived latency\n- Use when implementing function calling \u002F tool use with Gemini\n- Use when optimizing model selection (Flash vs Pro vs Ultra) for cost and performance\n- Use when debugging Gemini API errors, rate limits, or quota issues\n\n## Step-by-Step Guide\n\n### 1. Installation & Setup\n\n**Node.js \u002F TypeScript:**\n```bash\nnpm install @google\u002Fgenerative-ai\n```\n\n**Python:**\n```bash\npip install google-generativeai\n```\n\nSet your API key securely:\n```bash\nexport GEMINI_API_KEY=\"your-api-key-here\"\n```\n\n### 2. Basic Text Generation\n\n**Node.js:**\n```javascript\nimport { GoogleGenerativeAI } from \"@google\u002Fgenerative-ai\";\n\nconst genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);\nconst model = genAI.getGenerativeModel({ model: \"gemini-1.5-flash\" });\n\nconst result = await model.generateContent(\"Explain async\u002Fawait in JavaScript\");\nconsole.log(result.response.text());\n```\n\n**Python:**\n```python\nimport google.generativeai as genai\nimport os\n\ngenai.configure(api_key=os.environ[\"GEMINI_API_KEY\"])\nmodel = genai.GenerativeModel(\"gemini-1.5-flash\")\n\nresponse = model.generate_content(\"Explain async\u002Fawait in JavaScript\")\nprint(response.text)\n```\n\n### 3. Streaming Responses\n\n```javascript\nconst result = await model.generateContentStream(\"Write a detailed blog post about AI\");\n\nfor await (const chunk of result.stream) {\n  process.stdout.write(chunk.text());\n}\n```\n\n### 4. Multimodal Input (Text + Image)\n\n```javascript\nimport fs from \"fs\";\n\nconst imageData = fs.readFileSync(\"screenshot.png\");\nconst imagePart = {\n  inlineData: {\n    data: imageData.toString(\"base64\"),\n    mimeType: \"image\u002Fpng\",\n  },\n};\n\nconst result = await model.generateContent([\"Describe this image:\", imagePart]);\nconsole.log(result.response.text());\n```\n\n### 5. Function Calling \u002F Tool Use\n\n```javascript\nconst tools = [{\n  functionDeclarations: [{\n    name: \"get_weather\",\n    description: \"Get current weather for a city\",\n    parameters: {\n      type: \"OBJECT\",\n      properties: {\n        city: { type: \"STRING\", description: \"City name\" },\n      },\n      required: [\"city\"],\n    },\n  }],\n}];\n\nconst model = genAI.getGenerativeModel({ model: \"gemini-1.5-pro\", tools });\nconst result = await model.generateContent(\"What's the weather in Mumbai?\");\n\nconst call = result.response.functionCalls()?.[0];\nif (call) {\n  \u002F\u002F Execute the actual function\n  const weatherData = await getWeather(call.args.city);\n  \u002F\u002F Send result back to model\n}\n```\n\n### 6. Multi-turn Chat\n\n```javascript\nconst chat = model.startChat({\n  history: [\n    { role: \"user\", parts: [{ text: \"You are a helpful coding assistant.\" }] },\n    { role: \"model\", parts: [{ text: \"Sure! I'm ready to help with code.\" }] },\n  ],\n});\n\nconst response = await chat.sendMessage(\"How do I reverse a string in Python?\");\nconsole.log(response.response.text());\n```\n\n### 7. Model Selection Guide\n\n| Model | Best For | Speed | Cost |\n|-------|----------|-------|------|\n| `gemini-1.5-flash` | High-throughput, cost-sensitive tasks | Fast | Low |\n| `gemini-1.5-pro` | Complex reasoning, long context | Medium | Medium |\n| `gemini-2.0-flash` | Latest fast model, multimodal | Very Fast | Low |\n| `gemini-2.0-pro` | Most capable, advanced tasks | Slow | High |\n\n## Best Practices\n\n- ✅ **Do:** Use `gemini-1.5-flash` for most tasks — it's fast and cost-effective\n- ✅ **Do:** Always stream responses for user-facing chat UIs to reduce perceived latency\n- ✅ **Do:** Store API keys in environment variables, never hard-code them\n- ✅ **Do:** Implement exponential backoff for rate limit (429) errors\n- ✅ **Do:** Use `systemInstruction` to set persistent model behavior\n- ❌ **Don't:** Use `gemini-pro` for simple tasks — Flash is cheaper and faster\n- ❌ **Don't:** Send large base64 images inline for files > 20MB — use File API instead\n- ❌ **Don't:** Ignore safety ratings in responses for production apps\n\n## Error Handling\n\n```javascript\ntry {\n  const result = await model.generateContent(prompt);\n  return result.response.text();\n} catch (error) {\n  if (error.status === 429) {\n    \u002F\u002F Rate limited — wait and retry with exponential backoff\n    await new Promise(r => setTimeout(r, 2 ** retryCount * 1000));\n  } else if (error.status === 400) {\n    \u002F\u002F Invalid request — check prompt or parameters\n    console.error(\"Invalid request:\", error.message);\n  } else {\n    throw error;\n  }\n}\n```\n\n## Troubleshooting\n\n**Problem:** `API_KEY_INVALID` error\n**Solution:** Ensure `GEMINI_API_KEY` environment variable is set and the key is active in Google AI Studio.\n\n**Problem:** Response blocked by safety filters\n**Solution:** Check `result.response.promptFeedback.blockReason` and adjust your prompt or safety settings.\n\n**Problem:** Slow response times\n**Solution:** Switch to `gemini-1.5-flash` and enable streaming. Consider caching repeated prompts.\n\n**Problem:** `RESOURCE_EXHAUSTED` (quota exceeded)\n**Solution:** Check your quota in Google Cloud Console. Implement request queuing and exponential backoff.\n",{"name":5,"risk":36,"source":41,"date_added":54,"description":7},"2026-03-04","main","7a38d8e7073e61c16eda85681cb32fb68a8657a5","skills-store\u002Fcursor\u002Fgemini-api-integration","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router","https:\u002F\u002Fgithub.com\u002Fsapsapshen","2026-04-14 21:12:12",{"source":8,"skillName":5,"commands":62,"prompt":72,"zipAvailable":73},[63,66,69],{"tool":64,"command":65},"npx","npx skills add sapsapshen\u002Fai-memory-router --skill gemini-api-integration",{"tool":67,"command":68},"bunx","bunx skills add sapsapshen\u002Fai-memory-router --skill gemini-api-integration",{"tool":70,"command":71},"pnpm","pnpm dlx skills add sapsapshen\u002Fai-memory-router --skill gemini-api-integration","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fgemini-api-integration\u002FSKILL.md",true,[],[76,86,93,101,107,115],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":80,"licenseFileUrl":81,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":85},"01M72R8PZX1ABFHJGTYPA4CAF1","webapp-testing","To test local web applications, write native Python Playwright scripts.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fwebapp-testing\u002FSKILL.md",[],[],"2026-11-10 22:39:42",{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":85},"01M72QG37MMZNDY7X7GXPAK5W6","python-packaging","Comprehensive guide to creating, structuring, and distributing Python packages using modern packaging tools, pyproject.toml, and publishing to PyPI.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fpython-packaging\u002FSKILL.md",[],[],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":80,"licenseFileUrl":97,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":85},"01M72NXR0QMP9G46TW6A2DH59C","canvas-design","These are instructions for creating design philosophies - aesthetic movements that are then EXPRESSED VISUALLY. Output only .md files, .pdf files, and .png files.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fcanvas-design\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fcanvas-design\u002FSKILL.md",[],[],{"skillNo":102,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":80,"licenseFileUrl":103,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":85},"01M72N55TK3EEQ4QK4AWDC2KZS","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":80,"licenseFileUrl":111,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":85},"01M72MTWC150CFAP4Y5GSNKF80","slack-gif-creator","A toolkit providing utilities and knowledge for creating animated GIFs optimized for Slack.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fslack-gif-creator\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fslack-gif-creator\u002FSKILL.md",[],[],{"skillNo":116,"name":117,"nameZh":6,"description":118,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":80,"licenseFileUrl":119,"sourceHtmlUrl":120,"categories":121,"keywords":122,"publishedAt":85},"01M72KPT3VVNSP88MNAY466TZT","frontend-design","You are a frontend designer-engineer, not a layout generator.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Ffrontend-design\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Ffrontend-design\u002FSKILL.md",[],[]]