gemini-api
Skill1 starsChanged 5 days agoUnlicenseView on GitHub
Practical guide and zero-dependency recipes for calling Google's Gemini API directly (HTTP/REST, Python urllib, curl). Use when generating text, structured JSON, running batch LLM calls, configuring models, or setting up GEMINI_API_KEY without needing skill-opt.
- Reads credentials
- Sends data out
9 other projects use a version of this.
Adopted by
Most recently taken up by
- oivanfelipe/claude-skillstheir own version, first seen Nov 8, 2026
- sanjay3290/ai-skillstheir own version, first seen Nov 8, 2026
- ManatoYamashita/skillstheir own version, first seen Nov 1, 2026
- olaitanojo/skillstheir own version, first seen Oct 17, 2026
- workatustadarshajay/CareLoop-AItheir own version, first seen Oct 9, 2026
- ya-luotao/skillstheir own version, first seen Oct 9, 2026
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 9
- google/skills★ 24ksame name
- sanjay3290/ai-skills★ 452same name
- jmxt3/gitscape.ai★ 33same name
- Adhamxon/claude-code-skills★ 2same name
- ManatoYamashita/skills★ 1same name
- olaitanojo/skills★ 1same name
- ya-luotao/skills★ 1same name
- oivanfelipe/claude-skills★ 0same name
- workatustadarshajay/CareLoop-AI★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository76 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ad-copy-writerSkill
- ae-inspect-describeSkill
- algorithmic-artSkill
- animation-directorSkill
- assembly-guideSkill
- brainstorming-and-ideatingSkill
- brainstorming-research-ideasSkill
- brainstormingSkill
- brief-to-tasksSkill
- canvas-designSkill
- cli-designSkill
- cli-output-hierarchySkill
- commit-messageSkill
- craft-uiSkill
- creative-directorSkill
- design-briefSkill
- design-flowSkill
- design-mock-auditSkill
- design-reviewSkill
- design-system-patternsSkill
- design-tokensSkill
- deslopifySkill
- diagnoseSkill
- diagramming-app-routesSkill
- doc-restructureSkill
- eval-criticSkill
- formatting-open-markdownsSkill
- frontend-designSkill
- frontend-slidesSkill
- gdocs-tab-writerSkill
- gif-creationSkill
- github_repo_researchSkill
- grill-meSkill
- grill-with-docsSkill
- hallmarkSkill
- handoffSkill
- html-presentationSkill
- humanizerSkill
- i-have-adhdSkill
- improve-codebase-architectureSkill
- information-architectureSkill
- install-skill-from-githubSkill
- markdown-output-hierarchySkill
- marketing-psychologySkill
- merge-latestSkill
- modern-web-performanceSkill
- motion-designSkill
- pdf-readerSkill
- pm-brainstormingSkill
- pm-discovery-brainstormSkill
- product-marketingSkill
- prototypeSkill
- pull-requestSkill
- ralph_loopSkill
- react-best-practicesSkill
- review-loopSkill
- sandbox-explainerSkill
- skill-creatorSkill
- skill-optSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
11 rules. 0 are common, 4 are distinctive, and 7 are very specific to this project.
0
Common
Most of the 9 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 15
All requests authenticate via an API key passed in the query parameter ?key=${GEMINI_API_KEY} or header x-goog-api-key.
- Distinctive: line 51
Always prefer these canonical aliases for general text and reasoning tasks.
- Distinctive: line 61
Use these when pinning to specific generation architectures or preview features:
- Distinctive: line 81
When automating API calls, design model selection hierarchically:
- Very specific: line 90
Use this production-grade, self-contained implementation without needing external packages (requests, google-generativeai):
- Very specific: line 195
Run multiple prompts in parallel using concurrent.futures:
- Distinctive: line 222
Test an API key and connectivity from the shell in one line:
- Very specific: line 236
System Instructions Placement: Never put system prompts in contents.
- Very specific: line 237
Always place them in the dedicated top-level system_instruction: {"parts": [{"text": "..."}]} block.
- Very specific: line 239
Key Security: Never commit raw API keys to Git, Fig, Piper, or review CLs.
- Very specific: line 241
Candidate Parsing: Always guard access: res.get("candidates", [])[0].get("content", {}).get("parts", [])[0].get("text", "").
“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Calling the Gemini API
This skill provides direct, zero-dependency recipes and reference patterns for calling Google's Gemini API across Python and the command line.
1. Authentication & Environment
All requests authenticate via an API key passed in the query parameter
?key=${GEMINI_API_KEY} or header x-goog-api-key.
Environment Setup
# Check if key is present
echo "$GEMINI_API_KEY"
# If not set, export in ~/.bashrc or current shell
export GEMINI_API_KEY="AIzaSy..."In Python:
import os
import sys
api_key = os.environ.get("GEMINI_API_KEY", "")
if not api_key:
sys.exit("ERROR: GEMINI_API_KEY environment variable is not set.")2. Models & Capabilities
Endpoint template:
https://generativelanguage.googleapis.com/v1beta/models/{MODEL}:generateContent?key={API_KEY}Preferred First Choices (Auto-Updating Pointers)
Always prefer these canonical aliases for general text and reasoning tasks. They automatically resolve to the latest stable production model snapshots:
| Model Alias | Purpose | Latency / Throughput |
gemini-pro-latest | Complex reasoning, multi-step refactoring, architecture critique, system analysis | Highest quality, medium latency |
gemini-flash-latest | General text generation, code transformation, balanced synthesis | Fast, balanced quality |
gemini-flash-lite-latest | High-volume batch evaluation, rapid classification, scoring, triage | Lowest latency, highest QPS |
Alternative & Fixed Version Models (Alts)
Use these when pinning to specific generation architectures or preview features:
| Model | Classification | Description |
gemini-3.8-flash | Latest Flash generation | Advanced speed-optimized model with expanded context reasoning |
gemini-3.7-flash | Stable Flash generation | High-performance reasoning with low latency |
gemini-3.6-flash | Workhorse Flash | Proven balanced reasoning and code generation |
gemini-3.1-pro-preview | Deep Pro preview | Frontier reasoning for architectural design and complex debugging |
Specialized Image Models (Image Generation & Edits Only)
These models use the standard :generateContent endpoint but return image payloads inside candidates[0].content.parts[].inlineData (image/png or image/jpeg) rather than text:
| Model | Task | Endpoint / Notes |
gemini-3.1-flash-image | Rapid image generation & edits | Fast image synthesis via :generateContent |
gemini-3-pro-image | High-fidelity image generation | Multi-turn visual refinement and detailed asset synthesis |
Dynamic Model Fallback Strategy
When automating API calls, design model selection hierarchically:
- Try
gemini-flash-latest(orgemini-flash-lite-latestfor batch jobs). - Fallback to
gemini-pro-latest. - Fallback to pinned snapshots (
gemini-3.8-flash,gemini-3.7-flash,gemini-3.1-pro-preview).
3. Zero-Dependency Python Helper (Standard Library)
Use this production-grade, self-contained implementation without needing
external packages (requests, google-generativeai):
import json
import os
import time
import urllib.error
import urllib.request
from typing import Any, Dict, List, Optional
def call_gemini(
prompt: str,
system_instruction: Optional[str] = None,
model: str = "gemini-flash-latest",
fallback_models: Optional[List[str]] = None,
temperature: float = 0.2,
max_output_tokens: Optional[int] = None,
json_mode: bool = False,
api_key: Optional[str] = None,
max_retries: int = 3
) -> str:
"""Invokes Gemini API with model fallback and exponential backoff."""
key = api_key or os.environ.get("GEMINI_API_KEY", "")
if not key:
raise ValueError("GEMINI_API_KEY not configured in environment.")
candidate_models = [model] + (fallback_models or [
"gemini-pro-latest",
"gemini-flash-lite-latest",
"gemini-3.8-flash",
"gemini-3.7-flash",
"gemini-3.1-pro-preview"
])
# Payload Construction
payload: Dict[str, Any] = {
"contents": [{"parts": [{"text": prompt}]}],
"generationConfig": {
"temperature": temperature,
}
}
if system_instruction:
payload["system_instruction"] = {
"parts": [{"text": system_instruction}]
}
if max_output_tokens:
payload["generationConfig"]["maxOutputTokens"] = max_output_tokens
if json_mode:
payload["generationConfig"]["responseMimeType"] = "application/json"
data_bytes = json.dumps(payload).encode("utf-8")
for current_model in candidate_models:
url = f"https://generativelanguage.googleapis.com/v1beta/models/{current_model}:generateContent?key={key}"
for attempt in range(1, max_retries + 1):
req = urllib.request.Request(
url,
data=data_bytes,
headers={"Content-Type": "application/json"}
)
try:
with urllib.request.urlopen(req, timeout=60) as resp:
res = json.loads(resp.read().decode("utf-8"))
cands = res.get("candidates", [])
if cands and "content" in cands[0]:
parts = cands[0]["content"].get("parts", [])
if parts and "text" in parts[0]:
return parts[0]["text"].strip()
return ""
except urllib.error.HTTPError as e:
# 404 or 503: model unavailable -> try fallback model
if e.code in (404, 503):
break
# 429: rate limited -> backoff
time.sleep(2 ** attempt)
except Exception:
time.sleep(2 ** attempt)
return ""4. Common Recipes
A. Structured JSON Extraction
schema_prompt = "Extract entities and status from: 'Host db-prod-01 CPU peaked at 98% and failed health check.'"
response_json = call_gemini(
prompt=schema_prompt,
system_instruction="You are an automated triage parser. Output valid JSON matching: {'host': str, 'metric': str, 'status': str}.",
json_mode=True
)
data = json.loads(response_json)
print(data["host"], data["status"])B. High-Throughput Concurrent Batch Calls
Run multiple prompts in parallel using concurrent.futures:
import concurrent.futures
prompts = [
("Prompt 1", "Explain Paxos"),
("Prompt 2", "Explain Raft"),
("Prompt 3", "Explain 2PC")
]
def worker(item):
label, text = item
res = call_gemini(prompt=text, model="gemini-2.5-flash-lite")
return label, res
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as pool:
results = list(pool.map(worker, prompts))
for label, response in results:
print(f"=== {label} ===\n{response[:100]}...\n")5. Quick CLI / Curl Verification
Test an API key and connectivity from the shell in one line:
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent?key=${GEMINI_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"contents":[{"parts":[{"text":"Reply with: API CONNECTION SUCCESSFUL"}]}]}' \
| grep -o '"text": *"[^"]*"'6. Critical Rules & Gotchas
- System Instructions Placement: Never put system prompts in
contents. Always place them in the dedicated top-levelsystem_instruction: {"parts": [{"text": "..."}]}block. - Key Security: Never commit raw API keys to Git, Fig, Piper, or review
CLs. Always read from
os.environ["GEMINI_API_KEY"]. - Candidate Parsing: Always guard access:
res.get("candidates", [])[0].get("content", {}).get("parts", [])[0].get("text", ""). If a response is blocked by safety filters,candidates[0].content.partsmay be empty. CheckfinishReasonif text is blank. - Timeouts: Wrap
urlopenin explicit timeouts (timeout=60or90) to prevent hanging processes on network partitions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

