In wenigen Minuten einen Gemini API-Schlüssel erhalten und die erste API-Anfrage senden.
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();
Ok
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" } ] } ] }'
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-22 (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 2\nvideo_library\n\n\nOur state of the art video generation model\n[](/gemini-api/docs/models#veo-2) \n\nImagen 4\nimagesmode\n\n\nOur highest quality image generation model that creates stunning visuals\n[](/gemini-api/docs/models#imagen-4) \n\nGemini Embeddings\ndata_array\n\n\nOur first Gemini embedding model, designed for production RAG workflows\n[](/gemini-api/docs/models#gemini-embedding)\n\nExplore the API \n\nNative Image Generation\n\nGenerate and edit highly contextual images natively with Gemini 2.0 Flash.\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)"]]