MeshWorld India LogoMeshWorld.

Gemini API Cheat Sheet: 2.5 Pro, Vision & Tools

(Updated: Jul 23, 2026)
Listen to ArticleAI Speech
~7 min read narration
100%
Gemini API Cheat Sheet: 2.5 Pro, Vision & Tools

What Are the Key Gemini API Models and Parameters?

Models

Model IDContextBest for
gemini-2.5-pro1M tokensComplex reasoning, long documents, coding
gemini-2.5-flash1M tokensFast, cost-efficient, everyday tasks
gemini-2.0-flash1M tokensSpeed-optimized, multimodal
gemini-2.0-flash-lite1M tokensLightest, cheapest, high-volume
gemini-1.5-pro2M tokensLargest context window available
text-embedding-0042048 tokensText embeddings
imagen-3.0-generate-002Image generation

generateContent — key parameters

ParameterTypeWhat it does
modelstringWhich Gemini model to use
contentsarray[{role, parts}] — user/model turns
systemInstructionobjectSystem prompt {parts: [{text}]}
generationConfigobjectTemperature, tokens, format settings
safetySettingsarrayContent filtering thresholds
toolsarrayFunction declarations or built-in tools
toolConfigobject{functionCallingConfig: {mode}}

generationConfig options

SettingTypeWhat it does
temperaturefloat 0–2Randomness
topPfloat 0–1Nucleus sampling
topKintToken pool size
maxOutputTokensintMax response length
stopSequencesarrayStrings that stop generation
responseMimeTypestring"application/json" for JSON mode
responseSchemaobjectJSON schema for structured output
candidateCountintNumber of responses to generate
thinkingConfigobject{thinkingBudget: N} for reasoning

Built-in tools

ToolWhat it does
googleSearchGrounds responses in live Google Search results
codeExecutionRuns Python code, returns output + charts
urlContextFetches and includes content from URLs

Gemini CLI — commands

CommandWhat it does
geminiStart interactive REPL
gemini -p "prompt"Non-interactive single prompt
gemini --model gemini-2.5-proUse a specific model
gemini --yoloAuto-accept all tool actions (no confirmation)
gemini --sandboxRun code execution in sandboxed environment
gemini --debugShow full API request/response details
/helpShow slash commands in REPL
/clearClear conversation history
/statsShow token usage for this session
/toolsList available tools

Safety settings — harm categories

CategoryHarmCategory constant
Dangerous contentHARM_CATEGORY_DANGEROUS_CONTENT
HarassmentHARM_CATEGORY_HARASSMENT
Hate speechHARM_CATEGORY_HATE_SPEECH
Sexually explicitHARM_CATEGORY_SEXUALLY_EXPLICIT

Threshold values: BLOCK_NONE, BLOCK_LOW_AND_ABOVE, BLOCK_MEDIUM_AND_ABOVE, BLOCK_HIGH_AND_ABOVE


Detailed sections

Basic text generation (Node.js)

JAVASCRIPT
import { GoogleGenerativeAI } from "@google/generative-ai";

const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-2.0-flash" });

const result = await model.generateContent("Explain recursion simply.");
console.log(result.response.text());

System instruction + chat

JAVASCRIPT
const model = genAI.getGenerativeModel({
  model: "gemini-2.5-flash",
  systemInstruction: "You are a senior DevOps engineer. Give concise, practical answers.",
});

const chat = model.startChat();

const r1 = await chat.sendMessage("What is a Kubernetes pod?");
console.log(r1.response.text());

const r2 = await chat.sendMessage("How is it different from a deployment?");
console.log(r2.response.text());

Streaming response

JAVASCRIPT
const model = genAI.getGenerativeModel({ model: "gemini-2.0-flash" });

const result = await model.generateContentStream(
  "Write a step-by-step guide to setting up CI/CD."
);

for await (const chunk of result.stream) {
  process.stdout.write(chunk.text());
}

Vision — image input

JAVASCRIPT
import fs from "fs";

const model = genAI.getGenerativeModel({ model: "gemini-2.0-flash" });

const imageData = fs.readFileSync("diagram.png");
const base64 = imageData.toString("base64");

const result = await model.generateContent([
  { inlineData: { mimeType: "image/png", data: base64 } },
  "Describe what's in this architecture diagram.",
]);

console.log(result.response.text());

JSON / structured output

JAVASCRIPT
const model = genAI.getGenerativeModel({
  model: "gemini-2.5-flash",
  generationConfig: {
    responseMimeType: "application/json",
    responseSchema: {
      type: "object",
      properties: {
        name: { type: "string" },
        language: { type: "string" },
        stars: { type: "integer" },
      },
      required: ["name", "language", "stars"],
    },
  },
});

const result = await model.generateContent(
  "Extract repo info from: react/react - JavaScript - 230k stars"
);

const data = JSON.parse(result.response.text());
console.log(data); // { name: 'react/react', language: 'JavaScript', stars: 230000 }

Function calling (tool use)

