[model] gemini-2.5-flash-lite (free) === ###### tags: `AI / Google / Models` ###### tags: `AI`, `Google`, `Models`, `gemini-2.5-flash-lite`, `AI Studios`, `free` <br> [TOC] <br> ## Tutorial (舊版) > 舊版不需要建立 project 1. https://aistudio.google.com/prompts/new_chat ![](https://hackmd.io/_uploads/r1sS4Uu-ee.png) 點擊上方的 "[Get API Key](https://aistudio.google.com/apikey)" 2. 再點擊 "Create API Key" 創建一把 free api key 3. 發 request 測試 ```bash GEMINI_API_KEY=<gemini-api-key> curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent?key=${GEMINI_API_KEY}" \ -H 'Content-Type: application/json' \ -X POST \ -d '{ "contents": [{ "parts":[{"text": "Explain how AI works"}] }] }' ``` - ### `gemini-2.0-flash` ```json= { "candidates": [ { "content": { "parts": [ { "text": "Okay, let's break down how AI works, from a high-level overview to some more specific concepts. I'll try to keep it as clear and accessible as possible.\n\n**Core Idea: Mimicking Intelligence**\n\nAt its heart, Artificial Intelligence is about creating machines that can perform tasks that typically require human intelligence. This includes things like:\n\n* **Learning:** Improving performance over time based on data.\n* **Problem-solving:** Finding solutions to complex issues.\n* **Decision-making:** Choosing the best course of action.\n* **Perception:** Understanding and interpreting sensory input (e.g., images, sound, text).\n* **Reasoning:** Drawing inferences and conclusions.\n* **Natural Language Processing:** Understanding and generating human language.\n\n**The Building Blocks: Algorithms and Data**\n\nAI systems are built on two key foundations:\n\n1. **Algorithms:** These are sets of instructions (like recipes) that tell the computer how to process information and perform specific tasks. Think of them as the \"brains\" of the AI.\n\n2. **Data:** This is the information that the AI learns from. The more high-quality data an AI has, the better it can learn and perform. Think of it as the \"experience\" of the AI.\n\n**Key Approaches to AI**\n\nThere are many different approaches to building AI systems, but here are some of the most important:\n\n* **Machine Learning (ML):** This is the most common and fastest-growing area of AI. Instead of explicitly programming a computer to do something, you *train* it on data.\n\n * **Supervised Learning:** The AI is given labeled data, meaning the correct answers are provided. It learns to map inputs to outputs.\n * *Example:* Training an AI to recognize cats in images. You provide thousands of images, each labeled \"cat\" or \"not cat.\" The AI learns to identify patterns that distinguish cats from other objects.\n * **Unsupervised Learning:** The AI is given unlabeled data and must find patterns and structures on its own.\n * *Example:* Clustering customers based on their purchasing behavior. The AI identifies groups of customers with similar buying habits without being told what those groups are.\n * **Reinforcement Learning:** The AI learns through trial and error by interacting with an environment. It receives rewards for correct actions and penalties for incorrect ones, gradually learning the optimal strategy.\n * *Example:* Training an AI to play a video game. The AI tries different actions, receives points for winning, and learns which strategies are most effective.\n\n* **Deep Learning (DL):** This is a subfield of machine learning that uses artificial neural networks with many layers (hence \"deep\"). These networks are inspired by the structure of the human brain. Deep learning is particularly good at handling complex patterns and large amounts of data.\n * *Example:* Image recognition, natural language processing, and speech recognition.\n * *How it works:* Data passes through multiple layers of interconnected nodes (artificial neurons). Each layer extracts increasingly complex features from the data. The network adjusts the connections between nodes to improve its accuracy.\n\n* **Rule-Based Systems (Expert Systems):** These systems rely on a set of pre-defined rules to make decisions. A human expert defines these rules, and the AI follows them logically.\n * *Example:* A medical diagnosis system that uses rules to determine a patient's illness based on their symptoms.\n * *Limitation:* Can be inflexible and difficult to update as knowledge evolves.\n\n* **Natural Language Processing (NLP):** Focuses on enabling computers to understand, interpret, and generate human language.\n * *Example:* Chatbots, machine translation, sentiment analysis.\n\n* **Computer Vision:** Enables computers to \"see\" and interpret images and videos.\n * *Example:* Object detection, facial recognition, image classification.\n\n**A Simple Example: Spam Detection**\n\nLet's illustrate with a simplified example of how machine learning can be used for spam detection:\n\n1. **Data Collection:** Gather a large dataset of emails, labeled as either \"spam\" or \"not spam\" (ham).\n\n2. **Feature Extraction:** Identify features in the emails that are indicative of spam. These might include:\n * The presence of certain words (\"viagra,\" \"urgent,\" \"free\")\n * The number of exclamation points\n * The sender's email address\n * The presence of links\n\n3. **Model Training:** Use a machine learning algorithm (e.g., Naive Bayes, Support Vector Machine) to train a model on the labeled data and extracted features. The model learns the relationships between the features and the spam/ham label.\n\n4. **Prediction:** When a new email arrives, extract the same features and feed them into the trained model. The model predicts whether the email is spam or ham based on what it has learned.\n\n5. **Evaluation and Improvement:** Evaluate the model's performance (accuracy, precision, recall) on a separate test dataset. If the performance is not satisfactory, you can:\n * Gather more data\n * Extract different features\n * Try a different algorithm\n * Tune the model's parameters\n\n**Important Concepts and Terms:**\n\n* **Training Data:** Data used to train the AI model.\n* **Test Data:** Data used to evaluate the performance of the trained model on unseen data.\n* **Overfitting:** When a model learns the training data too well and performs poorly on new data. It essentially memorizes the training data instead of learning general patterns.\n* **Underfitting:** When a model is too simple to capture the underlying patterns in the data.\n* **Bias:** Systematic errors or prejudices in the data or algorithm that lead to unfair or inaccurate predictions.\n* **Variance:** The sensitivity of the model to changes in the training data. High variance can lead to overfitting.\n* **Artificial Neural Network (ANN):** A computational model inspired by the structure and function of the human brain.\n* **Nodes (Neurons):** Basic units of an ANN that perform simple calculations.\n* **Layers:** Groups of nodes organized in a hierarchical structure.\n* **Weights:** Values that represent the strength of connections between nodes.\n* **Activation Function:** A function that determines the output of a node based on its input.\n* **Gradient Descent:** An optimization algorithm used to train neural networks by iteratively adjusting the weights to minimize the error.\n\n**Limitations and Challenges**\n\n* **Data Dependency:** AI models often require large amounts of data to train effectively.\n* **Explainability:** Deep learning models can be difficult to understand (black boxes). It can be hard to explain *why* a model made a particular decision.\n* **Bias:** AI models can perpetuate and amplify biases present in the training data.\n* **Ethical Concerns:** AI raises ethical concerns about fairness, privacy, and job displacement.\n* **Computational Resources:** Training complex AI models can require significant computing power.\n* **Generalization:** AI models can struggle to generalize to new situations that are different from the data they were trained on.\n\n**The Future of AI**\n\nAI is rapidly evolving and transforming many industries. Expect to see continued advancements in areas like:\n\n* **Generative AI:** AI that can create new content, such as text, images, and music (e.g., DALL-E, GPT-3).\n* **Robotics:** AI-powered robots that can perform complex tasks in various environments.\n* **Autonomous Vehicles:** Self-driving cars and trucks.\n* **Personalized Medicine:** AI that can analyze patient data to provide personalized treatments.\n* **AI for Science:** AI that can accelerate scientific discovery by analyzing large datasets and generating new hypotheses.\n\n**In Summary**\n\nAI is a powerful technology that uses algorithms and data to mimic human intelligence. Machine learning, especially deep learning, is a dominant approach. While AI offers tremendous potential, it also presents challenges related to data dependency, explainability, bias, and ethics. Understanding these concepts is crucial to navigating the rapidly evolving landscape of AI.\n" } ], "role": "model" }, "finishReason": "STOP", "citationMetadata": { "citationSources": [ { "startIndex": 208, "endIndex": 330, "uri": "https://medium.com/@dplayer/leveraging-ai-in-a-b-testing-revolutionizing-marketing-efficiency-003eee227ce8" }, { "startIndex": 232, "endIndex": 365 }, { "startIndex": 2244, "endIndex": 2365 }, { "startIndex": 6443, "endIndex": 6576 } ] }, "avgLogprobs": -0.20933691731049059 } ], "usageMetadata": { "promptTokenCount": 4, "candidatesTokenCount": 1804, "totalTokenCount": 1808, "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 4 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 1804 } ] }, "modelVersion": "gemini-2.0-flash" } ``` - ### `gemini-2.5-flash-lite` ``` { "candidates": [ { "content": { "parts": [ { "text": "AI, or Artificial Intelligence, is a broad field focused on creating systems that can perform tasks that typically require human intelligence. Instead of explaining every single technique and nuance, let's break down the core concepts and how they generally work.\n\nThink of AI not as a single magical entity, but as a collection of powerful tools and methodologies designed to mimic cognitive functions.\n\nHere's a breakdown of how AI works, focusing on the most prevalent approaches:\n\n## The Core Idea: Learning from Data\n\nAt its heart, most modern AI is driven by the concept of **learning from data**. Instead of explicitly programming every single rule for every possible scenario, AI systems are trained on vast amounts of information. This training allows them to identify patterns, make predictions, and derive insights without being told exactly what to do in each instance.\n\n## Key Components and Concepts:\n\n1. **Data:** This is the lifeblood of AI. It can be anything:\n * **Images:** For visual recognition tasks (e.g., identifying cats in photos).\n * **Text:** For language understanding and generation (e.g., chatbots, translation).\n * **Numbers:** For financial forecasting, scientific research, or predicting customer behavior.\n * **Audio:** For speech recognition or music generation.\n * **Sensor readings:** For robotics, autonomous vehicles, or environmental monitoring.\n\n2. **Algorithms:** These are the sets of instructions and mathematical procedures that AI systems use to process data and learn. Different algorithms are suited for different tasks. Some of the most common include:\n * **Machine Learning (ML):** This is the most dominant subfield of AI. ML algorithms learn from data without being explicitly programmed. They build models that can make predictions or decisions.\n * **Deep Learning (DL):** A subfield of ML that uses artificial neural networks with multiple layers (hence \"deep\"). These networks are inspired by the structure of the human brain and are incredibly powerful for tasks like image and speech recognition.\n * **Natural Language Processing (NLP):** This branch of AI focuses on enabling computers to understand, interpret, and generate human language.\n * **Computer Vision:** This allows computers to \"see\" and interpret images and videos.\n * **Robotics:** While not solely AI, AI is crucial for enabling robots to perceive their environment, make decisions, and act.\n\n3. **Models:** Once an AI algorithm is trained on data, it produces a **model**. This model is essentially a learned representation of the patterns and relationships within the data. It's what the AI uses to perform its task.\n * **Example:** A spam filter AI learns a model that identifies characteristics of spam emails (e.g., certain keywords, sender patterns). When a new email arrives, the model analyzes it and predicts whether it's spam or not.\n\n## How Different Types of AI Learn:\n\nThere are several common ways AI systems learn:\n\n* **Supervised Learning:** The AI is trained on labeled data. This means for each piece of data, there's a correct \"answer\" or \"label.\"\n * **Analogy:** Teaching a child to identify animals by showing them pictures and saying \"this is a dog,\" \"this is a cat.\"\n * **Examples:** Image classification (labeling images with objects), spam detection (labeling emails as spam or not spam), predicting house prices (using past sales data with prices).\n\n* **Unsupervised Learning:** The AI is given unlabeled data and tasked with finding patterns, structures, or relationships within it.\n * **Analogy:** Giving a child a box of toys and letting them sort them by color, size, or type on their own.\n * **Examples:** Customer segmentation (grouping customers with similar purchasing habits), anomaly detection (finding unusual patterns in data), topic modeling (discovering themes in text documents).\n\n* **Reinforcement Learning:** The AI learns by trial and error, interacting with an environment. It receives rewards for desired actions and penalties for undesirable ones, gradually learning to maximize its cumulative reward.\n * **Analogy:** Teaching a dog tricks with treats for correct behavior.\n * **Examples:** Game playing (e.g., AlphaGo beating human Go champions), robotics (training a robot to walk), autonomous driving (learning to navigate safely).\n\n## The Process of Building and Using AI:\n\n1. **Data Collection and Preparation:** Gathering relevant data and cleaning it (removing errors, inconsistencies, and irrelevant information).\n2. **Feature Engineering/Selection:** Identifying and selecting the most important characteristics (features) from the data that the AI will use to learn.\n3. **Choosing an Algorithm:** Selecting the appropriate machine learning or deep learning algorithm for the task.\n4. **Training the Model:** Feeding the prepared data into the chosen algorithm to build the model. This is often computationally intensive.\n5. **Evaluating the Model:** Testing the model's performance on unseen data to ensure it generalizes well and makes accurate predictions.\n6. **Deployment:** Integrating the trained model into an application or system where it can be used to perform its intended task.\n7. **Monitoring and Iteration:** Continuously monitoring the model's performance and retraining it with new data as needed to maintain accuracy and adapt to changing conditions.\n\n## Key Technologies and Concepts Within AI:\n\n* **Neural Networks:** The foundation of deep learning. They consist of interconnected \"neurons\" that process and transmit information.\n* **Backpropagation:** An algorithm used to train neural networks by adjusting the \"weights\" (connections between neurons) to minimize errors.\n* **Natural Language Understanding (NLU) & Natural Language Generation (NLG):** Subfields of NLP that deal with comprehension and creation of human language.\n* **Convolutional Neural Networks (CNNs):** Particularly effective for image and video processing.\n* **Recurrent Neural Networks (RNNs) & Transformers:** Powerful for sequential data like text and time series. Transformers are currently state-of-the-art for many NLP tasks.\n\n## In Summary:\n\nAI is not a single \"thing\" but a field of study and a set of tools. At its core, modern AI excels at **learning complex patterns from vast amounts of data using algorithms**. This learned knowledge is then encapsulated in a **model** that the AI uses to make predictions, decisions, or perform tasks that were once thought to be exclusively human abilities. The continuous advancement in data availability, computational power, and algorithmic sophistication is what drives the rapid progress we see in AI today." } ], "role": "model" }, "finishReason": "STOP", "index": 0 } ], "usageMetadata": { "promptTokenCount": 4, "candidatesTokenCount": 1389, "totalTokenCount": 1393, "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 4 } ] }, "modelVersion": "gemini-2.5-flash-lite", "responseId": "c0uyacbRHJiY0-kP2OiRmAQ" } ``` <br> --- <br> ## Get Code > - [首頁右上角,有 [Get code] 選項](https://aistudio.google.com/prompts/new_chat) > ![image](https://hackmd.io/_uploads/SJNUpakqZx.png) ```bash #!/bin/bash set -e -E GEMINI_API_KEY="$GEMINI_API_KEY" MODEL_ID="gemini-2.5-flash-lite" # 更換模型 GENERATE_CONTENT_API="streamGenerateContent" cat << EOF > request.json { "contents": [ { "role": "user", "parts": [ { "text": "INSERT_INPUT_HERE" }, ] }, ], "generationConfig": { "thinkingConfig": { "thinkingLevel": "HIGH", }, }, } EOF curl \ -X POST \ -H "Content-Type: application/json" \ "https://generativelanguage.googleapis.com/v1beta/models/${MODEL_ID}:${GENERATE_CONTENT_API}?key=${GEMINI_API_KEY}" -d '@request.json' ``` <br> ## 參考資料 - [Everything you need to know about the Gemini API as a developer in less than 5 minutes](https://medium.com/around-the-prompt/5e75343ccff9) - 我該如何測試最新的 Gemini 型號? 如果您想先測試 Gemini 模型(從最新的實驗模型到生產模型的所有內容)而不編寫任何程式碼,您可以前往Google AI Studio。完成測試後,您還可以在 AI Studio 中產生 Gemini API 金鑰(左上角的「取得 API 金鑰」)。 AI Studio 是免費的,而且API 上也有一個慷慨的免費層級,其中包括每天使用 Gemini 1.5 Flash 的 1,500 個請求。 - [Day6 申請可免費使用的主流模型公司 API - Google Gemini](https://ithelp.ithome.com.tw/m/articles/10384139) <br> --- <br> ## 討論 ### Gemini Flash Lite 是免費的嗎?如何使用? - ### gpt-5.4 (2026/03/12) 如果你說的是 **Google 的 Gemini Flash-Lite**,答案是:**有免費層,但要看你怎麼用。** 目前官方文件中可見的主力型號是 **`gemini-2.5-flash-lite`**;另外 Google 也在 2026-03-03 推出了 **`gemini-3.1-flash-lite-preview`**。官方定價頁明確列出 **Gemini 2.5 Flash-Lite 的 Free Tier 為免費**,輸入與輸出都標示 **Free of charge**;Gemini 3 指南也寫明 **3.1 Flash-Lite Preview 在 Gemini API 有 free tier**。([Google AI for Developers][202603012-A-1]) 不過要分清楚兩種情境: **1. Gemini App / 網頁版聊天**:目前 Gemini Apps 的模型選項官方寫的是 **Fast / Thinking / Pro**,不是直接顯示「Flash-Lite」這個名字。([Google Help][202603012-A-2]) **2. Google AI Studio / Gemini API**:這裡才是最直接使用 **Flash-Lite** 的地方,官方模型頁與定價頁都可直接選到 **Gemini 2.5 Flash-Lite**,而且 AI Studio 也是 Google 官方建議的快速起點。([Google AI for Developers][202603012-A-3]) 最簡單的使用方式有兩種: **A. 不寫程式:用 Google AI Studio** 到 Google AI Studio 登入後,直接選模型,挑 **Gemini 2.5 Flash-Lite**,就可以開始測試提示詞;官方首頁也提供「Sign in to Google AI Studio」與「Get your API key」入口。([Google AI for Developers][202603012-A-4]) **B. 寫程式:用 Gemini API** 官方文件說,使用 Gemini API 需要先在 Google AI Studio 建立 **API key**,而且所有 API 呼叫都要帶上 API key。([Google AI for Developers][202603012-A-5]) 最短流程是這樣: 1. 到 Google AI Studio 登入並建立 API key。([Google AI for Developers][202603012-A-4]) 2. 模型填 `gemini-2.5-flash-lite`。([Google AI for Developers][202603012-A-1]) 3. 用 REST API、官方 SDK,或 OpenAI 相容方式呼叫。官方也明講 Gemini 可用 **OpenAI libraries** 搭配少量修改來呼叫。([Google AI for Developers][202603012-A-6]) 例如用 REST 的概念會像這樣: ```bash curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent" \ -H "x-goog-api-key: YOUR_GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "contents": [ { "parts": [ { "text": "請用繁體中文簡單介紹台南。" } ] } ] }' ``` 上面這個寫法符合官方 API 文件的基本做法:用 `x-goog-api-key` 傳 API key,對指定模型呼叫 `generateContent`。([Google AI for Developers][202603012-A-7]) 你若只是想「免費試玩」,**先用 Google AI Studio 最省事**。你若是想把它接到自己的程式、網站或工具裡,**再申請 API key 用 `gemini-2.5-flash-lite`** 最直接。至於 **Gemini App**,你通常看到的是 **Fast / Thinking / Pro** 這種模式名稱,不一定能直接選到「Flash-Lite」本名。([Google AI for Developers][202603012-A-4]) 你要的話,我可以下一則直接幫你整理成: **「完全新手版:5 分鐘註冊與實測教學」**,或 **「Python / OpenAI 相容寫法範例」**。 [202603012-A-1]: https://ai.google.dev/gemini-api/docs/pricing "Gemini Developer API pricing  |  Gemini API  |  Google AI for Developers" [202603012-A-2]: https://support.google.com/gemini/answer/13275745?co=GENIE.Platform%3DAndroid&hl=en&utm_source=chatgpt.com "Use Gemini Apps - Android" [202603012-A-3]: https://ai.google.dev/gemini-api/docs/models "Models  |  Gemini API  |  Google AI for Developers" [202603012-A-4]: https://ai.google.dev/aistudio "Google AI Studio | Gemini API  |  Google AI for Developers" [202603012-A-5]: https://ai.google.dev/gemini-api/docs/api-key?utm_source=chatgpt.com "Using Gemini API keys | Google AI for Developers" [202603012-A-6]: https://ai.google.dev/gemini-api/docs/openai "OpenAI compatibility  |  Gemini API  |  Google AI for Developers" [202603012-A-7]: https://ai.google.dev/api?utm_source=chatgpt.com "Gemini API reference | Google AI for Developers" <br> --- <br> ### 給予 Step-by-Step 操作 - ### gpt-5.4 (2026/03/12) 好,我改成**真的可以照著點**的版本。 你現在要做的事情,分成 2 條路: 1. **先在 Google AI Studio 拿到 API key** 2. **再選 `gemini-2.5-flash-lite` 來測試或產生程式碼** Google 官方文件目前明確寫到:Gemini API 需要 API key;Google AI Studio 是最快開始的地方;而 **`gemini-2.5-flash-lite`** 是目前可用的穩定模型代碼。([Google AI for Developers][202603012-B-1]) --- ## 先做第 1 件事:拿到 API key ### 第 1 步:打開 Google AI Studio > https://aistudio.google.com/prompts/new_chat (← 應該是要進到這網站) 進入 Google AI Studio 首頁,點 **「Sign in to Google AI Studio」** 登入你的 Google 帳號。官方首頁也有 **「Get a Gemini API Key」** 的入口。([Google AI for Developers][202603012-B-2]) ### 第 2 步:第一次使用就先接受條款 如果你是第一次進去,通常會先看到服務條款或使用同意畫面,照畫面完成即可。官方文件說,**新使用者在接受 Terms of Service 後,Google AI Studio 會建立預設的 Google Cloud Project 與 API key,方便快速開始**。([Google AI for Developers][202603012-B-1]) ### 第 3 步:進到 API Keys 頁面 登入後,進入 **Dashboard**,再找到 **API Keys** 頁面。官方文件明確寫到:你可以在 Google AI Studio 的 **API Keys page** 建立與管理所有 Gemini API keys。([Google AI for Developers][202603012-B-1]) ### 第 4 步:建立 API key 在 **API Keys** 頁面建立新的 key。建立完成後,把它先複製下來,稍後會用到。官方也提到,API key 可以先暫時直接放進測試程式,但正式使用時不建議硬寫在程式裡,之後應改成環境變數。([Google AI for Developers][202603012-B-1]) --- ## 如果你這裡沒看到可以建立 key,照下面做 有些人不是全新帳號,或本來就有 Google Cloud 專案,這時不一定會自動幫你建好。 ### 第 5 步:匯入 Google Cloud 專案 到 **Dashboard → Projects**,按 **Import projects**,搜尋你的 Google Cloud project 名稱或 project ID,匯入後再回到 **API Keys** 頁面建立 key。官方文件有列出這個流程。([Google AI for Developers][202603012-B-1]) ### 第 6 步:如果你根本沒有 project 官方文件也寫到:如果還沒有任何 project,你必須先建立新的 project,或從 Google Cloud 匯入一個 project,再建立 key。([Google AI for Developers][202603012-B-1]) --- ## 再做第 2 件事:在 AI Studio 直接測試 `gemini-2.5-flash-lite` ### 第 7 步:回到 AI Studio 的 Chat 畫面 打開 Google AI Studio 後,左側預設會是 **Chat**。官方 quickstart 文件明確寫到,開啟 AI Studio 後,**Chat 會預先被選取**。([Google AI for Developers][202603012-B-3]) ### 第 8 步:選模型 在畫面上方或模型選單中,找到並選擇: ```text gemini-2.5-flash-lite ``` 官方模型文件明確列出穩定模型代碼就是 **`gemini-2.5-flash-lite`**。([Google AI for Developers][202603012-B-4]) ### 第 9 步:輸入測試提示詞 你可以先輸入最簡單的內容,例如: ```text 請用繁體中文介紹台南,100 字內。 ``` 然後按執行。Google AI Studio 的 quickstart 文件說,它就是用來快速試 prompt、調整模型設定、做聊天測試的。([Google AI for Developers][202603012-B-3]) ### 第 10 步:看到回應就代表模型可用了 只要你有收到回應,就表示: * AI Studio 可用 * 模型選擇成功 * 你的帳號與專案基本上沒問題([Google AI for Developers][202603012-B-3]) --- ## 接著把它變成程式呼叫 ### 第 11 步:在 AI Studio 直接按「Get code」 官方 quickstart 文件寫得很清楚:當你準備開始開發時,可以按 **「Get code」**,再選你要的程式語言,AI Studio 會幫你產生 Gemini API 的範例。([Google AI for Developers][202603012-B-3]) ### 第 12 步:你也可以自己先用 curl 測試 Gemini API 官方參考文件說,所有請求都要帶上 `x-goog-api-key` header。([Google AI for Developers][202603012-B-5]) 範例可以這樣寫: ```bash curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent" \ -H "x-goog-api-key: YOUR_GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -X POST \ -d '{ "contents": [ { "parts": [ { "text": "請用繁體中文介紹台南,100字內。" } ] } ] }' ``` 上面這個寫法符合官方 API 文件的呼叫方式,只是把模型名稱換成 **`gemini-2.5-flash-lite`**。模型代碼來自官方模型頁,API key header 來自官方 API reference。([Google AI for Developers][202603012-B-4]) --- ## 免費嗎?你現在這樣用通常是免費起步 Google 官方定價頁目前寫明,Gemini Developer API 有 **Free** 方案,包含: * limited access to certain models * free input & output tokens * Google AI Studio access([Google AI for Developers][202603012-B-6]) 所以你現在照上面這套流程,通常就是走 **免費起步** 的方式。([Google AI for Developers][202603012-B-6]) --- ## 最容易卡住的地方 ### 1. 找不到 API key 頁面 先去 **Dashboard**,再找 **API Keys**。如果還是沒有,通常要先有 project;沒有的話就到 **Projects** 先匯入或建立。([Google AI for Developers][202603012-B-1]) ### 2. 找不到 `gemini-2.5-flash-lite` 請確認你是在 **Google AI Studio / Gemini API** 的模型選擇,不是一般 Gemini App 的聊天模式。官方模型頁有列出這個模型,而且有 **Try in Google AI Studio** 入口。([Google AI for Developers][202603012-B-4]) ### 3. API 呼叫失敗 最常見原因是: * API key 沒貼對 * header 沒帶 `x-goog-api-key` * 模型名稱打錯 官方 API 文件有明確要求帶這個 header。([Google AI for Developers][202603012-B-5]) --- ## 最短版操作摘要 1. 打開 Google AI Studio 並登入。([Google AI for Developers][202603012-B-2]) 2. 到 **Dashboard → API Keys** 建立 key。([Google AI for Developers][202603012-B-1]) 3. 回到 **Chat** 畫面。([Google AI for Developers][202603012-B-3]) 4. 模型選 **`gemini-2.5-flash-lite`**。([Google AI for Developers][202603012-B-4]) 5. 輸入 prompt 測試。([Google AI for Developers][202603012-B-3]) 6. 要寫程式就按 **Get code**,或用 curl 呼叫 API。([Google AI for Developers][202603012-B-3]) 下一則我可以直接幫你寫成更細的版本: **「我看到哪個按鈕就點哪個按鈕」**,包含 **AI Studio 畫面導覽 + Python 範例**。 [202603012-B-1]: https://ai.google.dev/gemini-api/docs/api-key "Using Gemini API keys  |  Google AI for Developers" [202603012-B-2]: https://ai.google.dev/aistudio?utm_source=chatgpt.com "Google AI Studio | Gemini API" [202603012-B-3]: https://ai.google.dev/gemini-api/docs/ai-studio-quickstart "Google AI Studio quickstart  |  Gemini API  |  Google AI for Developers" [202603012-B-4]: https://ai.google.dev/gemini-api/docs/models/gemini-2.5-flash-lite "Gemini 2.5 Flash-Lite  |  Gemini API  |  Google AI for Developers" [202603012-B-5]: https://ai.google.dev/api "Gemini API reference  |  Google AI for Developers" [202603012-B-6]: https://ai.google.dev/gemini-api/docs/pricing "Gemini Developer API pricing  |  Gemini API  |  Google AI for Developers"