All skills
google avatar

/gemini-api

@becc4b8
by googlegoogle/skills21k stars
1,698

Use when the user asks about using Gemini in an enterprise environment or explicitly mentions Vertex AI, Google Cloud, or Agent Platform. Guides the usage of the Gemini API on Agent Platform with the Google Gen AI SDK. Covers SDK usage (Python, JS/TS, Go, Java, C#), capabilities like multimodal inputs, tools, media generation, caching, batch prediction, and Live API.

Use this Skill: https://skilld.dev/gh/google/skills/gemini-api

This session only. Nothing lands on disk.

referencesadvanced_features.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Advanced Features

Content Caching

Cache large documents or contexts to reduce cost and latency.

Only use explicit caching if asked directly. Implicit caching is enabled by default and automatically provides cost savings when cache hits occur.

from google import genai
from google.genai import types

client = genai.Client()

content_cache = client.caches.create(
    model="gemini-3.8-flash",
    config=types.CreateCachedContentConfig(
        contents=[
            types.Content(
                role="user",
                parts=[
                    types.Part.from_uri(
                        file_uri="gs://your-bucket/large.pdf",
                        mime_type="application/pdf",
                    )
                ],
            )
        ],
        system_instruction="You are an expert researcher.",
        display_name="example-cache",
        ttl="86400s",
    ),
)

# Use the cache
response = client.models.generate_content(
    model="gemini-3.8-flash",
    contents="Summarize the pdf",
    config=types.GenerateContentConfig(cached_content=content_cache.name),
)

Batch Prediction

For processing large datasets asynchronously.

import time
from google import genai
from google.genai import types

client = genai.Client()

job = client.batches.create(
    model="gemini-3.8-flash",
    src="gs://your-bucket/prompts.jsonl",
    config=types.CreateBatchJobConfig(dest="gs://your-bucket/outputs"),
)

completed_states = {
    types.JobState.JOB_STATE_SUCCEEDED,
    types.JobState.JOB_STATE_FAILED,
    types.JobState.JOB_STATE_CANCELLED,
}
while job.state not in completed_states:
    time.sleep(30)
    job = client.batches.get(name=job.name)

Thinking (Reasoning)

Thinking is on by default for gemini-3.1-pro-preview (default HIGH / dynamic) and gemini-3.8-flash (default MEDIUM). gemini-3.5-flash-lite defaults to MINIMAL. It can be adjusted by using the thinking_level parameter.

  • MINIMAL: Constrains the model to use as few tokens as possible for thinking and is best used for low-complexity tasks that wouldn't benefit from extensive reasoning. (Not supported for gemini-3.1-pro-preview)
  • LOW: Constrains the model to use fewer tokens for thinking and is suitable for simpler tasks where extensive reasoning is not required.
  • MEDIUM: Offers a balanced approach suitable for tasks of moderate complexity that benefit from reasoning but don't require deep, multi-step planning.
  • HIGH: Maximizes reasoning depth. The model may take significantly longer to reach a first token, but the output will be more thoroughly vetted.
from google import genai
from google.genai import types

client = genai.Client()
response = client.models.generate_content(
    model="gemini-3.1-pro-preview",
    contents="solve x^2 + 4x + 4 = 0",
    config=types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(
            thinking_level=types.ThinkingLevel.HIGH,
        )
    ),
)

# Access thoughts if returned
for part in response.candidates[0].content.parts:
    if part.thought:
        print(f"Thought: {part.text}")
    else:
        print(f"Final Answer: {part.text}")

Model Context Protocol (MCP) support (experimental)

Built-in MCP support is an experimental feature. You can pass a local MCP server as a tool directly.

import os
import asyncio
from datetime import datetime
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

from google import genai
from google.genai import types

client = genai.Client()

# Create server parameters for stdio connection
server_params = StdioServerParameters(
    command="npx",  # Executable
    args=["-y", "@philschmid/weather-mcp"],  # MCP Server
    env=None,  # Optional environment variables
)


async def run():
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            # Prompt to get the weather for the current day in London.
            prompt = f"What is the weather in London in {datetime.now().strftime('%Y-%m-%d')}?"

            # Initialize the connection between client and server
            await session.initialize()

            # Send request to the model with MCP function declarations
            response = await client.aio.models.generate_content(
                model="gemini-3.8-flash",
                contents=prompt,
                config=types.GenerateContentConfig(
                    tools=[
                        session  # uses the session, will automatically call the tool using automatic function calling
                    ],
                ),
            )
            print(response.text)


# Start the asyncio event loop and run the main function
asyncio.run(run())

Source: SKILL.md on GitHub

1 warning9d3 checks · Risk SAFE
  • Gen Agent Trust Hub9d

    This skill provides a detailed integration guide for the Gemini API. It includes security considerations such as prompts designed to override the agent's internal knowledge of model versions, instructional safety filter examples that use provocative content, and the demonstration of dynamic code execution and external tool integration via MCP. These elements are presented as educational samples but should be reviewed when implementing in production.

  • Socket9d

    No alerts

  • Snyk9d

    Risk: MEDIUM · 1 issue

Signed by skilld at becc4b8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last week
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}
compatibility
Requires active Google Cloud credentials and Agent Platform API enabled.

README badge

README badge for google/skills/gemini-api