/ai-and-reasoning:invoking-geminifrom ai-and-reasoning
Invokes Google Gemini models for image generation, text-to-speech narration, structured JSON output, and multi-modal tasks. Useful when Gemini offers advantages over Claude for cost-effective parallel processing or Google-specific features.
Ships in ai-and-reasoning. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Delegate tasks to Google's Gemini models when they offer advantages over Claude.
Image generation:
Speech (TTS):
Structured outputs:
Cost optimization:
Multi-modal tasks:
uv pip install requests pydantic
Credentials — Option A (recommended): Cloudflare AI Gateway
Source /mnt/project/proxy.env with CF_ACCOUNT_ID, CF_GATEWAY_ID, CF_API_TOKEN.
Requests route through Cloudflare AI Gateway, bypassing IP blocks. Google API key stored in gateway via BYOK.
Credentials — Option B: Direct Google API
If no proxy.env, falls back to direct: GOOGLE_API_KEY.txt or API_CREDENTIALS.json.
Generate images using Gemini's native image models. This is the primary way to create illustrations, blog headers, diagrams, and visual content.
import sys
sys.path.append('/mnt/skills/user/invoking-gemini/scripts')
from gemini_client import generate_image
# One call — returns {"path": "...", "caption": "..."} or None
result = generate_image("A watercolor painting of a mountain lake at sunset")
print(result["path"]) # /mnt/user-data/outputs/gemini_image_1740000000.png
generate_image(
prompt: str, # The image description
output_path: str = None, # Auto-generates if omitted
model: str = "nano-banana-2.1", # Default: fast. Use "image-pro" for quality
temperature: float = 0.7, # 0.5-0.7 for diagrams, 0.7-0.8 for illustrations
) -> dict | None
# Returns: {"path": "/mnt/user-data/outputs/gemini_image_*.png", "caption": str|None}
# Returns None on failure
| Alias | Model | Best For | Cost/image |
|---|---|---|---|
"nano-banana-2.1" or "image" | gemini-nano-banana-2.1 | Fast iteration, drafts, text rendering (default) | $0.034 (1K) – $0.113 (4K) |
"nano-banana-2" | gemini-3.1-flash-image | Previous version of the default; use only to reproduce earlier results | $0.067 (1K) |
"nano-banana-2-lite" | gemini-3.1-flash-lite-image | Lowest latency, and 6x cheaper than the default on text and reference-image input; same 1K image price | $0.034 (1K) |
"image-pro" or "nano-banana-pro" | gemini-3-pro-image | Highest fidelity, published content | $0.134 (1K/2K) |
import sys
sys.path.append('/mnt/skills/user/invoking-gemini/scripts')
from gemini_client import generate_image
# 1. Compose prompt with style prefix + subject
style_prefix = (
"Style: Risograph-inspired editorial illustration. "
"Visible halftone dot texture and slight color misregistration between layers. "
"Limited ink palette: deep indigo, warm coral, and sage green on off-white paper. "
"Layered transparency where colors overlap creates rich secondary tones. "
"Modern and professional — the aesthetic of an indie design studio, not a fantasy novel. "
"Generous whitespace. No photorealism, no glow effects, no cyberpunk. No text or labels."
)
subject = "A raven perched on a stack of books, observing a network graph"
prompt = f"{style_prefix}\n\nSubject: {subject}. Wide landscape format, suitable as a blog header."
# 2. Generate (use image-pro for published content)
result = generate_image(prompt, model="image-pro", temperature=0.75)
if result:
print(f"Saved: {result['path']}")
# 3. Present to user
# present_files([result["path"]])
result = generate_image(
"A logo for a coffee shop called 'Bean There'",
output_path="/mnt/user-data/outputs/coffee_logo.png"
)
Gemini 3.8 Flash TTS and Flash-Lite TTS went GA on 2026-09-23. Output is WAV, 24 kHz mono 16-bit, SynthID-watermarked.
from gemini_client import generate_speech, design_voice, list_voices
r = generate_speech("Odin kept two ravens. <short pause> Huginn was thought.",
output_path="/tmp/line.wav", voice="Algenib",
style="quiet and dry, unhurried")
# {'path': '/tmp/line.wav', 'seconds': 4.2, 'audio_tokens': 135} or None
v = design_voice("A low, dry, quietly amused male voice with a faint rasp. "
"Soft southern British accent.", "narrator", gender="male",
language_code="en-GB") # {'id': 'voice_...', 'sample_path': ...}
generate_speech("...", voice=v["id"])
lows = list_voices(gender="male", pitch="low") # library of 2,089 prebuilt voices
Charon, Kore, Algenib "gravelly",
Enceladus "breathy", ...) plus 2,059 persona voices with ids like
en-gb-storyteller-4. list_voices() returns accent, pitch, gender and a
description for each; the accent filter needs the exact string ("Winchester
English"), so filter accents on the returned field.style= (a speech_metadata annotation). Do not prefix the
text with "Style: ..." — the 3.8 models read the prefix aloud, and
systemInstruction is rejected. Inline events go in the text: <laugh>,
<sigh>, <breath>, <short pause>; CAPITALS stress a word.medium.en) and a retake.import sys
sys.path.append('/mnt/skills/user/invoking-gemini/scripts')
from gemini_client import invoke_gemini
response = invoke_gemini(
prompt="Explain quantum computing in 3 bullet points",
model="flash", # gemini-4-hydrogen (default)
)
print(response)
Use Pydantic models for guaranteed JSON Schema compliance:
from gemini_client import invoke_with_structured_output
from pydantic import BaseModel, Field
class BookAnalysis(BaseModel):
title: str
genre: str = Field(description="Primary genre")
key_themes: list[str] = Field(max_length=5)
rating: int = Field(ge=1, le=5)
result = invoke_with_structured_output(
prompt="Analyze the book '1984' by George Orwell",
pydantic_model=BookAnalysis
)
print(result.title) # "1984"
Nested models are supported. Gemini's responseSchema rejects $ref/$defs,
which pydantic emits for every nested model, so the client inlines them before
sending:
class Finding(BaseModel):
claim: str
confidence: Literal["high", "medium", "low"]
note: str | None = None
class Analysis(BaseModel):
findings: list[Finding] # nested — inlined for you
gaps: list[str]
Budget output generously. Thinking tokens count against max_output_tokens
(default 32768). Too low and the JSON truncates mid-object, which surfaces as a
pydantic parse error rather than a length error — the client now detects
finishReason=MAX_TOKENS and says so explicitly.
from gemini_client import invoke_parallel
results = invoke_parallel(
prompts=["Summarize Hamlet", "Summarize Macbeth", "Summarize Othello"],
model="lite", # gemini-3.5-flash-lite — cheap/fast tier for batch
)
The current generation is Gemini 4 (Argon 2026-10-13, Carbon 2026-11-10,
Hydrogen 2026-11-12, Neon 2026-11-18). gemini-4-hydrogen is the default and
the flash alias, following Google's routing guide (ai.google.dev/gemini-api/docs/choosing-a-model): Hydrogen for everyday
work, Neon for harder high-frequency work, Carbon for the hardest problems,
3.5 Flash-Lite for bulk text.
No Gemini 4 model is called "Pro", and this skill does not use the old
gemini-3.1-pro-preview: it costs several times as much as Hydrogen for less
benefit on coding and agentic tasks. The pro alias therefore resolves to
Hydrogen, and "maximum reasoning" means thinking_level='xhigh' on Hydrogen. Neon and Carbon are not the default because they cost more (output price:
Neon 2x Hydrogen; Carbon 1.3x, rising to 2.7x on 2026-12-01). Ask for them by
name when a task needs the extra reasoning.
Older model IDs and aliases (listed in references/models.md) are rewritten to a current model, with a note on stderr.
| Model | Alias | Input/1M | Output/1M | Thinking levels (default) | Notes |
|---|---|---|---|---|---|
| gemini-4-hydrogen | flash, pro, hydrogen | $1.50 | $7.50 | low, medium, high (default), xhigh | Default. Released 2026-11-12. Fast, has a free tier. Google reports >5x fewer fabricated claims than 3.8 Flash. |
| gemini-4-neon | neon | $3.00 | $15.00 | low, medium, high (default), xhigh | Released 2026-11-18. Between Hydrogen and Carbon: deeper reasoning than Hydrogen, faster than Carbon. Paid tier only. |
| gemini-4-carbon | carbon | $2.00 → $4.00 | $10.00 → $20.00 | low, medium (default), high | Released 2026-11-10. Strongest reasoning; for hard debugging, architecture, proofs, security. Price doubles on 2026-12-01. Rejects xhigh. |
| gemini-4-argon | argon | $2.00 → $4.00 | $10.00 → $20.00 | low, medium, high | Released 2026-10-13. Reasoning close to Carbon with fewer tokens per turn, same price. Rejects xhigh. |
| gemini-3.8-flash | flash-3.8 | $0.75 → $1.50 | $3.75 → $7.50 | low, medium (default), high | Previous-generation Flash, for callers that need to stay on it. Nothing falls back to it automatically. Intro price runs through 2026-12-31. |
| gemini-3.5-flash-lite | lite | $0.30 | $2.50 | minimal (default), low, medium, high | Bulk tier. Lowest-cost general model; only text model here that accepts minimal. |
All Gemini 4 models: 1M unified context, 64K default output (up to 1M with long
decode), implicit caching only. → marks Carbon/Argon's introductory price
through 2026-11-30 and 3.8 Flash's through 2026-12-31. Output prices include
thinking tokens. Google's Batch API is half of standard price and long decode
extends output to 1M tokens; this client exposes neither.
| Model | Alias | Input/1M | Per Image |
|---|---|---|---|
| gemini-nano-banana-2.1 | image, nano-banana-2.1 | $1.50 (text/image input) | $0.034 (1K) / $0.050 (2K) / $0.113 (4K) |
| gemini-3.1-flash-image | nano-banana-2 | $0.50 | $0.067 (1K) |
| gemini-3.1-flash-lite-image | nano-banana-2-lite | $0.25 | $0.034 (1K) |
| gemini-3-pro-image | image-pro, nano-banana-pro | $2.00 | $0.134 (1K/2K) |
"Input/1M" is the price of the prompt and any reference images. The per-image price is set by image output tokens ($30/M on the 2.1 and Lite models), so a model with a higher input price can still cost less per image. Both tables describe the same models; the first is for choosing, this one for pricing.
| Model | Alias | Input/1M | Output/1M (audio) | Notes |
|---|---|---|---|---|
| gemini-3.8-flash-tts | tts | $0.50 → $1.00 | $9.00 → $18.00 | GA 2026-09-23. Expressive, 130 languages, 2 speakers. Use generate_speech(), not invoke_gemini(). |
| gemini-3.8-flash-lite-tts | tts-lite | $0.50 → $1.00 | $6.00 → $12.00 | GA 2026-09-23. Bulk / read-aloud, 101 languages. Replaces gemini-3.1-flash-tts-preview ($1 / $20). |
Speech aliases live in SPEECH_ALIASES, not MODEL_ALIASES, so a text call can
never resolve to an audio model.
See references/models.md for full details.
Gemini 3.x and 4 models reason before responding. Set it with the string
thinking_level ∈ {minimal, low, medium, high, xhigh} (integer
thinking_budget is not supported). Defaults: high on Hydrogen and Neon, medium on
Carbon, Argon and 3.8 Flash, minimal on 3.5 Flash-Lite. A model that thinks
by default will silently spend output tokens on reasoning (symptom: empty
response with finishReason=MAX_TOKENS), so budget max_output_tokens
generously or lower the level.
Only lite accepts minimal. Every Gemini 4 model and 3.8 Flash return
HTTP 400 (Thinking level MINIMAL is not supported for this model), so low is
their floor. Carbon and Argon also reject xhigh. The client downgrades
minimal to low and xhigh to high on those models and prints a note to
stderr, so a request never fails on this (verified live 2026-11-20). For a true
no-thinking pass, use lite.
response = invoke_gemini(
prompt="Transcribe this image.",
model="lite", # only lite takes 'minimal'
image_path="/tmp/screenshot.png",
max_output_tokens=4000,
thinking_level="minimal", # don't burn output budget on reasoning
)
response = invoke_gemini(prompt="...", model="flash")
if response is None:
print("API call failed — check credentials")
result = generate_image("...")
if result is None:
print("Image generation failed — check credentials or try again")
Common issues: Missing API key → see Setup. Rate limit → auto-retries with backoff. Network error → returns None.
response = invoke_gemini(
prompt="Write a haiku",
model="flash", # gemini-4-hydrogen
temperature=0.9,
max_output_tokens=200,
top_p=0.95,
thinking_level="low", # Hydrogen thinks at "high" by default; "low" keeps the 200-token budget for the answer
)
from pydantic import BaseModel
from gemini_client import invoke_with_structured_output
class ImageDescription(BaseModel):
objects: list[str]
scene: str
colors: list[str]
result = invoke_with_structured_output(
prompt="Describe this image",
pydantic_model=ImageDescription,
image_path="/mnt/user-data/uploads/photo.jpg"
)
See references/advanced.md for more patterns.
"No credentials configured": Create /mnt/project/proxy.env with CF credentials, or add GOOGLE_API_KEY.txt.
CF Gateway 401/403: Verify CF_API_TOKEN has AI Gateway permissions. If not using BYOK, add GOOGLE_API_KEY to proxy.env.
Import errors: uv pip install requests pydantic
Image generation returns None: Check credentials. If persistent, try model="nano-banana-2" (more reliable than image-pro). Check for content policy blocks in error output.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub oaustegard/claude-skills --plugin ai-and-reasoning20 skills in this plugin
/agent-routingDecide which model, effort level, and cascade shape each subagent gets, and how to keep improvement loops safe (evaluator-as-selector, stop on regression). Routes on measured cost-per-completed-task rather than per-token price, because a tier's token count varies more by task shape than price varies across tiers. Covers per-model effort semantics, the concision lever, cascade preconditions, context handoff, and watching a subagent fan-out live. Use when choosing a subagent's model or effort, when choosing how to escalate a failed attempt, or when asked which model or effort a task should get. Grounded in a 2026-07 calibration, a 2026-08 coding-cost study, a 2026-09 seeded-bug repair battery, a 2026-10 Haiku 5.5 ladder priced per spawn, a 2026-10 retry-versus-escalation ladder on 295 SWE-bench Verified tasks, and a 2026-11 Haiku-swarm-versus-Sonnet-loop search at equal spend; Managed Agents API specifics are operational, not calibrated./challengingCross-context adversarial review for deliverables before shipping. Use when producing blog posts, technical recommendations, analysis briefs, code, or any artifact where accuracy matters more than speed. Triggers on "challenge this", "review before shipping", "adversarial pass", "stress test this"./convening-expertsConvenes expert panels for problem-solving. Use when user mentions panel, experts, multiple perspectives, MECE, DMAIC, RAPID, Six Sigma, root cause analysis, strategic decisions, process improvement, or asks for philosophers/ancients (Socratic, Aristotelian, Stoic method experts)./deciding-with-confidenceRoutes, triages, flags and rates a piece of text with a probability for every option: which department or queue a ticket goes to, which intent a message expresses, whether a yes/no condition holds (is this tool call grounded, should the agent ask first, is the customer angry), and how severe or urgent it is on a rubric, each with a calibrated confidence. Runs Claude Haiku in the request and response shapes of OpenAI's Decisions API, or of TypeSafe's System One API (Jev's), for when no purpose-built decision model is at hand. Use for "route this ticket", "triage these", "classify with a confidence", "give me a probability that", "rate the severity", "score against this rubric", guardrail checks before a tool call, "a Decisions API without OpenAI", or a stand-in for Jev./delegating-with-contextDelegates work to a subagent or spawned session by writing only the task, while a PreToolUse hook pages the parent transcript through Jev and appends the chunks that task needs. Use before writing any Agent tool prompt or create_session prompt, and when asked to delegate this, hand this off, use a subagent, spawn an agent, run agents in parallel, or brief a subagent on what we have done so far./dispatching-subagentsChooses how to launch subagents from Claude Code (the Agent tool, a Workflow script, or headless claude -p children) and runs a headless fan-out from one background command. Use for "fan this out to 50 agents", "run these tasks in parallel", "launch subagents for each file", "should I spawn agents or write a workflow", "batch this through Haiku", "run claude -p in parallel", "dispatch a task list without the launches eating my context", or before any launch of more than a handful of subagents, where the launching itself is the cost. Covers the parent-turn cost of each mechanism, concurrency ceilings, what context and tools each child gets, effort control, output contracts, a cost ledger, and resume after interruption.Other plugins' skills for the same job