首頁文章關於報價聯絡我們🌐 EN
返回首頁AI API
Gemini 教學|2026 年 Google Gemini API 串接與使用完整教學

Gemini 教學|2026 年 Google Gemini API 串接與使用完整教學

📑 目錄

免費、強大、100 萬 Token!Gemini API 是 2026 年入門 AI 的最佳選擇

💡 重點摘要:如果你想學 AI API,但又不想一開始就花錢——Gemini 就是你的答案。

Google 的 Gemini API 有三個別人比不上的優勢:

  1. 免費額度最大方 — 每分鐘 15 次請求,不用信用卡
  2. Context Window 最大 — 100 萬 Token,可以一次丟整本書進去
  3. Google AI Studio 最好上手 — 圖形介面,不用寫程式就能測試

這篇教學會帶你從註冊帳號開始,到用 Python 串接 Gemini API,再到玩轉多模態功能(丟圖片給 AI 分析)。

想快速上手 AI API?CloudSwap 提供技術支援與企業方案,解決企業採購與發票需求。



Gemini 帳號註冊與 API Key 取得

Answer-First: 只要有 Google 帳號就能使用 Gemini API。前往 Google AI Studio,一鍵建立 API Key,全程不到 3 分鐘。

步驟一:前往 Google AI Studio

  1. 打開瀏覽器,前往 aistudio.google.com
  2. 用你的 Google 帳號登入
  3. 同意服務條款

步驟二:取得 API Key

  1. 點左側選單的「Get API Key」
  2. 點「Create API Key」
  3. 選擇一個 Google Cloud 專案(沒有的話會自動建立)
  4. 複製 API Key

你的 Key 長這樣:AIzaSy...

免費版限制:

對學習和開發原型來說,這些限制完全夠用。

免費版 vs 付費版

項目免費版(Google AI Studio)付費版(Vertex AI)
費用免費按用量計費
RPM15依方案,可達 1000+
SLA
資料隱私可能用於改善服務不用於改善服務
適合學習、原型、個人專案生產環境、企業應用

Gemini 教學步驟圖Gemini 教學步驟圖



Google AI Studio 使用教學

Answer-First: Google AI Studio 是 Gemini 的官方線上測試介面。不用寫程式碼,直接在瀏覽器中測試 Prompt、切換模型、調整參數。

介面導覽

Google AI Studio 的主要區域:

三種測試模式

  1. Chat Prompt:多輪對話模式,適合測試聊天機器人場景
  2. Structured Prompt:給範例讓 AI 學習格式,適合固定格式的輸出
  3. Freeform Prompt:單次問答,最簡單的模式

實際操作

  1. 選擇左側的「Create Prompt」
  2. 右側選擇模型(建議先用 Gemini 2.0 Flash,速度最快)
  3. 在中央輸入你的問題
  4. 點「Run」

試試看這個 Prompt:

你是一位台灣旅遊達人。請推薦三個台北的私房景點,每個景點用 2-3 句話描述。

匯出為程式碼

測試滿意後,點右上角的「Get code」,Google AI Studio 會自動生成 Python、JavaScript、curl 等格式的程式碼,你直接複製貼上就能用。



Python SDK 串接範例

Answer-First: 2026 年 Gemini Python SDK 已更新為 google-genai,語法比舊版更簡潔。安裝只需一行指令。

安裝 SDK

pip install google-genai

注意: 2026 年新版 SDK 是 google-genai(不是舊的 google-generativeai)。如果你看到網路上的教學用 import google.generativeai as genai,那是舊版語法。

基本範例:文字生成

from google import genai

client = genai.Client(api_key="your-api-key")

response = client.models.generate_content(
    model="gemini-2.0-flash",
    contents="請用三句話解釋量子電腦"
)

print(response.text)

多輪對話

from google import genai

client = genai.Client(api_key="your-api-key")

chat = client.chats.create(model="gemini-2.0-flash")

# 第一輪
response1 = chat.send_message("你好,我想學 Python")
print(response1.text)

# 第二輪(AI 會記得上一輪的對話)
response2 = chat.send_message("有什麼推薦的學習資源嗎?")
print(response2.text)

System Prompt 設定

from google import genai
from google.genai import types

client = genai.Client(api_key="your-api-key")

response = client.models.generate_content(
    model="gemini-2.0-flash",
    config=types.GenerateContentConfig(
        system_instruction="你是一位專業的財務分析師,用繁體中文回答",
        temperature=0.5,
        max_output_tokens=1000,
    ),
    contents="請分析 AI 產業的投資前景"
)

print(response.text)

透過 CloudSwap 採購 Gemini API 企業方案,享折扣與統一發票。立即了解 →

想了解 Gemini API 的完整定價、模型比較與企業方案?請參考 Gemini API 完整指南

想從零開始系統性學習 AI API?請參考 AI API 入門教學完整指南



Gemini 進階功能(多模態)教學

Answer-First: Gemini 最強的特色之一是多模態能力——你可以同時傳文字和圖片給 AI 分析。這在其他平台需要額外付費,Gemini 免費版就支援。

