Gemini API SDK のデフォルトは 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 }'"]]