เอกสารนี้ให้ภาพรวมระดับสูงเกี่ยวกับความแตกต่างระหว่าง Gemini API เวอร์ชัน v1 กับ v1beta
v1: API เวอร์ชันที่เสถียร ฟีเจอร์ในเวอร์ชันเสถียรจะ ได้รับการสนับสนุนอย่างเต็มที่ตลอดอายุการใช้งานของเวอร์ชันหลัก หากมีการเปลี่ยนแปลงที่ทำให้ใช้งานร่วมกันไม่ได้ เราจะสร้าง API เวอร์ชันหลักถัดไปและเลิกใช้งานเวอร์ชันที่มีอยู่หลังจากผ่านไประยะเวลาที่เหมาะสม เราอาจนำการเปลี่ยนแปลงที่ไม่ทำให้เกิดข้อผิดพลาดมาใช้กับ API โดยไม่ต้องเปลี่ยนเวอร์ชันหลัก
SDK ของ Gemini API จะใช้ v1beta เป็นค่าเริ่มต้น แต่คุณเลือกใช้เวอร์ชันอื่นได้ โดยตั้งค่าเวอร์ชัน API ตามที่แสดงในตัวอย่างโค้ดต่อไปนี้
Python
fromgoogleimportgenaiclient=genai.Client(http_options={'api_version':'v1alpha'})response=client.models.generate_content(model='gemini-2.0-flash',contents="Explain how AI works",)print(response.text)
JavaScript
import{GoogleGenAI}from"@google/genai";constai=newGoogleGenAI({httpOptions:{apiVersion:"v1alpha"},});asyncfunctionmain(){constresponse=awaitai.models.generateContent({model:"gemini-2.0-flash",contents:"Explain how AI works",});console.log(response.text);}awaitmain();
REST
curl"https://generativelanguage.googleapis.com/v1/models/gemini-1.5-flash:generateContent"\ -H"x-goog-api-key: $GEMINI_API_KEY"\ -H'Content-Type: application/json'\ -XPOST\ -d'{ "contents": [{ "parts":[{"text": "Explain how AI works."}] }] }'
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-08-22 UTC"],[],[],null,["# API versions explained\n\nThis document provides a high-level overview of the differences between the `v1`\nand `v1beta` versions of the Gemini API.\n\n- **v1**: Stable version of the API. Features in the stable version are fully-supported over the lifetime of the major version. If there are any breaking changes, then the next major version of the API will be created and the existing version will be deprecated after a reasonable period of time. Non-breaking changes may be introduced to the API without changing the major version.\n- **v1beta**: This version includes early-access features that may be under development and is subject to rapid and breaking changes. There is also no guarantee that the features in the Beta version will move to the stable version. Due to this instability, you should consider not launching production applications with this version.\n\n| Feature | v1 | v1beta |\n|----------------------------------------------------|----|--------|\n| Generate Content - Text-only input | | |\n| Generate Content - Text-and-image input | | |\n| Generate Content - Text output | | |\n| Generate Content - Multi-turn conversations (chat) | | |\n| Generate Content - Function calls | | |\n| Generate Content - Streaming | | |\n| Embed Content - Text-only input | | |\n| Generate Answer | | |\n| Semantic retriever | | |\n\n- - Supported\n- - Will never be supported\n\nConfigure API version in an SDK\n-------------------------------\n\nThe Gemini API SDK's default to `v1beta`, but you can opt to use other versions\nby setting the API version as shown in the following code sample: \n\n### Python\n\n from google import genai\n\n client = genai.Client(http_options={'api_version': 'v1alpha'})\n\n response = client.models.generate_content(\n model='gemini-2.0-flash',\n contents=\"Explain how AI works\",\n )\n\n print(response.text)\n\n### JavaScript\n\n import { GoogleGenAI } from \"@google/genai\";\n\n const ai = new GoogleGenAI({\n httpOptions: { apiVersion: \"v1alpha\" },\n });\n\n async function main() {\n const response = await ai.models.generateContent({\n model: \"gemini-2.0-flash\",\n contents: \"Explain how AI works\",\n });\n console.log(response.text);\n }\n\n await main();\n\n### REST\n\n curl \"https://generativelanguage.googleapis.com/v1/models/gemini-1.5-flash:generateContent\" \\\n -H \"x-goog-api-key: $GEMINI_API_KEY\" \\\n -H 'Content-Type: application/json' \\\n -X POST \\\n -d '{\n \"contents\": [{\n \"parts\":[{\"text\": \"Explain how AI works.\"}]\n }]\n }'"]]