Gemini Text Generation
Generate content using Google's Gemini API through executable scripts with advanced capabilities including system instructions, thinking mode, JSON output, and Google Search grounding.
When to Use This Skill
Use this skill when you need to:
- Generate any type of text content (blogs, emails, code, stories)
- Process images with text descriptions or analysis
- Perform complex reasoning requiring step-by-step thinking
- Get structured JSON outputs for data processing
- Access real-time information via Google Search
- Apply specific personas or behavior patterns
- Combine text generation with other Gemini skills (images, TTS, embeddings)
Available Scripts
scripts/generate.js
Purpose: Full-featured text generation with all Gemini capabilities
When to use:
- Any text generation task
- Multimodal prompts (text + image)
- Complex reasoning requiring thinking mode
- Structured JSON output requirements
- Real-time information needs (grounding)
- Custom system instructions/personas
Key parameters:
| Parameter |
Description |
Example |
prompt |
Text prompt (required) |
"Explain quantum computing" |
--model, -m |
Model to use |
gemini-3-flash-preview |
--system, -s |
System instruction |
"You are a helpful assistant" |
--thinking, -t |
Enable thinking mode |
Flag |
--json, -j |
Force JSON output |
Flag |
--grounding, -g |
Enable Google Search |
Flag |
--image, -i |
Image for multimodal |
photo.png |
--temperature |
Sampling 0.0-2.0 |
0.7 for creative |
--max-tokens |
Output limit |
1000 |
Output: Generated text string, optionally with grounding sources
Workflows
Workflow 1: Basic Text Generation
node scripts/generate.js "Explain quantum computing in simple terms"
- Best for: Simple content creation, explanations, summaries
- Model:
gemini-3-flash-preview (default, fast)
Workflow 2: With System Instruction (Persona)
node scripts/generate.js "How do I read a file in Python?" --system "You are a helpful coding assistant"
- Best for: Domain-specific tasks, expert personas, consistent tone
- Use when: You need specific behavioral constraints
Workflow 3: Complex Reasoning (Thinking Mode)
node scripts/generate.js "Analyze the ethical implications of AI in healthcare" --thinking
- Best for: Complex analysis, step-by-step reasoning, multi-step problems
- Use when: Task requires careful consideration and logical progression
Workflow 4: Structured JSON Output
node scripts/generate.js "Generate a user profile object with name, email, and preferences" --json
- Best for: Data extraction, structured data generation, API responses
- Output: Valid JSON ready for parsing
- Note: Prompt must clearly request JSON structure
Workflow 5: Real-Time Information (Grounding)
node scripts/generate.js "Who won the latest Super Bowl?" --grounding
- Best for: Current events, news, factual information after training cutoff
- Output: Response + grounding sources with citations
- Use when: Accuracy of current information is critical
Workflow 6: Multimodal (Image Analysis)
node scripts/generate.js "Describe what's in this image in detail" --image photo.png
- Best for: Image captioning, visual analysis, image-based Q&A
- Requires: Image file in PNG or JPEG format
- Combines well with: gemini-files for file upload
Workflow 7: Content Creation Pipeline (Batch + Text + TTS)
# 1. Create batch requests (gemini-batch skill)
# 2. Generate content
node scripts/generate.js "Create a 500-word blog post about sustainable energy"
# 3. Convert to audio (gemini-tts skill)
- Best for: High-volume content production, podcasts, audiobooks
Parameters Reference
Model Selection
| Model |
Speed |
Intelligence |
Context |
Best For |
gemini-3-flash-preview |
Fast |
High |
1M |
General use, agentic tasks (default) |
gemini-3-pro-preview |
Medium |
Highest |
1M |
Complex reasoning, research |
gemini-2.5-flash |
Fast |
Medium |
1M |
Stable, reliable generation |
gemini-2.5-pro |
Slow |
High |
1M |
Code, math, STEM tasks |
Temperature Settings
| Value |
Creativity |
Best For |
| 0.0-0.3 |
Low |
Code, facts, formal writing |
| 0.4-0.7 |
Medium |
Balanced output |
| 0.8-1.0 |
High |
Creative writing, brainstorming |
| 1.0-2.0 |
Very High |
Highly creative, varied outputs |
Thinking Budget
| Value |
Description |
| 0 |
Disabled (default behavior) |
| 512-1024 |
Standard reasoning |
| 2048+ |
Deep analysis (slower, more tokens) |
Output Interpretation
Standard Text Output
- Plain text response ready for use
- Check for truncation if max-tokens was set
- May include markdown formatting
JSON Output
- Valid JSON object (use
--json flag)
- Parse with:
import json; data = json.loads(output)
- Verify structure matches your requirements
- Handle potential parsing errors
Grounded Response
When --grounding is used, the script prints:
- Main response text
- "--- Grounding Sources ---" section
- List of sources with titles and URLs
Thinking Mode Output
- May include reasoning steps before final answer
- Longer response times due to thinking process
- Better for tasks requiring careful analysis
Common Issues
"google-genai not installed"
npm install @google/genai@latest dotenv@latest
"API key not set"
Set environment variable:
export GOOGLE_API_KEY="your-key-here"
# or
export GEMINI_API_KEY="your-key-here"
"Model not available"
- Check model name spelling
- Verify API access for selected model
- Try
gemini-3-flash-preview (most available)
JSON parse errors
- Ensure prompt explicitly requests JSON structure
- Check output for JSON formatting
- Consider using system instruction: "You always respond with valid JSON"
Image file not found
- Verify image path is correct
- Use absolute paths if relative paths fail
- Supported formats: PNG, JPEG
Response truncated
- Increase
--max-tokens value
- Break task into smaller requests
- Use pro models with higher token limits
Best Practices
Performance Optimization
- Use flash models for speed, pro for quality
- Lower temperature (0.0-0.3) for deterministic outputs
- Set appropriate max-tokens to control costs
- Use thinking mode only for complex tasks
Prompt Engineering
- Be specific and clear in your prompts
- Use system instructions for consistent behavior
- Include examples in prompts for better results
- For JSON: specify exact structure in prompt
Error Handling
- Wrap script calls in try-except blocks
- Validate JSON output before parsing
- Handle network timeouts with retries
- Check API quota limits for batch operations
Cost Management
- Use flash models when possible (lower cost)
- Limit max-tokens for simple queries
- Cache results for repeated queries
- Use batch API for high-volume tasks
Related Skills
- gemini-image: Generate images from text
- gemini-tts: Convert text to speech
- gemini-embeddings: Create vector embeddings for semantic search
- gemini-files: Upload files for multimodal processing
- gemini-batch: Process multiple requests efficiently
Quick Reference
# Basic
node scripts/generate.js "Your prompt"
# Persona
node scripts/generate.js "Prompt" --system "You are X"
# Thinking
node scripts/generate.js "Complex task" --thinking
# JSON
node scripts/generate.js "Generate JSON" --json
# Search
node scripts/generate.js "Current event" --grounding
# Multimodal
node scripts/generate.js "Describe this" --image photo.png
Reference
1---2name: gemini-text3description: Generate text content using Google Gemini models via scripts/. Use for text generation, multimodal prompts with images, thinking mode for complex reasoning, JSON-formatted outputs, and Google Search grounding for real-time information. Triggers on "generate with gemini", "use gemini for text", "AI text generation", "multimodal prompt", "gemini thinking mode", "grounded response".4license: MIT5---67# Gemini Text Generation89Generate content using Google's Gemini API through executable scripts with advanced capabilities including system instructions, thinking mode, JSON output, and Google Search grounding.1011## When to Use This Skill1213Use this skill when you need to:14- Generate any type of text content (blogs, emails, code, stories)15- Process images with text descriptions or analysis16- Perform complex reasoning requiring step-by-step thinking17- Get structured JSON outputs for data processing18- Access real-time information via Google Search19- Apply specific personas or behavior patterns20- Combine text generation with other Gemini skills (images, TTS, embeddings)2122## Available Scripts2324### scripts/generate.js25**Purpose**: Full-featured text generation with all Gemini capabilities2627**When to use**:28- Any text generation task29- Multimodal prompts (text + image)30- Complex reasoning requiring thinking mode31- Structured JSON output requirements32- Real-time information needs (grounding)33- Custom system instructions/personas3435**Key parameters**:36| Parameter | Description | Example |37|-----------|-------------|---------|38| `prompt` | Text prompt (required) | `"Explain quantum computing"` |39| `--model`, `-m` | Model to use | `gemini-3-flash-preview` |40| `--system`, `-s` | System instruction | `"You are a helpful assistant"` |41| `--thinking`, `-t` | Enable thinking mode | Flag |42| `--json`, `-j` | Force JSON output | Flag |43| `--grounding`, `-g` | Enable Google Search | Flag |44| `--image`, `-i` | Image for multimodal | `photo.png` |45| `--temperature` | Sampling 0.0-2.0 | `0.7` for creative |46| `--max-tokens` | Output limit | `1000` |4748**Output**: Generated text string, optionally with grounding sources4950## Workflows5152### Workflow 1: Basic Text Generation53```bash54node scripts/generate.js "Explain quantum computing in simple terms"55```56- Best for: Simple content creation, explanations, summaries57- Model: `gemini-3-flash-preview` (default, fast)5859### Workflow 2: With System Instruction (Persona)60```bash61node scripts/generate.js "How do I read a file in Python?" --system "You are a helpful coding assistant"62```63- Best for: Domain-specific tasks, expert personas, consistent tone64- Use when: You need specific behavioral constraints6566### Workflow 3: Complex Reasoning (Thinking Mode)67```bash68node scripts/generate.js "Analyze the ethical implications of AI in healthcare" --thinking69```70- Best for: Complex analysis, step-by-step reasoning, multi-step problems71- Use when: Task requires careful consideration and logical progression7273### Workflow 4: Structured JSON Output74```bash75node scripts/generate.js "Generate a user profile object with name, email, and preferences" --json76```77- Best for: Data extraction, structured data generation, API responses78- Output: Valid JSON ready for parsing79- Note: Prompt must clearly request JSON structure8081### Workflow 5: Real-Time Information (Grounding)82```bash83node scripts/generate.js "Who won the latest Super Bowl?" --grounding84```85- Best for: Current events, news, factual information after training cutoff86- Output: Response + grounding sources with citations87- Use when: Accuracy of current information is critical8889### Workflow 6: Multimodal (Image Analysis)90```bash91node scripts/generate.js "Describe what's in this image in detail" --image photo.png92```93- Best for: Image captioning, visual analysis, image-based Q&A94- Requires: Image file in PNG or JPEG format95- Combines well with: gemini-files for file upload9697### Workflow 7: Content Creation Pipeline (Batch + Text + TTS)98```bash99# 1. Create batch requests (gemini-batch skill)100# 2. Generate content101node scripts/generate.js "Create a 500-word blog post about sustainable energy"102# 3. Convert to audio (gemini-tts skill)103```104- Best for: High-volume content production, podcasts, audiobooks105106## Parameters Reference107108### Model Selection109110| Model | Speed | Intelligence | Context | Best For |111|-------|-------|--------------|---------|----------|112| `gemini-3-flash-preview` | Fast | High | 1M | General use, agentic tasks (default) |113| `gemini-3-pro-preview` | Medium | Highest | 1M | Complex reasoning, research |114| `gemini-2.5-flash` | Fast | Medium | 1M | Stable, reliable generation |115| `gemini-2.5-pro` | Slow | High | 1M | Code, math, STEM tasks |116117### Temperature Settings118119| Value | Creativity | Best For |120|-------|-----------|----------|121| 0.0-0.3 | Low | Code, facts, formal writing |122| 0.4-0.7 | Medium | Balanced output |123| 0.8-1.0 | High | Creative writing, brainstorming |124| 1.0-2.0 | Very High | Highly creative, varied outputs |125126### Thinking Budget127128| Value | Description |129|-------|-------------|130| 0 | Disabled (default behavior) |131| 512-1024 | Standard reasoning |132| 2048+ | Deep analysis (slower, more tokens) |133134## Output Interpretation135136### Standard Text Output137- Plain text response ready for use138- Check for truncation if max-tokens was set139- May include markdown formatting140141### JSON Output142- Valid JSON object (use `--json` flag)143- Parse with: `import json; data = json.loads(output)`144- Verify structure matches your requirements145- Handle potential parsing errors146147### Grounded Response148When `--grounding` is used, the script prints:1491. Main response text1502. "--- Grounding Sources ---" section1513. List of sources with titles and URLs152153### Thinking Mode Output154- May include reasoning steps before final answer155- Longer response times due to thinking process156- Better for tasks requiring careful analysis157158## Common Issues159160### "google-genai not installed"161```bash162npm install @google/genai@latest dotenv@latest163```164165### "API key not set"166Set environment variable:167```bash168export GOOGLE_API_KEY="your-key-here"169# or170export GEMINI_API_KEY="your-key-here"171```172173### "Model not available"174- Check model name spelling175- Verify API access for selected model176- Try `gemini-3-flash-preview` (most available)177178### JSON parse errors179- Ensure prompt explicitly requests JSON structure180- Check output for JSON formatting181- Consider using system instruction: "You always respond with valid JSON"182183### Image file not found184- Verify image path is correct185- Use absolute paths if relative paths fail186- Supported formats: PNG, JPEG187188### Response truncated189- Increase `--max-tokens` value190- Break task into smaller requests191- Use pro models with higher token limits192193## Best Practices194195### Performance Optimization196- Use flash models for speed, pro for quality197- Lower temperature (0.0-0.3) for deterministic outputs198- Set appropriate max-tokens to control costs199- Use thinking mode only for complex tasks200201### Prompt Engineering202- Be specific and clear in your prompts203- Use system instructions for consistent behavior204- Include examples in prompts for better results205- For JSON: specify exact structure in prompt206207### Error Handling208- Wrap script calls in try-except blocks209- Validate JSON output before parsing210- Handle network timeouts with retries211- Check API quota limits for batch operations212213### Cost Management214- Use flash models when possible (lower cost)215- Limit max-tokens for simple queries216- Cache results for repeated queries217- Use batch API for high-volume tasks218219## Related Skills220221- **gemini-image**: Generate images from text222- **gemini-tts**: Convert text to speech223- **gemini-embeddings**: Create vector embeddings for semantic search224- **gemini-files**: Upload files for multimodal processing225- **gemini-batch**: Process multiple requests efficiently226227## Quick Reference228229```bash230# Basic231node scripts/generate.js "Your prompt"232233# Persona234node scripts/generate.js "Prompt" --system "You are X"235236# Thinking237node scripts/generate.js "Complex task" --thinking238239# JSON240node scripts/generate.js "Generate JSON" --json241242# Search243node scripts/generate.js "Current event" --grounding244245# Multimodal246node scripts/generate.js "Describe this" --image photo.png247```248249## Reference250251- See `references/models.md` for detailed model information252- Get API key: https://aistudio.google.com/apikey253- Documentation: https://ai.google.dev/gemini-api