惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
爱范儿
爱范儿
GbyAI
GbyAI
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
C
Check Point Blog
H
Help Net Security
P
Proofpoint News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog RSS Feed
Y
Y Combinator Blog
U
Unit 42
T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Gemini API Cheatsheet 2026 — Free Tier Limits, Models, an...
hiyoyo · 2026-05-03 · via DEV Community
Cover image for Gemini API Cheatsheet 2026 — Free Tier Limits, Models, and Endpoints in One Place

hiyoyo

If this is useful, a ❤️ helps others find it.

Everything I keep looking up when building with Gemini — in one place.


Models (2026)

Model Context Best for
gemini-2.5-flash-preview 1M tokens General use, thinking, fast
gemini-2.5-pro-preview 1M tokens Complex reasoning, best quality
gemini-1.5-flash 1M tokens Stable, production-ready
gemini-1.5-pro 2M tokens Longest context
gemini-2.0-flash-lite 1M tokens Lowest latency, highest volume

For most use cases: gemini-2.5-flash-preview


Free Tier Limits (Google AI Studio)

Model RPM TPM RPD
Gemini 2.5 Flash Preview 10 250,000 500
Gemini 1.5 Flash 15 1,000,000 1,500
Gemini 1.5 Pro 2 32,000 50
Gemini 2.0 Flash Lite 30 1,000,000 1,500

RPM = requests per minute, TPM = tokens per minute, RPD = requests per day


Basic Request (REST)

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview:generateContent \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: YOUR_API_KEY" \
  -d '{
    "contents": [{"parts": [{"text": "Your prompt here"}]}]
  }'

Enter fullscreen mode Exit fullscreen mode


With System Prompt

{
  "system_instruction": {
    "parts": [{"text": "You are a helpful assistant."}]
  },
  "contents": [
    {"role": "user", "parts": [{"text": "Your prompt here"}]}
  ]
}

Enter fullscreen mode Exit fullscreen mode


Streaming

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview:streamGenerateContent \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: YOUR_API_KEY" \
  -d '{"contents": [{"parts": [{"text": "Tell me a story"}]}]}'

Enter fullscreen mode Exit fullscreen mode


In Rust (reqwest)

use reqwest::Client;
use serde_json::json;

pub async fn call_gemini(prompt: &str, api_key: &str) -> Result {
    let client = Client::new();
    let url = format!(
        "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview:generateContent?key={}",
        api_key
    );

    let body = json!({
        "contents": [{"parts": [{"text": prompt}]}]
    });

    let res = client.post(&url).json(&body).send().await?;
    let data: serde_json::Value = res.json().await?;

    let text = data["candidates"][0]["content"]["parts"][0]["text"]
        .as_str()
        .unwrap_or("")
        .to_string();

    Ok(text)
}

Enter fullscreen mode Exit fullscreen mode


Error Codes

Code Meaning Fix
400 Bad request / token limit Shorten prompt
403 Invalid API key Check key
429 Rate limit hit Wait and retry
500 Internal error Retry
503 Overloaded Wait 2s, retry once

Token Counting (rough guide)

  • 1 token ≈ 4 characters in English
  • 1 token ≈ 2–3 characters in Japanese
  • 100 lines of logcat ≈ 3,000–5,000 tokens
  • 1 page of PDF text ≈ 500–800 tokens

Get a Free API Key

  1. Go to aistudio.google.com
  2. Sign in with Google
  3. Click "Get API Key"
  4. Done — no credit card required

Hiyoko PDF Vault → https://hiyokoko.gumroad.com/l/HiyokoPDFVault
X → @hiyoyok