API Gemini Developer

Receba uma chave da API Gemini e faça sua primeira solicitação de API em minutos.

Se você definir a chave de API como a variável de ambiente GEMINI_API_KEY, ela será detectada automaticamente pelo cliente ao usar as bibliotecas da API Gemini. Caso contrário, será necessário transmitir sua chave de API como um argumento ao inicializar o cliente.

Python

from google import genai

# The client gets the API key from the environment variable `GEMINI_API_KEY`.
client = 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";

// The client gets the API key from the environment variable `GEMINI_API_KEY`.
const ai = new GoogleGenAI({});

async function main() {
  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash",
    contents: "Explain how AI works in a few words",
  });
  console.log(response.text);
}

await main();

Go

package main

import (
    "context"
    "fmt"
    "log"
    "google.golang.org/genai"
)

func main() {
    ctx := context.Background()
    // The client gets the API key from the environment variable `GEMINI_API_KEY`.
    client, err := genai.NewClient(ctx, nil))
    if err != 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,
    )
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(result.Text())
}

Java

package com.example;

import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;

public class GenerateTextFromTextInput {
  public static void main(String[] args) {
    // The client gets the API key from the environment variable `GEMINI_API_KEY`.
    Client client = new Client();

    GenerateContentResponse response =
        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' \
  -X POST \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "Explain how AI works in a few words"
          }
        ]
      }
    ]
  }'

Conheça os modelos

Usar o Gemini no Google AI Studio

Explore a API

Geração de imagens nativa

Gere e edite imagens altamente contextualizadas de forma nativa com o Gemini 2.0 Flash.

Explorar o contexto longo

Insira milhões de tokens nos modelos do Gemini e extraia insights de imagens, vídeos e documentos não estruturados.

Gerar saídas estruturadas

Restrição do Gemini para responder com JSON, um formato de dados estruturado adequado para processamento automatizado.

Começar a criar com a API Gemini

Primeiros passos
OSZAR »