Obtenez une clé API Gemini et effectuez votre première requête API en quelques minutes.
Python
fromgoogleimportgenaiclient=genai.Client()response=client.models.generate_content(model="gemini-2.5-flash",contents="Explain how AI works in a few words",)print(response.text)
JavaScript
import{GoogleGenAI}from"@google/genai";constai=newGoogleGenAI({});asyncfunctionmain(){constresponse=awaitai.models.generateContent({model:"gemini-2.5-flash",contents:"Explain how AI works in a few words",});console.log(response.text);}awaitmain();
Go
packagemainimport("context""fmt""log""google.golang.org/genai")funcmain(){ctx:=context.Background()client,err:=genai.NewClient(ctx,nil)iferr!=nil{log.Fatal(err)}result,err:=client.Models.GenerateContent(ctx,"gemini-2.5-flash",genai.Text("Explain how AI works in a few words"),nil,)iferr!=nil{log.Fatal(err)}fmt.Println(result.Text())}
Java
packagecom.example;importcom.google.genai.Client;importcom.google.genai.types.GenerateContentResponse;publicclassGenerateTextFromTextInput{publicstaticvoidmain(String[]args){Clientclient=newClient();GenerateContentResponseresponse=client.models.generateContent("gemini-2.5-flash","Explain how AI works in a few words",null);System.out.println(response.text());}}
REST
curl"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.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 in a few words" } ] } ] }'
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/29 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/08/29 (UTC)."],[],[],null,["Gemini Developer API \n[Get a Gemini API Key](https://aistudio.google.com/apikey)\n\nGet a Gemini API key and make your first API request in minutes. \n\nPython \n\n from google import genai\n\n client = genai.Client()\n\n response = client.models.generate_content(\n model=\"gemini-2.5-flash\",\n contents=\"Explain how AI works in a few words\",\n )\n\n print(response.text)\n\nJavaScript \n\n import { GoogleGenAI } from \"@google/genai\";\n\n const ai = new GoogleGenAI({});\n\n async function main() {\n const response = await ai.models.generateContent({\n model: \"gemini-2.5-flash\",\n contents: \"Explain how AI works in a few words\",\n });\n console.log(response.text);\n }\n\n await main();\n\nGo \n\n package main\n\n import (\n \"context\"\n \"fmt\"\n \"log\"\n \"google.golang.org/genai\"\n )\n\n func main() {\n ctx := context.Background()\n client, err := genai.NewClient(ctx, nil)\n if err != nil {\n log.Fatal(err)\n }\n\n result, err := client.Models.GenerateContent(\n ctx,\n \"gemini-2.5-flash\",\n genai.Text(\"Explain how AI works in a few words\"),\n nil,\n )\n if err != nil {\n log.Fatal(err)\n }\n fmt.Println(result.Text())\n }\n\nJava \n\n package com.example;\n\n import com.google.genai.Client;\n import com.google.genai.types.GenerateContentResponse;\n\n public class GenerateTextFromTextInput {\n public static void main(String[] args) {\n Client client = new Client();\n\n GenerateContentResponse response =\n client.models.generateContent(\n \"gemini-2.5-flash\",\n \"Explain how AI works in a few words\",\n null);\n\n System.out.println(response.text());\n }\n }\n\nREST \n\n curl \"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.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 {\n \"parts\": [\n {\n \"text\": \"Explain how AI works in a few words\"\n }\n ]\n }\n ]\n }'\n\nMeet the models\n\n\n[Use Gemini in Google AI Studio](https://aistudio.google.com) \n\n2.5 Pro\nspark\n\n\nOur most powerful thinking model with features for complex reasoning and much more\n[](/gemini-api/docs/models#gemini-2.5-pro) \n\n2.5 Flash\nspark\n\n\nOur newest multimodal model, with next generation features and improved\ncapabilities\n[](/gemini-api/docs/models/gemini#gemini-2.5-flash) \n\n2.5 Flash-Lite\nspark\n\n\nOur fastest and most cost-efficient multimodal model with great performance\nfor high-frequency tasks\n[](/gemini-api/docs/models/gemini#gemini-2.5-flash-lite) \n\nVeo 3\nvideo_library\n\n\nOur state of the art video generation model\n[](/gemini-api/docs/video) \n\nImagen 4\nimagesmode\n\n\nOur highest quality image generation model that creates stunning visuals\n[](/gemini-api/docs/imagen) \n\nGemini Embeddings\ndata_array\n\n\nOur first Gemini embedding model, designed for production RAG workflows\n[](/gemini-api/docs/embeddings)\n\nExplore the API \n\nNative Image Generation\n\nGenerate and edit highly contextual images natively with Gemini 2.5 Flash Image.\n[](/gemini-api/docs/image-generation) \n\nExplore long context\n\nInput millions of tokens to Gemini models and derive understanding from unstructured images, videos, and documents.\n[](/gemini-api/docs/long-context) \n\nGenerate structured outputs\n\nConstrain Gemini to respond with JSON, a structured data format suitable for automated processing.\n[](/gemini-api/docs/structured-output) \n\nStart building with the Gemini API [Get started](/gemini-api/docs/quickstart)"]]