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

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Jina AI
Jina AI
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
美团技术团队
腾讯CDC
博客园 - Franky
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
aimingoo的专栏
aimingoo的专栏
博客园_首页
V
V2EX
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss

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 ฟรี ไม่จำกัด
Thanawat Won · 2026-05-09 · via DEV Community

กลุ่มโมเดล Gemini ของ Google เป็นตัวเลือก LLM ที่คุ้มค่าสำหรับงานปริมาณสูง แต่ค่าใช้จ่ายยังเพิ่มเร็วเมื่อแอปสาธารณะมีผู้ใช้จำนวนมาก Puter.js ช่วยให้คุณเรียกใช้ Gemini หลายรุ่น เช่น 2.5 Pro, 2.5 Flash, 2.0 Flash, 3 Flash Preview รวมถึงตระกูล Gemma 2/3/4 ได้จากเบราว์เซอร์โดยไม่ต้องใช้ Google API key และโมเดลค่าใช้จ่ายจะอยู่ที่ผู้ใช้ปลายทางผ่านบัญชี Puter ของผู้ใช้เอง

ลองใช้ Apidog วันนี้

สรุป (TL;DR)

  • Puter.js ช่วยให้เรียกใช้ Gemini และ Gemma จากเบราว์เซอร์ได้โดยไม่ต้องมี Google API key, Google Cloud project หรือเซิร์ฟเวอร์
  • โมเดล Gemini ที่รองรับ: 2.5 Pro, 2.5 Flash, 2.5 Flash Lite, 2.0 Flash, 2.0 Flash Lite, 3 Flash Preview รวมถึงรุ่นพรีวิวบางรุ่น
  • โมเดล Gemma ที่รองรับ: Gemma 2, 3, 4 ในหลายขนาด เช่น 4B, 12B, 27B, 31B, 26B-A4B
  • เริ่มต้นได้ด้วย <script> แท็กเดียว แล้วเรียก puter.ai.chat()
  • รองรับ streaming, vision input, temperature และ multi-turn chat ในเบราว์เซอร์
  • ผู้ใช้ปลายทางเป็นผู้รับผิดชอบค่าใช้จ่ายผ่านบัญชี Puter ของตนเอง
  • ใช้ Apidog เพื่อจัดการและเปรียบเทียบการทดสอบระหว่าง Puter prototype กับ Gemini API อย่างเป็นทางการ

“ฟรีไม่จำกัด” ทำงานอย่างไร

Puter.js เปลี่ยนรูปแบบการเรียกใช้ LLM จาก “นักพัฒนาถือ API key และจ่ายค่า token” เป็น “ผู้ใช้ลงชื่อเข้าใช้ Puter และใช้เครดิตของตนเอง” บัญชี Puter ใหม่จะมีเครดิตเริ่มต้น และผู้ใช้สามารถเติมเงินได้เมื่อต้องการใช้งานเพิ่ม

ผลลัพธ์สำหรับนักพัฒนา:

  • ไม่ต้องมี Google Cloud project หรือ AI Studio key ไม่ต้องจัดการ quota, key rotation หรือ billing account
  • ไม่ต้องรับภาระค่า token ของผู้ใช้ทั้งหมด ปริมาณการใช้งานผูกกับบัญชีของผู้ใช้ปลายทาง
  • เหมาะกับแอปฝั่งเบราว์เซอร์ เช่น static site, demo, hackathon project, browser extension หรือ prototype

ข้อจำกัดสำคัญ: Puter.js เหมาะกับงานที่มี user session ในเบราว์เซอร์ หากเป็น cron job, batch job, webhook หรือ backend service ควรใช้ Gemini API อย่างเป็นทางการโดยตรง

ขั้นตอนที่ 1: ติดตั้ง Puter.js

วิธีที่เร็วที่สุดคือใช้ CDN:

<script src="https://js.puter.com/v2/"></script>

Enter fullscreen mode Exit fullscreen mode

หรือถ้าใช้ bundler:

npm install @heyputer/puter.js

Enter fullscreen mode Exit fullscreen mode

import { puter } from '@heyputer/puter.js';

Enter fullscreen mode Exit fullscreen mode

ขั้นตอนที่ 2: เลือกโมเดล Gemini หรือ Gemma

เลือกโมเดลตามรูปแบบงาน:

รหัสโมเดล เหมาะกับงานแบบใด
google/gemini-2.5-pro งาน reasoning ซับซ้อน, วิเคราะห์เอกสารยาว, งานที่ต้องการคุณภาพสูง
google/gemini-2.5-flash ค่าเริ่มต้นสำหรับแอปทั่วไป สมดุลระหว่างความเร็วและคุณภาพ
google/gemini-2.5-flash-lite งานปริมาณมาก เช่น tagging, classification, Q&A ง่ายๆ
google/gemini-2.0-flash งานทั่วไปที่ต้องการพฤติกรรมค่อนข้างเสถียร
google/gemini-3-flash-preview ทดลองรุ่นพรีวิวล่าสุด
google/gemma-3-27b-it งานที่ต้องการ open-weight model แบบ instruction-tuned
google/gemma-4-31b-it Gemma ขนาดใหญ่สำหรับงานที่ต้องการคุณภาพสูงกว่า Gemma รุ่นเล็ก