圖片分析

from google import genai
from google.genai import types
import base64

client = genai.Client(api_key="your-api-key")

# 讀取本地圖片
with open("receipt.jpg", "rb") as f:
    image_data = base64.b64encode(f.read()).decode()

response = client.models.generate_content(
    model="gemini-2.0-flash",
    contents=[
        types.Part.from_text("請幫我讀取這張收據上的金額和品項"),
        types.Part.from_bytes(
            data=base64.b64decode(image_data),
            mime_type="image/jpeg"
        )
    ]
)

print(response.text)

多模態應用場景

100 萬 Token Context Window

Gemini 2.5 Pro 的 Context Window 是 100 萬 Token。

這有多大?大約等於 50 萬個中文字,或是 3-4 本完整的書

實用場景:

Gemini 的限制(老實說)

Gemini 雖然免費又強大,但也有缺點:

想比較 Gemini 和其他 AI API?請參考 Gemini API 完整指南

想了解 AI API 的整體入門?請參考 AI API 入門教學完整指南

更多 Python 串接教學?請參考 Python AI API 教學完整指南

想學習更廣泛的 API 串接技巧?請參考 API 串接教學

API Key 的安全保管也很重要!請參考 API Key 管理與安全



FAQ:Gemini 教學常見問題

Gemini 註冊需要付費嗎?

不需要。用 Google 帳號登入 Google AI Studio 就能免費使用 Gemini API。免費版每分鐘 15 次請求、每日 1,500 次請求。不需要綁定信用卡。

Gemini 和 ChatGPT 哪個比較好?

各有優勢。Gemini 的免費額度更大方、Context Window 更大(100 萬 vs 128K Token)、多模態功能免費。ChatGPT(GPT-4o)的中文品質更好、API 生態系更完整。建議兩個都試試看。

Gemini API 可以用來做商業產品嗎?

免費版不建議用於正式的商業產品(有速率限制且 SLA 沒保障)。商業用途建議使用 Vertex AI 的付費方案,或透過 CloudSwap 企業方案取得。

舊版 SDK 和新版 SDK 有什麼差別?

舊版是 google-generativeai(import google.generativeai),新版是 google-genai(from google import genai)。2026 年建議用新版,語法更簡潔,功能更完整。

Gemini 支援繁體中文嗎?

支援。但中文品質不如 Claude。常見問題包括:偶爾簡繁混用、部分台灣用語理解不精確。如果對中文品質要求很高,建議用 Claude Sonnet。


立即諮詢,取得 Gemini API 企業方案

CloudSwap 提供 Google Gemini API 企業採購服務(透過 Vertex AI):

  • 企業專屬折扣,享更優惠定價
  • 台灣統一發票,解決報帳難題
  • 中文技術支援,串接問題即時協助

立即諮詢企業方案 →加入 LINE 即時諮詢 →



參考資料

  1. Google AI for Developers - Gemini API Documentation(2026)
  2. Google AI Studio - Official Documentation
  3. google-genai Python SDK - Documentation
  4. Google Cloud - Vertex AI Gemini API
  5. Google - Gemini Model Card & Safety Guidelines
{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "Gemini 教學|2026 年 Google Gemini API 串接與使用完整教學",
  "author": {
    "@type": "Person",
    "name": "CloudSwap 技術團隊",
    "url": "https://cloudswap.info/about"
  },
  "datePublished": "2026-03-21",
  "dateModified": "2026-03-21",
  "publisher": {
    "@type": "Organization",
    "name": "CloudSwap",
    "url": "https://cloudswap.info"
  }
}
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "Gemini 註冊需要付費嗎?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "不需要。用 Google 帳號登入 Google AI Studio 就能免費使用。免費版每分鐘 15 次請求、每日 1,500 次請求,不需要信用卡。"
      }
    },
    {
      "@type": "Question",
      "name": "Gemini 和 ChatGPT 哪個比較好?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "各有優勢。Gemini 免費額度更大方、Context Window 更大。ChatGPT 中文品質更好、API 生態系更完整。建議兩個都試試看。"
      }
    },
    {
      "@type": "Question",
      "name": "Gemini API 可以用來做商業產品嗎?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "免費版不建議用於正式商業產品。商業用途建議使用 Vertex AI 付費方案。"
      }
    },
    {
      "@type": "Question",
      "name": "舊版 SDK 和新版 SDK 有什麼差別?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "舊版是 google-generativeai,新版是 google-genai。2026 年建議用新版,語法更簡潔,功能更完整。"
      }
    },
    {
      "@type": "Question",
      "name": "Gemini 支援繁體中文嗎?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "支援,但中文品質不如 Claude。常見問題包括偶爾簡繁混用、部分台灣用語理解不精確。對中文品質要求很高建議用 Claude Sonnet。"
      }
    }
  ]
}
AI API
上一篇
Gemini API vs OpenAI API|2026 年功能、定價與整合難度完整評測
下一篇
Gemini API Python 串接教學:2026 從零開始呼叫 Google AI 模型