Gemini Developer API и платформа Gemini

При разработке решений на основе генеративного искусственного интеллекта с помощью Gemini Google предлагает два API-продукта: Gemini Developer API и Gemini platform API.

Gemini Developer API – это самый быстрый способ создавать, запускать и масштабировать приложения на основе Gemini. Большинству разработчиков следует использовать Gemini Developer API, если только им не нужны специальные корпоративные средства управления.

Платформа Gemini предлагает комплексную экосистему готовых к использованию в корпоративной среде функций и сервисов для создания и развертывания приложений на основе генеративного искусственного интеллекта с поддержкой Google Cloud.

Недавно мы упростили перенос данных между этими сервисами. Теперь Gemini Developer API и Gemini Platform API доступны через единый Google GenAI SDK и Interactions API.

Сравнение кода: API взаимодействий (рекомендуется)

Interactions API – это рекомендуемый способ создания приложений с использованием моделей и агентов Gemini. В приведенных ниже примерах сравнивается генерация текста с помощью Gemini Developer API и платформы Gemini.

Python

Вы можете получить доступ к Gemini Developer API и сервисам платформы Gemini через библиотеку google-genai (>= 2.3.0). Инструкции по установке google-genai приведены на странице библиотек.

Gemini Developer API

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.8-flash",
    input="Explain how AI works in a few words",
)
print(interaction.output_text)

Gemini platform API

from google import genai

client = genai.Client(
    enterprise=True, project="your-project-id", location="global"
)

interaction = client.interactions.create(
    model="gemini-3.8-flash",
    input="Explain how AI works in a few words",
)
print(interaction.output_text)

JavaScript и TypeScript

Вы можете получить доступ к Gemini Developer API и сервисам платформы Gemini через библиотеку @google/genai (>= 2.3.0). Инструкции по установке @google/genai приведены на странице библиотек.

Gemini Developer API

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({});

const interaction = await ai.interactions.create({
  model: "gemini-3.8-flash",
  input: "Explain how AI works in a few words",
});
console.log(interaction.output_text);

Gemini platform API

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({
  enterprise: true,
  project: "your_project",
  location: "global",
});

const interaction = await ai.interactions.create({
  model: "gemini-3.8-flash",
  input: "Explain how AI works in a few words",
});
console.log(interaction.output_text);

Сравнение кода: API generateContent

Мы рекомендуем использовать Interactions API для новых проектов, но API generateContent по-прежнему поддерживается.

Python

Вы можете получить доступ к Gemini Developer API и сервисам платформы Gemini с помощью библиотеки google-genai. Инструкции по установке google-genai приведены на странице библиотек.

Gemini Developer API

from google import genai

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3.8-flash", contents="Explain how AI works in a few words"
)
print(response.text)

Gemini platform API

from google import genai

client = genai.Client(
    vertexai=True, project='your-project-id', location='us-central1'
)

response = client.models.generate_content(
    model="gemini-3.8-flash", contents="Explain how AI works in a few words"
)
print(response.text)

JavaScript и TypeScript

Вы можете получить доступ к Gemini Developer API и сервисам платформы Gemini с помощью библиотеки @google/genai. Инструкции по установке @google/genai приведены на странице библиотек.

Gemini Developer API

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({});

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

main();

Gemini platform API

import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({
  vertexai: true,
  project: 'your_project',
  location: 'your_location',
});

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

main();

Проложить маршрут

Вы можете получить доступ к Gemini Developer API и сервисам платформы Gemini с помощью библиотеки google.golang.org/genai. Инструкции по установке google.golang.org/genai приведены на странице библиотек.

Gemini Developer API

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

// Your Google API key
const apiKey = "your-api-key"

func main() {
  ctx := context.Background()
  client, err := genai.NewClient(ctx, nil)
  if err != nil {
      log.Fatal(err)
  }

  // Call the GenerateContent method.
  result, err := client.Models.GenerateContent(ctx, "gemini-3.8-flash", genai.Text("Tell me about New York?"), nil)

}

Gemini platform API

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

// Your Google Cloud project
const project = "your-project"

// A Google Cloud location like "us-central1"
const location = "some-gcp-location"

func main() {
  ctx := context.Background()
  client, err := genai.NewClient(ctx, &genai.ClientConfig
  {
        Project:  project,
      Location: location,
      Backend:  genai.BackendVertexAI,
  })

  // Call the GenerateContent method.
  result, err := client.Models.GenerateContent(ctx, "gemini-3.8-flash", genai.Text("Tell me about New York?"), nil)

}

Другие варианты использования и платформы

Информацию о других платформах и примерах использования можно найти в документации по Gemini Developer API и документации по платформе Gemini.

Что нужно учитывать при переносе

При переносе:

Если вам больше не нужен ключ Gemini API для Gemini Developer API, удалите его в соответствии с рекомендациями по обеспечению безопасности.

Чтобы удалить ключ API, выполните следующие действия:

  1. Откройте страницу Google Cloud API Credentials (Учетные данные API Google Cloud).

  2. Найдите ключ API, который хотите удалить, и нажмите на значок Действия.

  3. Выберите Удалить ключ API.

  4. В модальном окне Delete credential (Удаление учетных данных) выберите Delete (Удалить).

    После удаления ключа API может пройти несколько минут, прежде чем изменение распространится в системе. Когда процесс завершится, трафик, использующий удаленный ключ API, будет отклоняться.

Дальнейшие действия