แนวทางเริ่มต้น:

  • ใช้ google/gemini-2.5-flash เป็น default
  • ใช้ google/gemini-2.5-pro เมื่อ prompt ซับซ้อนหรือจำเป็นต้อง reasoning ลึก
  • ใช้ google/gemini-2.5-flash-lite เมื่อต้องการความเร็วและต้นทุนต่ำสำหรับงานจำนวนมาก

ขั้นตอนที่ 3: เรียก Gemini จาก HTML หน้าเดียว

ตัวอย่างขั้นต่ำ:

<!DOCTYPE html>
<html>
<body>
  <script src="https://js.puter.com/v2/"></script>

  <script>
    puter.ai.chat(
      "Explain machine learning in three sentences",
      { model: "google/gemini-2.5-flash" }
    ).then(response => {
      puter.print(response);
    });
  </script>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

เปิดไฟล์นี้ในเบราว์เซอร์ จากนั้น Puter จะจัดการ flow การลงชื่อเข้าใช้และการเรียกโมเดลให้ คุณไม่ต้องตั้งค่า API key, environment variable หรือ backend server

ขั้นตอนที่ 4: สตรีมคำตอบสำหรับ UI แชท

ถ้าคำตอบยาวหรือเป็นแชท ควรใช้ streaming เพื่อให้ผู้ใช้เห็นคำตอบระหว่างที่โมเดลกำลังสร้างข้อความ:

const response = await puter.ai.chat(
  "Explain photosynthesis in detail",
  {
    model: "google/gemini-2.5-flash",
    stream: true,
  }
);

for await (const part of response) {
  if (part?.text) {
    outputDiv.innerHTML += part.text;
  }
}

Enter fullscreen mode Exit fullscreen mode

part.text คือ chunk ของคำตอบ คุณสามารถ append เข้า UI ได้ทันที เช่น <div>, chat bubble หรือ markdown renderer

ขั้นตอนที่ 5: ส่งรูปภาพเข้า Gemini ด้วย vision input

Gemini รองรับ multimodal input คุณสามารถส่ง URL รูปภาพเป็น argument ที่สอง:

puter.ai.chat(
  "What do you see in this image? Describe colors, objects, and mood.",
  "https://assets.puter.site/doge.jpeg",
  { model: "google/gemini-2.5-flash" }
).then(response => {
  puter.print(response);
});

Enter fullscreen mode Exit fullscreen mode

กรณีใช้งานที่เหมาะสม:

  • สร้าง alt text
  • วิเคราะห์ภาพสินค้า
  • OCR เบื้องต้น
  • Q&A จากรูปภาพ
  • วิเคราะห์ screenshot
  • เครื่องมือ accessibility
  • image tagging

สำหรับภาพธรรมชาติและ diagram คุณภาพของ Gemini โดยทั่วไปทำได้ดี ส่วน screenshot ที่มีข้อความหนาแน่นมาก อาจต้องทดสอบเทียบกับโมเดลอื่นก่อนใช้งานจริง

ขั้นตอนที่ 6: ปรับ temperature

ส่ง parameter ผ่าน options object:

const response = await puter.ai.chat(
  "Write a creative short story about a robot chef",
  {
    model: "google/gemini-2.5-flash",
    temperature: 0.2,
  }
);

console.log(response);

Enter fullscreen mode Exit fullscreen mode

แนวทางตั้งค่า:

  • 0.0–0.3: งาน factual, structured output, classification
  • 0.4–0.7: งานแชททั่วไป
  • 0.7–1.0: งานเขียนเชิงสร้างสรรค์

สำหรับแชททั่วไป Gemini Flash มักทำงานได้ดีที่ประมาณ 0.7

ขั้นตอนที่ 7: ทำ multi-turn chat

ส่งประวัติการสนทนาเป็น array:

const messages = [
  { role: "user", content: "I am building a Next.js app with Postgres." },
  { role: "assistant", content: "Got it. What do you need help with?" },
  { role: "user", content: "How should I structure migrations?" },
];

const response = await puter.ai.chat(messages, {
  model: "google/gemini-2.5-pro",
});

console.log(response);

Enter fullscreen mode Exit fullscreen mode

ในการใช้งานจริง ให้เก็บข้อความของผู้ใช้และคำตอบของ assistant ทุกครั้ง แล้วส่ง history ทั้งหมดในการเรียกครั้งถัดไป เพื่อให้โมเดลรักษาบริบทของบทสนทนา