JAVASCRIPT
const tools = [
  {
    functionDeclarations: [
      {
        name: "get_stock_price",
        description: "Get the current stock price for a ticker symbol",
        parameters: {
          type: "object",
          properties: {
            ticker: {
              type: "string",
              description: "Stock ticker symbol, e.g. GOOG",
            },
          },
          required: ["ticker"],
        },
      },
    ],
  },
];

const model = genAI.getGenerativeModel({
  model: "gemini-2.0-flash",
  tools,
});

const result = await model.generateContent("What's Google's stock price?");
const response = result.response;

// Check if model wants to call a function
const call = response.candidates[0].content.parts[0].functionCall;
if (call) {
  console.log(call.name, call.args); // get_stock_price { ticker: 'GOOG' }
}
JAVASCRIPT
const model = genAI.getGenerativeModel({
  model: "gemini-2.0-flash",
  tools: [{ googleSearch: {} }], // enable live search grounding
});

const result = await model.generateContent(
  "What happened in AI news this week?"
);

console.log(result.response.text());

// Check grounding metadata
const groundingMeta = result.response.candidates[0].groundingMetadata;
console.log(groundingMeta?.webSearchQueries); // queries used
console.log(groundingMeta?.groundingChunks); // sources cited

Code execution

JAVASCRIPT
const model = genAI.getGenerativeModel({
  model: "gemini-2.5-flash",
  tools: [{ codeExecution: {} }],
});

const result = await model.generateContent(
  "Calculate the first 20 Fibonacci numbers and plot them."
);

// Response includes code written, execution output, and optionally a chart
const parts = result.response.candidates[0].content.parts;
for (const part of parts) {
  if (part.executableCode) console.log("Code:", part.executableCode.code);
  if (part.codeExecutionResult) console.log("Output:", part.codeExecutionResult.output);
}

Embeddings

JAVASCRIPT
const embModel = genAI.getGenerativeModel({ model: "text-embedding-004" });

const result = await embModel.embedContent("How do I deploy to Kubernetes?");
const vector = result.embedding.values; // float array (768 dims)

// Batch embeddings
const batchResult = await embModel.batchEmbedContents({
  requests: [
    { content: { parts: [{ text: "First document" }] } },
    { content: { parts: [{ text: "Second document" }] } },
  ],
});

Long document — file upload (Files API)

JAVASCRIPT
import { GoogleAIFileManager } from "@google/generative-ai/server";

const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY);

// Upload a large PDF
const uploadResult = await fileManager.uploadFile("report.pdf", {
  mimeType: "application/pdf",
  displayName: "Q4 Report",
});

const file = uploadResult.file;
console.log(`Uploaded: ${file.uri}`);

// Use the uploaded file in a prompt
const model = genAI.getGenerativeModel({ model: "gemini-2.5-pro" });

const result = await model.generateContent([
  { fileData: { fileUri: file.uri, mimeType: "application/pdf" } },
  "Summarize the key financial highlights from this report.",
]);

console.log(result.response.text());

Environment setup

BASH
# Install SDK
npm install @google/generative-ai

# Set API key
export GEMINI_API_KEY=AIza...

# Get a key: aistudio.google.com

# Python SDK
pip install google-generativeai

python3 -c "
import google.generativeai as genai
genai.configure(api_key='YOUR_KEY')
model = genai.GenerativeModel('gemini-2.0-flash')
r = model.generate_content('Hello!')
print(r.text)
"

Gemini CLI setup

BASH
# Install
npm install -g @google/gemini-cli

# Authenticate (opens browser)
gemini auth login

# Or set API key directly
export GEMINI_API_KEY=AIza...

# Start interactive session
gemini

# One-shot with file context
gemini -p "Review this code for bugs" < src/main.ts

Frequently Asked Questions

Which Gemini model should I select for software development?

Use gemini-2.5-pro for complex refactoring, multi-file code review, and deep architectural reasoning. Use gemini-2.5-flash or gemini-2.0-flash for high-throughput tasks like inline completions, basic chat, or fast code generation.

How does Google Search grounding work with Gemini API?

By passing the googleSearch tool parameter in your API payload, Gemini executes web queries behind the scenes and embeds real-time search citations directly into the generated response.


See how Gemini compares in practice: Claude vs Gemini 2.5 for Coding.

Reader Quality Feedback

Did this technical guide help solve your problem?

Suggest Errata ($0)
Vishnu
Primary Author

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Explore Author Archive
Compute Fuel & Open Testbed
100% Independent & Verified

Fuel High-Density, Zero-Fluff Engineering Deep-Dives

Every guide on MeshWorld is validated on physical Linux nodes and reproducible testbeds. If this article saved you hours of debugging or unblocked production, consider funding our next cluster run.

Weekly Dispatch

Join MeshWorld Dispatch

Get practical tutorials, system blueprints, and curated AI engineering notes straight to your inbox. No fluff, zero spam.

Zero spam. 1-click unsubscribe anytime.Prefer RSS?
Curated Continuations

Up Next in This Domain.

Browse Full Archive