เปรียบเทียบ Gemini กับโมเดลอื่นด้วย prompt เดียวกัน

Puter ใช้ interface เดียวกันสำหรับหลาย provider คุณจึงเขียน loop เพื่อทดสอบ latency และคุณภาพคำตอบได้ง่าย:

const models = [
  "google/gemini-2.5-flash",
  "claude-sonnet-4-6",
  "gpt-5.5",
  "x-ai/grok-4.3",
];

const prompt = "Refactor this React component to use hooks: ...";

for (const model of models) {
  const start = performance.now();

  const response = await puter.ai.chat(prompt, { model });

  const elapsed = performance.now() - start;
  console.log(`${model}: ${elapsed.toFixed(0)}ms`);
  console.log(response);
  console.log("---");
}

Enter fullscreen mode Exit fullscreen mode

ใช้วิธีนี้เพื่อเลือกโมเดลตามงานจริงของคุณ ไม่ควรเลือกจาก benchmark ทั่วไปเพียงอย่างเดียว เพราะ prompt, context, output format และ UI latency มีผลต่อประสบการณ์ผู้ใช้โดยตรง

สิ่งที่คุณได้รับและสิ่งที่คุณอาจไม่ได้รับ

สิ่งที่คุณได้รับ

  • Gemini 2.5/2.0/3 Flash และ 2.5 Pro
  • ตระกูล Gemma 2/3/4 สำหรับ workflow แบบ open-weight
  • multi-turn conversation
  • streaming response
  • vision input ผ่าน URL รูปภาพ
  • parameter เช่น temperature, max_tokens, system prompts
  • การใช้งานที่เหมาะกับแอปเบราว์เซอร์ที่ต้องการ scale ตามจำนวนผู้ใช้

สิ่งที่คุณอาจไม่ได้รับ ขึ้นอยู่กับเวอร์ชันของ Puter

  • native function calling บน Gemini
  • code execution tools
  • Google Search grounding
  • context window ขนาด 2 ล้าน token เต็มรูปแบบของ Gemini
  • server-side execution ที่ไม่มี browser user session
  • visibility โดยตรงต่อ rate limit จาก Google

ถ้าคุณกำลังสร้าง agent ที่ต้องใช้ tool calling ซับซ้อน, code execution หรือ grounding อย่างเป็นทางการ Gemini API ผ่าน Google AI Studio จะเหมาะกว่า แต่ถ้าเป็นแชท, Q&A, content generation, image understanding หรือ prototype ฝั่งเบราว์เซอร์ Puter.js เพียงพอสำหรับหลายกรณี

เมื่อใดควรใช้ Puter และเมื่อใดควรใช้ Gemini API อย่างเป็นทางการ

ใช้ Puter เมื่อ

  • คุณทำแอปสาธารณะฟรีและไม่ต้องการรับค่า token เอง
  • คุณทำ prototype และไม่ต้องการตั้งค่า Google Cloud
  • คุณต้องการเรียก Gemini จาก static site หรือ browser extension
  • คุณทำโปรเจกต์แฮกกาธอนหรือ demo
  • ผู้ใช้ของคุณยอมรับการลงชื่อเข้าใช้ Puter ได้

ใช้ Gemini API อย่างเป็นทางการเมื่อ

  • คุณต้องการเรียกใช้งานจาก backend เช่น cron, batch, webhook
  • คุณต้องการ code execution, Search grounding หรือ context window 2 ล้าน token
  • คุณต้องการข้อกำหนดด้าน compliance หรือความสัมพันธ์ทางสัญญากับ Google
  • คุณต้องการ fine-tuning หรือ workflow เฉพาะของ Google
  • ผู้ใช้ของคุณไม่ควรผ่านขั้นตอน login ของ Puter

สำหรับคำแนะนำการใช้งาน Gemini 3 Flash แบบครบวงจร ดูที่ วิธีใช้ Gemini 3 Flash Preview API

การทดสอบ integration ด้วย Apidog

เพราะ Puter ทำงานในเบราว์เซอร์ คุณจึงไม่สามารถทดสอบเหมือน backend API runner ได้ทั้งหมด รูปแบบที่ใช้งานได้คือ:

  1. สร้างหน้า static ขนาดเล็กที่โหลด Puter.js และรับ prompt ผ่าน query parameter
  2. ใช้ Apidog ทดสอบ Gemini API อย่างเป็นทางการสำหรับเส้นทาง production หรือ migration
  3. เก็บ environment แยกกันใน collection เดียว เช่น puter-prototype และ gemini-prod

ตัวอย่าง environment:

  • puter-prototype: URL localhost หรือ static page ที่ฝัง Puter.js
  • gemini-prod: https://generativelanguage.googleapis.com/v1

ดาวน์โหลด Apidog แล้วตั้งค่า environment ทั้งสองชุดไว้ใน workspace เดียวกัน เพื่อให้ทดสอบและเปรียบเทียบ behavior ได้สะดวก

สำหรับแนวทางทดสอบ API เพิ่มเติม ดูที่ เครื่องมือทดสอบ API สำหรับวิศวกร QA

เส้นทาง LLM ฟรีอื่นๆ ผ่าน Puter

โมเดล “ผู้ใช้ปลายทางเป็นผู้รับผิดชอบค่าใช้จ่าย” ของ Puter ใช้ได้กับ LLM หลายตัว:

โค้ดส่วนใหญ่เหมือนเดิม เปลี่ยนเพียงค่า model:

const response = await puter.ai.chat("Summarize this text", {
  model: "google/gemini-2.5-flash",
});

Enter fullscreen mode Exit fullscreen mode

คำถามที่พบบ่อย (FAQ)

นี่เป็นแบบไม่จำกัดจริงหรือไม่

จากฝั่งนักพัฒนา ใช่ คุณไม่ต้องถือ API key หรือรับค่า token เอง แต่ผู้ใช้ปลายทางจะใช้เครดิตในบัญชี Puter ของตนเอง บัญชีใหม่มีเครดิตเริ่มต้น และผู้ใช้สามารถเติมเงินได้เมื่อต้องการใช้งานเพิ่ม

ต้องมีบัญชี Google หรือ Google Cloud project หรือไม่

ไม่ต้อง Puter จัดการการเรียกใช้ปลายน้ำให้ คุณไม่ต้องเห็นหรือจัดการ Google API key

ใช้ใน production ได้หรือไม่

ได้ สำหรับแอปที่ทำงานบนเบราว์เซอร์ คำถามสำคัญคือผู้ใช้ของคุณยอมรับ flow การลงชื่อเข้าใช้ Puter หรือไม่

Gemini ผ่าน Puter ให้ผลลัพธ์เหมือน API อย่างเป็นทางการหรือไม่

โมเดลปลายทางคือ Gemini เช่นกัน แต่ flow การเรียกมีชั้นของ Puter เพิ่มเข้ามา ดังนั้น latency อาจต่างกัน ควรทดสอบกับ prompt จริงของคุณก่อนตัดสินใจ

แล้ว context window 2 ล้าน token ของ Gemini ล่ะ

Puter อาจไม่ได้เปิดขีดจำกัด 2 ล้าน token เต็มรูปแบบในทุกโมเดล หากคุณต้องการบริบทยาวมาก ควรใช้ Gemini API อย่างเป็นทางการ

ใช้ Gemini ผ่าน Puter ใน Discord bot หรือ backend service ได้หรือไม่

ไม่เหมาะนัก เพราะ Puter เน้น browser user session หากเป็น bot หรือ backend service ให้ใช้ Gemini API อย่างเป็นทางการโดยตรง

ควรใช้โมเดลใดเป็น default

ใช้ google/gemini-2.5-flash เป็นค่าเริ่มต้นสำหรับงานทั่วไป เปลี่ยนเป็น google/gemini-2.5-pro เมื่อต้องการ reasoning สูง และใช้ google/gemini-2.5-flash-lite สำหรับงาน classification หรือ tagging จำนวนมาก

รองรับ Imagen หรือไม่

ปัจจุบัน Puter รองรับการสร้างภาพผ่าน gpt-image-2 และ DALL-E ของ OpenAI ไม่ใช่ Imagen ดู รับ GPT-5.5 API ฟรีไม่จำกัด สำหรับเส้นทางการสร้างภาพ

สรุป

Gemini ผ่าน Puter.js เป็นวิธีที่รวดเร็วสำหรับการเพิ่มความสามารถ LLM และ multimodal ให้แอปฝั่งเบราว์เซอร์โดยไม่ต้องตั้งค่า Google Cloud หรือจัดการ API key เริ่มต้นด้วยการเพิ่ม script, เลือก google/gemini-2.5-flash, แล้วเรียก puter.ai.chat()

ถ้าคุณต้องการ backend execution, fine-tuning, code execution, Search grounding หรือ context window ขนาดใหญ่มาก ให้ใช้ Gemini API อย่างเป็นทางการ แต่ถ้าคุณกำลังทำ prototype, static site, hackathon project หรือแอปสาธารณะฟรี Puter.js เป็นทางเลือกที่ใช้งานง่ายและลดภาระค่าใช้จ่ายฝั่งนักพัฒนาได้มาก

สร้าง request และ environment ใน Apidog เพื่อเปรียบเทียบ Puter prototype กับ Gemini API อย่างเป็นทางการ แล้วเลือกเส้นทางที่เหมาะกับ production ของคุณ