از نسخه پیش‌نمایش Vertex AI در SDKهای Firebase به Logic SDKهای Firebase


Firebase AI Logic و SDK های کلاینت آن قبلاً " Vertex AI in Firebase " نامیده می‌شدند. برای انعکاس بهتر خدمات و ویژگی‌های توسعه‌یافته ما (به عنوان مثال، اکنون از Gemini Developer API پشتیبانی می‌کنیم!)، نام خدمات خود را به Firebase AI Logic تغییر دادیم و بسته‌بندی مجدد کردیم .

برای دسترسی ایمن به مدل‌های هوش مصنوعی مولد گوگل مستقیماً از طریق برنامه‌های تلفن همراه یا وب خود، اکنون می‌توانید یک ارائه‌دهنده « Gemini API » را انتخاب کنید - یا API پلتفرم عامل Gemini که مدت‌هاست در دسترس است (قبلاً Vertex AI) یا اکنون API توسعه‌دهنده Gemini . این بدان معناست که اکنون می‌توانید از API توسعه‌دهنده Gemini استفاده کنید که یک سطح بدون هزینه با محدودیت‌ها و سهمیه‌های معقول ارائه می‌دهد.

مروری بر مراحل مهاجرت به SDK های Firebase AI Logic

  • مرحله ۱ : بهترین ارائه‌دهنده «Gemini API» را برای برنامه و موارد استفاده خود انتخاب کنید.

  • مرحله ۲ : فعال کردن API های مورد نیاز

  • مرحله ۳ : کتابخانه مورد استفاده در برنامه خود را به‌روزرسانی کنید.

  • مرحله ۴ : مقداردهی اولیه را در برنامه خود به‌روزرسانی کنید.

  • مرحله ۵ : کد خود را بسته به ویژگی‌هایی که استفاده می‌کنید، به‌روزرسانی کنید.

مرحله ۱ : بهترین ارائه‌دهنده «Gemini API» را برای برنامه خود انتخاب کنید

با این مهاجرت، شما می‌توانید ارائه‌دهنده‌ی « Gemini API » را انتخاب کنید:

  • SDK های قدیمی « Vertex AI in Firebase » فقط می‌توانستند از API مربوط به Agent Platform Gemini (که قبلاً Vertex AI نام داشت) استفاده کنند.

  • کیت‌های توسعه نرم‌افزار (SDK) جدید Firebase AI Logic به شما امکان می‌دهند انتخاب کنید که می‌خواهید کدام ارائه‌دهنده « Gemini API » را مستقیماً از برنامه تلفن همراه یا وب خود فراخوانی کنید - یا Gemini Developer API یا Agent Platform Gemini API (که قبلاً Vertex AI نام داشت) .

تفاوت‌های بین استفاده از دو ارائه‌دهنده‌ی API مربوط به Gemini را بررسی کنید، به خصوص از نظر ویژگی‌های پشتیبانی‌شده، قیمت‌گذاری و محدودیت‌های نرخ. فقط برای یک مثال، API توسعه‌دهندگان Gemini از ارائه فایل‌ها با استفاده از URLهای Cloud Storage پشتیبانی نمی‌کند، اما اگر می‌خواهید از ردیف رایگان و سهمیه‌ی معقول آن بهره‌مند شوید، می‌تواند انتخاب خوبی باشد.

مرحله ۲ : فعال کردن API های مورد نیاز

مطمئن شوید که تمام APIهای مورد نیاز در پروژه Firebase شما فعال هستند تا بتوانید از ارائه‌دهنده « Gemini API » انتخابی خود استفاده کنید.

توجه داشته باشید که می‌توانید هر دو ارائه‌دهنده API را همزمان در پروژه خود فعال کنید.

  1. وارد کنسول Firebase شوید و سپس پروژه Firebase خود را انتخاب کنید.

  2. در کنسول Firebase ، به بخش سرویس‌های هوش مصنوعی > منطق هوش مصنوعی بروید.

  3. برای شروع یک گردش کار هدایت‌شده که به شما در تنظیم APIها و منابع مورد نیاز پروژه‌تان کمک می‌کند، روی «شروع به کار» کلیک کنید.

  4. ارائه‌دهنده‌ی «Gemini API» را که می‌خواهید با Firebase AI Logic SDKs استفاده کنید، انتخاب کنید. در صورت تمایل، همیشه می‌توانید ارائه‌دهنده‌ی API دیگری را بعداً تنظیم و استفاده کنید.

    • رابط برنامه‌نویسی کاربردی Gemini - پرداخت هزینه اختیاری (در طرح قیمت‌گذاری بدون هزینه Spark موجود است)
      گردش کار کنسول، APIهای مورد نیاز را فعال کرده و یک کلید API جمینی در پروژه شما ایجاد می‌کند.
      این کلید API مربوط به Gemini را به کدبیس برنامه خود اضافه نکنید . اطلاعات بیشتر.

    • رابط برنامه‌نویسی کاربردی پلتفرم عامل Gemini (که قبلاً Vertex AI نام داشت) - نیاز به پرداخت صورتحساب دارد (نیازمند طرح قیمت‌گذاری Blaze با قابلیت پرداخت در محل است)
      گردش کار کنسول، APIهای مورد نیاز را در پروژه شما فعال می‌کند.

  5. برای به‌روزرسانی کتابخانه و مقداردهی اولیه در برنامه خود، در این راهنمای مهاجرت ادامه دهید.

مرحله ۳ : به‌روزرسانی کتابخانه مورد استفاده در برنامه

کدبیس برنامه خود را برای استفاده از کتابخانه Firebase AI Logic به‌روزرسانی کنید.

سویفت

  1. در Xcode، در حالی که پروژه برنامه شما باز است، بسته Firebase خود را با استفاده از یکی از گزینه‌های زیر به نسخه ۱۱.۱۳.۰ یا بالاتر به‌روزرسانی کنید:

    • گزینه ۱ : به‌روزرسانی همه بسته‌ها: به مسیر File > Packages > Update to Latest Package Versions بروید.

    • گزینه ۲ : به‌روزرسانی جداگانه فایربیس: در بخشی به نام Package Dependencies به پکیج فایربیس بروید. روی پکیج فایربیس کلیک راست کنید و سپس Update Package را انتخاب کنید.

  2. مطمئن شوید که بسته Firebase اکنون نسخه 11.13.0 یا بالاتر را نشان می‌دهد. اگر اینطور نیست، بررسی کنید که الزامات بسته‌بندی مشخص‌شده شما امکان به‌روزرسانی به نسخه 11.13.0 یا بالاتر را فراهم می‌کند.

  3. هدف برنامه خود را در ویرایشگر پروژه انتخاب کنید و سپس به بخش چارچوب‌ها، کتابخانه‌ها و محتوای جاسازی‌شده بروید.

  4. کتابخانه جدید را اضافه کنید: دکمه + را انتخاب کنید و سپس FirebaseAI را از بسته Firebase اضافه کنید.

  5. پس از اتمام انتقال برنامه خود (به بخش‌های باقیمانده در این راهنما مراجعه کنید)، حتماً کتابخانه قدیمی را حذف کنید:
    FirebaseVertexAI-Preview را انتخاب کنید و سپس دکمه‌ی را فشار دهید.

Kotlin

  1. در فایل Gradle ماژول (سطح برنامه) خود (معمولاً <project>/<app-module>/build.gradle.kts یا <project>/<app-module>/build.gradle )، وابستگی‌های قدیمی را (در صورت وجود) با موارد زیر جایگزین کنید.

    توجه داشته باشید که ممکن است مهاجرت کدبیس برنامه (به بخش‌های باقیمانده این راهنما مراجعه کنید) قبل از حذف وابستگی قدیمی، آسان‌تر باشد.

    // BEFORE
    dependencies {
      implementation("com.google.firebase:firebase-vertexai:16.0.0-betaXX")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:34.18.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. پروژه اندروید خود را با فایل‌های Gradle همگام‌سازی کنید.

توجه داشته باشید که اگر تصمیم دارید از Firebase Android BoM استفاده نکنید، کافیست وابستگی مربوط به کتابخانه firebase-ai را اضافه کنید و آخرین نسخه پیشنهادی اندروید استودیو را بپذیرید.

Java

  1. در فایل Gradle ماژول (سطح برنامه) خود (معمولاً <project>/<app-module>/build.gradle.kts یا <project>/<app-module>/build.gradle )، وابستگی‌های قدیمی را (در صورت وجود) با موارد زیر جایگزین کنید.

    توجه داشته باشید که ممکن است مهاجرت کدبیس برنامه (به بخش‌های باقیمانده این راهنما مراجعه کنید) قبل از حذف وابستگی قدیمی، آسان‌تر باشد.

    // BEFORE
    dependencies {
      implementation("com.google.firebase:firebase-vertexai:16.0.0-betaXX")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:34.18.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. پروژه اندروید خود را با فایل‌های Gradle همگام‌سازی کنید.

توجه داشته باشید که اگر تصمیم دارید از Firebase Android BoM استفاده نکنید، کافیست وابستگی مربوط به کتابخانه firebase-ai را اضافه کنید و آخرین نسخه پیشنهادی اندروید استودیو را بپذیرید.

Web

  1. آخرین نسخه Firebase JS SDK برای وب را با استفاده از npm دریافت کنید:

    npm i firebase@latest

    یا

    yarn add firebase@latest
  2. هر جا که کتابخانه را وارد کرده‌اید، دستورات import خود را به‌روزرسانی کنید تا به جای آن firebase/ai استفاده شود.

    توجه داشته باشید که ممکن است مهاجرت کدبیس برنامه (به بخش‌های باقیمانده این راهنما مراجعه کنید) قبل از حذف ایمپورت‌های قدیمی، آسان‌تر باشد.

    // BEFORE
    import { initializeApp } from "firebase/app";
    import { getVertexAI, getGenerativeModel } from "firebase/vertexai-preview";
    
    
    // AFTER
    import { initializeApp } from "firebase/app";
    import { getAI, getGenerativeModel } from "firebase/ai";

Dart

  1. با اجرای دستور زیر از دایرکتوری پروژه Flutter خود، به استفاده از بسته firebase_ai در فایل pubspec.yaml خود به‌روزرسانی کنید:

    flutter pub add firebase_ai
  2. پروژه فلاتر خود را بازسازی کنید:

    flutter run
  3. پس از اتمام انتقال برنامه خود (به بخش‌های باقیمانده در این راهنما مراجعه کنید)، حتماً بسته قدیمی را حذف کنید:

    flutter pub remove firebase_vertexai

وحدت

پشتیبانی از Unity از « Vertex AI در Firebase » در دسترس نبود.

یاد بگیرید که چگونه با Firebase AI Logic SDK برای Unity شروع به کار کنید .

مرحله ۴ : مقداردهی اولیه را در برنامه خود به‌روزرسانی کنید

برای مشاهده محتوا و کد مخصوص ارائه‌دهنده در این صفحه، روی ارائه‌دهنده API Gemini خود کلیک کنید.

پلتفرم عامل

نحوه‌ی مقداردهی اولیه‌ی سرویس برای ارائه‌دهنده‌ی API انتخابی خود را به‌روزرسانی کنید و یک نمونه‌ی GenerativeModel ایجاد کنید.

سویفت


import FirebaseAILogic

// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(modelName: "gemini-3.7-flash")

Kotlin


// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
                        .generativeModel("gemini-3.7-flash")

Java


// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
        .generativeModel("gemini-3.7-flash");

// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);

Web


import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";

// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
  // ...
};

// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);

// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Create a `GenerativeModel` instance with a model that supports your use case.
const model = getGenerativeModel(ai, { model: "gemini-3.7-flash" });

Dart


import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

// Initialize FirebaseApp
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
final model =
      FirebaseAI.googleAI().generativeModel(model: 'gemini-3.7-flash');

وحدت

پشتیبانی از Unity از « Vertex AI در Firebase » در دسترس نبود.

یاد بگیرید که چگونه با Firebase AI Logic SDK برای Unity شروع به کار کنید .

توجه داشته باشید که بسته به قابلیتی که استفاده می‌کنید، ممکن است همیشه یک نمونه GenerativeModel ایجاد نکنید . برای پخش ورودی و خروجی با استفاده از Gemini Live API ، یک نمونه LiveModel ایجاد کنید.

مرحله ۵ : کد خود را بسته به ویژگی‌هایی که استفاده می‌کنید، به‌روزرسانی کنید

این مرحله تغییراتی را شرح می‌دهد که ممکن است بسته به ویژگی‌هایی که استفاده می‌کنید، مورد نیاز باشند.

  • اگر از آدرس‌های اینترنتی Cloud Storage URLs) استفاده می‌کنید و در این انتقال، API توسعه‌دهندگان Gemini را جایگزین کرده‌اید، باید درخواست‌های چندوجهی خود را به‌روزرسانی کنید تا فایل‌ها به عنوان داده‌های درون‌خطی (inline data) لحاظ شوند (یا از آدرس‌های اینترنتی یوتیوب برای ویدیوها استفاده کنید).

  • چندین تغییر برای نسخه‌های GA از SDK های " Vertex AI in Firebase " معرفی شده است. همین تغییرات برای استفاده از SDK های Firebase AI Logic نیز مورد نیاز است. لیست‌های زیر را برای هرگونه تغییری که ممکن است برای تطبیق با SDK Firebase AI Logic در کد خود ایجاد کنید، مرور کنید.

مورد نیاز برای همه زبان‌ها و پلتفرم‌ها

  • فراخوانی تابع
    اگر این ویژگی را قبل از GA پیاده‌سازی کرده‌اید، باید نحوه تعریف طرحواره خود را به‌روزرسانی کنید. توصیه می‌کنیم برای یادگیری نحوه نوشتن اعلان‌های تابع، راهنمای فراخوانی تابع به‌روزرسانی‌شده را مرور کنید.

  • تولید خروجی ساختاریافته (مانند JSON) با استفاده از responseSchema
    اگر این ویژگی را قبل از GA پیاده‌سازی کرده‌اید، باید نحوه تعریف طرحواره خود را به‌روزرسانی کنید. توصیه می‌کنیم برای یادگیری نحوه نوشتن طرحواره‌های JSON، راهنمای جدید خروجی ساختاریافته را مرور کنید.

  • تایم اوت

    • زمان پیش‌فرض برای درخواست‌ها به ۱۸۰ ثانیه تغییر یافت.

مورد نیاز بر اساس پلتفرم یا زبان

سویفت

  • شمارش‌ها

    • اکثر انواع enum با struct ها با متغیرهای استاتیک جایگزین شدند. این تغییر، انعطاف‌پذیری بیشتری را برای تکامل API به روشی سازگار با نسخه‌های قبلی فراهم می‌کند. هنگام استفاده از دستورات switch ، اکنون باید یک مورد default: را برای پوشش مقادیر ناشناخته یا مدیریت نشده، از جمله مقادیر جدیدی که در آینده به SDK اضافه می‌شوند، لحاظ کنید.

    • نام شمارش BlockThreshold به HarmBlockThreshold تغییر یافت؛ این نوع اکنون یک struct است.

    • موارد unknown و unspecified از شمارش‌های زیر (که اکنون struct هستند) حذف شدند: HarmCategory ، HarmBlockThreshold ، HarmProbability ، BlockReason و FinishReason .

    • شمارش ModelContent.Part با پروتکلی به نام Part جایگزین شد تا امکان اضافه کردن انواع جدید به روشی سازگار با نسخه‌های قبلی فراهم شود. این تغییر با جزئیات بیشتر در بخش قطعات محتوا توضیح داده شده است.

  • بخش‌های محتوا

    • پروتکل ThrowingPartsRepresentable حذف شد و مقداردهی اولیه ModelContent ساده‌سازی شد تا از خطاهای گاه به گاه کامپایلر جلوگیری شود. تصاویری که به درستی کدگذاری نمی‌شوند، هنگام استفاده در generateContent همچنان خطا می‌دهند.

    • موارد ModelContent.Part با انواع struct زیر که مطابق با پروتکل Part هستند، جایگزین شدند:

      • .text به TextPart
      • .data به InlineDataPart
      • .fileData به FileDataPart
      • .functionCall به FunctionCallPart
      • .functionResponse به FunctionResponsePart
  • دسته بندی آسیب

    • تغییر داده شد تا HarmCategory دیگر در نوع SafetySetting به صورت تودرتو نباشد. اگر به آن SafetySetting.HarmCategory اشاره می‌کنید، می‌توان آن را با HarmCategory جایگزین کرد.
  • بازخورد ایمنی

    • نوع SafetyFeedback حذف شد، زیرا در هیچ یک از پاسخ‌ها استفاده نشده بود.
  • فراداده استناد

    • نام ویژگی citationSources در CitationMetadata به citations تغییر یافت.
  • کل کاراکترهای قابل پرداخت

    • ویژگی totalBillableCharacters در CountTokensResponse به صورت اختیاری تغییر یافت تا موقعیت‌هایی را که هیچ کاراکتری ارسال نمی‌شود، منعکس کند.
  • پاسخ نامزد

    • برای مطابقت با سایر پلتفرم‌ها، نام CandidateResponse به Candidate تغییر یافت.
  • پیکربندی تولید

    • ویژگی‌های عمومی GenerationConfig به internal تغییر داده شد. همه آنها در مقداردهنده اولیه قابل تنظیم باقی می‌مانند.

Kotlin

  • شمارش‌ها

    • کلاس‌های enum و کلاس‌های sealed با کلاس‌های معمولی جایگزین شدند. این تغییر، انعطاف‌پذیری بیشتری را برای تکامل API به روشی سازگار با نسخه‌های قبلی فراهم می‌کند.

    • نام شمارش BlockThreshold را به HarmBlockThreshold تغییر داد.

    • مقادیر از شمارش‌های زیر حذف شده‌اند: HarmBlockThreshold ، HarmProbability ، HarmSeverity ، BlockReason و FinishReason .

  • روش‌های لکه‌ای

    • تمام متدهایی که Blob به عنوان بخشی از نام خود داشتند، به InlineData تغییر نام دادند.
  • تنظیمات ایمنی

    • method فیلد را به nullable تغییر دادم.
  • کلاس مدت زمان

    • تمام کاربردهای کلاس Duration کاتلین حذف شده و با long جایگزین شده است. این تغییر قابلیت همکاری بهتری با جاوا فراهم می‌کند.
  • فراداده استناد

    • تمام فیلدهایی که قبلاً در CitationMetadata تعریف شده بودند را در یک کلاس جدید به نام Citation قرار داد. Citationها را می‌توان در لیستی به نام citations در CitationMetadata یافت. این تغییر امکان ترازبندی بهتر انواع داده‌ها را در پلتفرم‌های مختلف فراهم می‌کند.
  • تعداد توکن‌ها

    • فیلد totalBillableCharacters به ​​nullable تغییر داده شد.
  • کل کاراکترهای قابل پرداخت

    • ویژگی totalBillableCharacters در CountTokensResponse به صورت اختیاری تغییر یافت تا موقعیت‌هایی را که هیچ کاراکتری ارسال نمی‌شود، منعکس کند.
  • نمونه‌سازی یک مدل

    • پارامتر requestOptions به انتهای لیست پارامترها منتقل شد تا با سایر پلتفرم‌ها هماهنگ شود.
  • Live API

    • مقدار UNSPECIFIED برای کلاس شمارشی ResponseModality حذف شد. به جای آن null استفاده کنید.

    • تغییر نام LiveGenerationConfig.setResponseModalities به LiveGenerationConfig.setResponseModality .

    • کلاس LiveContentResponse.Status حذف شده و در عوض فیلدهای وضعیت به عنوان ویژگی‌های LiveContentResponse تو در تو شده‌اند.

    • کلاس LiveContentResponse حذف شده و در عوض زیرکلاس‌هایی از LiveServerMessage ارائه شده است که با پاسخ‌های مدل مطابقت دارند.

    • LiveModelFutures.connect تغییر کرد تا ListenableFuture<LiveSessionFutures> را به جای ListenableFuture<LiveSession> برگرداند.

Java

  • شمارش‌ها

    • کلاس‌های enum و کلاس‌های sealed با کلاس‌های معمولی جایگزین شدند. این تغییر، انعطاف‌پذیری بیشتری را برای تکامل API به روشی سازگار با نسخه‌های قبلی فراهم می‌کند.

    • نام شمارش BlockThreshold را به HarmBlockThreshold تغییر داد.

    • مقادیر از شمارش‌های زیر حذف شده‌اند: HarmBlockThreshold ، HarmProbability ، HarmSeverity ، BlockReason و FinishReason .

  • روش‌های لکه‌ای

    • تمام متدهایی که Blob به عنوان بخشی از نام خود داشتند، به InlineData تغییر نام دادند.
  • تنظیمات ایمنی

    • method فیلد را به nullable تغییر دادم.
  • کلاس مدت زمان

    • تمام کاربردهای کلاس Duration کاتلین حذف شده و با long جایگزین شده است. این تغییر قابلیت همکاری بهتری با جاوا فراهم می‌کند.
  • فراداده استناد

    • تمام فیلدهایی که قبلاً در CitationMetadata تعریف شده بودند را در یک کلاس جدید به نام Citation قرار داد. Citationها را می‌توان در لیستی به نام citations در CitationMetadata یافت. این تغییر امکان ترازبندی بهتر انواع داده‌ها را در پلتفرم‌های مختلف فراهم می‌کند.
  • تعداد توکن‌ها

    • فیلد totalBillableCharacters به ​​nullable تغییر داده شد.
  • کل کاراکترهای قابل پرداخت

    • ویژگی totalBillableCharacters در CountTokensResponse به صورت اختیاری تغییر یافت تا موقعیت‌هایی را که هیچ کاراکتری ارسال نمی‌شود، منعکس کند.
  • نمونه‌سازی یک مدل

    • پارامتر requestOptions به انتهای لیست پارامترها منتقل شد تا با سایر پلتفرم‌ها هماهنگ شود.
  • Live API

    • مقدار UNSPECIFIED برای کلاس شمارشی ResponseModality حذف شد. به جای آن null استفاده کنید.

    • تغییر نام LiveGenerationConfig.setResponseModalities به LiveGenerationConfig.setResponseModality .

    • کلاس LiveContentResponse.Status حذف شده و در عوض فیلدهای وضعیت به عنوان ویژگی‌های LiveContentResponse تو در تو شده‌اند.

    • کلاس LiveContentResponse حذف شده و در عوض زیرکلاس‌هایی از LiveServerMessage ارائه شده است که با پاسخ‌های مدل مطابقت دارند.

    • LiveModelFutures.connect تغییر کرد تا ListenableFuture<LiveSessionFutures> را به جای ListenableFuture<LiveSession> برگرداند.

  • متدهای مختلف سازنده جاوا تغییر یافته‌اند تا اکنون به جای void ، نمونه کلاس خود را به درستی برگردانند.

Web

  • شمارش‌ها

    • مقادیر از شمارش‌های زیر حذف شده‌اند: HarmCategory ، BlockThreshold ، HarmProbability ، HarmSeverity ، BlockReason و FinishReason .
  • دلیل مسدود شدن

    • blockReason در PromptFeedback به صورت اختیاری تغییر یافت.

تغییرات فقط در صورتی لازم است که شروع به استفاده از رابط برنامه‌نویسی نرم‌افزار Gemini Developer API کنید (به جای رابط برنامه‌نویسی نرم‌افزار پلتفرم Gemini (که قبلاً Vertex AI نام داشت) ):

  • تنظیمات ایمنی

    • کاربردهای پشتیبانی نشده‌ی SafetySetting.method حذف شد.
  • داده‌های درون‌خطی

    • کاربردهای پشتیبانی نشده‌ی InlineDataPart.videoMetadata حذف شد.

Dart

  • شمارش‌ها

    • مقادیر از شمارش‌های زیر حذف شدند: HarmCategory ، HarmProbability ، BlockReason و FinishReason .
  • بخش داده

    • نام DataPart به InlineDataPart و تابع data static به inlineData تغییر یافت تا با سایر پلتفرم‌ها هماهنگ شود.
  • گزینه‌های درخواست

    • RequestOptions به دلیل عدم کارکرد timeout حذف شد. در آینده نزدیک دوباره اضافه خواهد شد، اما برای مطابقت با سایر پلتفرم‌ها به نوع GenerativeModel منتقل می‌شود.
  • توالی‌های توقف

    • پارامتر stopSequences در GenerationConfig را به اختیاری تغییر داد و مقدار پیش‌فرض آن را به جای یک آرایه خالی، null قرار داد.
  • نقل قول‌ها

    • نام ویژگی citationSources در CitationMetadata به citations تغییر یافت. نوع CitationSource برای مطابقت با سایر پلتفرم‌ها به Citation تغییر نام یافت.
  • انواع، متدها و ویژگی‌های عمومی غیرضروری

    • انواع، متدها و ویژگی‌های زیر که به طور ناخواسته در معرض نمایش قرار گرفته بودند، حذف شدند: defaultTimeout ، CountTokensResponseFields ، parseCountTokensResponse ، parseEmbedContentResponse ، parseGenerateContentResponse ، parseContent ، BatchEmbedContentsResponse ، ContentEmbedding ، EmbedContentRequest و EmbedContentResponse .
  • تعداد توکن‌ها

    • فیلدهای اضافی که دیگر لازم نیستند از تابع countTokens حذف شده‌اند. فقط contents مورد نیاز است.
  • نمونه‌سازی یک مدل

    • پارامتر systemInstruction به انتهای لیست پارامترها منتقل شد تا با سایر پلتفرم‌ها هماهنگ شود.
  • قابلیت جاسازی

    • قابلیت جاسازی پشتیبانی نشده ( embedContent و batchEmbedContents ) از مدل حذف شد.

وحدت

پشتیبانی از Unity از « Vertex AI در Firebase » در دسترس نبود.

یاد بگیرید که چگونه با Firebase AI Logic SDK برای Unity شروع به کار کنید .

خطاهای احتمالی مربوط به مهاجرت

همانطور که در حال مهاجرت به نسخه GA از Firebase AI Logic هستید، اگر تمام تغییرات مورد نیاز را طبق آنچه در این راهنمای مهاجرت توضیح داده شده است، تکمیل نکرده باشید، ممکن است با خطا مواجه شوید.

خطای ۴۰۳: Requests to this API firebasevertexai.googleapis.com ... are blocked.

اگر خطای ۴۰۳ با مضمون « Requests to this API firebasevertexai.googleapis.com ... are blocked. دریافت کردید، معمولاً به این معنی است که کلید API فایربیس در فایل یا شیء پیکربندی فایربیس شما، API مورد نیاز را در فهرست مجاز خود برای محصولی که می‌خواهید استفاده کنید، ندارد.

مطمئن شوید که کلید API فایربیس مورد استفاده توسط برنامه شما، تمام APIهای مورد نیاز را در لیست مجاز "محدودیت‌های API" کلید داشته باشد. برای Firebase AI Logic ، کلید API فایربیس شما باید حداقل API فایربیس AI Logic را در لیست مجاز خود داشته باشد. این API باید هنگام فعال کردن APIهای مورد نیاز در کنسول Firebase ، به طور خودکار به لیست مجاز کلید API شما اضافه شده باشد.

شما می‌توانید تمام کلیدهای API خود را در پنل APIs & Services > Credentials در کنسول Google Cloud مشاهده کنید.


درباره تجربه خود با Firebase AI Logic بازخورد دهید


،


Firebase AI Logic و SDK های کلاینت آن قبلاً " Vertex AI in Firebase " نامیده می‌شدند. برای انعکاس بهتر خدمات و ویژگی‌های توسعه‌یافته ما (به عنوان مثال، اکنون از Gemini Developer API پشتیبانی می‌کنیم!)، نام خدمات خود را به Firebase AI Logic تغییر دادیم و بسته‌بندی مجدد کردیم .

برای دسترسی ایمن به مدل‌های هوش مصنوعی مولد گوگل مستقیماً از طریق برنامه‌های تلفن همراه یا وب خود، اکنون می‌توانید یک ارائه‌دهنده « Gemini API » را انتخاب کنید - یا API پلتفرم عامل Gemini که مدت‌هاست در دسترس است (قبلاً Vertex AI) یا اکنون API توسعه‌دهنده Gemini . این بدان معناست که اکنون می‌توانید از API توسعه‌دهنده Gemini استفاده کنید که یک سطح بدون هزینه با محدودیت‌ها و سهمیه‌های معقول ارائه می‌دهد.

مروری بر مراحل مهاجرت به SDK های Firebase AI Logic

  • مرحله ۱ : بهترین ارائه‌دهنده «Gemini API» را برای برنامه و موارد استفاده خود انتخاب کنید.

  • مرحله ۲ : فعال کردن API های مورد نیاز

  • مرحله ۳ : کتابخانه مورد استفاده در برنامه خود را به‌روزرسانی کنید.

  • مرحله ۴ : مقداردهی اولیه را در برنامه خود به‌روزرسانی کنید.

  • مرحله ۵ : کد خود را بسته به ویژگی‌هایی که استفاده می‌کنید، به‌روزرسانی کنید.

مرحله ۱ : بهترین ارائه‌دهنده «Gemini API» را برای برنامه خود انتخاب کنید

با این مهاجرت، شما می‌توانید ارائه‌دهنده‌ی « Gemini API » را انتخاب کنید:

  • SDK های قدیمی « Vertex AI in Firebase » فقط می‌توانستند از API مربوط به Agent Platform Gemini (که قبلاً Vertex AI نام داشت) استفاده کنند.

  • کیت‌های توسعه نرم‌افزار (SDK) جدید Firebase AI Logic به شما امکان می‌دهند انتخاب کنید که می‌خواهید کدام ارائه‌دهنده « Gemini API » را مستقیماً از برنامه تلفن همراه یا وب خود فراخوانی کنید - یا Gemini Developer API یا Agent Platform Gemini API (که قبلاً Vertex AI نام داشت) .

تفاوت‌های بین استفاده از دو ارائه‌دهنده‌ی API مربوط به Gemini را بررسی کنید، به خصوص از نظر ویژگی‌های پشتیبانی‌شده، قیمت‌گذاری و محدودیت‌های نرخ. فقط برای یک مثال، API توسعه‌دهندگان Gemini از ارائه فایل‌ها با استفاده از URLهای Cloud Storage پشتیبانی نمی‌کند، اما اگر می‌خواهید از ردیف رایگان و سهمیه‌ی معقول آن بهره‌مند شوید، می‌تواند انتخاب خوبی باشد.

مرحله ۲ : فعال کردن API های مورد نیاز

مطمئن شوید که تمام APIهای مورد نیاز در پروژه Firebase شما فعال هستند تا بتوانید از ارائه‌دهنده « Gemini API » انتخابی خود استفاده کنید.

توجه داشته باشید که می‌توانید هر دو ارائه‌دهنده API را همزمان در پروژه خود فعال کنید.

  1. وارد کنسول Firebase شوید و سپس پروژه Firebase خود را انتخاب کنید.

  2. در کنسول Firebase ، به بخش سرویس‌های هوش مصنوعی > منطق هوش مصنوعی بروید.

  3. برای شروع یک گردش کار هدایت‌شده که به شما در تنظیم APIها و منابع مورد نیاز پروژه‌تان کمک می‌کند، روی «شروع به کار» کلیک کنید.

  4. ارائه‌دهنده‌ی «Gemini API» را که می‌خواهید با Firebase AI Logic SDKs استفاده کنید، انتخاب کنید. در صورت تمایل، همیشه می‌توانید ارائه‌دهنده‌ی API دیگری را بعداً تنظیم و استفاده کنید.

    • رابط برنامه‌نویسی کاربردی Gemini - پرداخت هزینه اختیاری (در طرح قیمت‌گذاری بدون هزینه Spark موجود است)
      گردش کار کنسول، APIهای مورد نیاز را فعال کرده و یک کلید API جمینی در پروژه شما ایجاد می‌کند.
      این کلید API مربوط به Gemini را به کدبیس برنامه خود اضافه نکنید . اطلاعات بیشتر.

    • رابط برنامه‌نویسی کاربردی پلتفرم عامل Gemini (که قبلاً Vertex AI نام داشت) - نیاز به پرداخت صورتحساب دارد (نیازمند طرح قیمت‌گذاری Blaze با قابلیت پرداخت در محل است)
      گردش کار کنسول، APIهای مورد نیاز را در پروژه شما فعال می‌کند.

  5. برای به‌روزرسانی کتابخانه و مقداردهی اولیه در برنامه خود، در این راهنمای مهاجرت ادامه دهید.

مرحله ۳ : به‌روزرسانی کتابخانه مورد استفاده در برنامه

کدبیس برنامه خود را برای استفاده از کتابخانه Firebase AI Logic به‌روزرسانی کنید.

سویفت

  1. در Xcode، در حالی که پروژه برنامه شما باز است، بسته Firebase خود را با استفاده از یکی از گزینه‌های زیر به نسخه ۱۱.۱۳.۰ یا بالاتر به‌روزرسانی کنید:

    • گزینه ۱ : به‌روزرسانی همه بسته‌ها: به مسیر File > Packages > Update to Latest Package Versions بروید.

    • گزینه ۲ : به‌روزرسانی جداگانه فایربیس: در بخشی به نام Package Dependencies به پکیج فایربیس بروید. روی پکیج فایربیس کلیک راست کنید و سپس Update Package را انتخاب کنید.

  2. مطمئن شوید که بسته Firebase اکنون نسخه 11.13.0 یا بالاتر را نشان می‌دهد. اگر اینطور نیست، بررسی کنید که الزامات بسته‌بندی مشخص‌شده شما امکان به‌روزرسانی به نسخه 11.13.0 یا بالاتر را فراهم می‌کند.

  3. هدف برنامه خود را در ویرایشگر پروژه انتخاب کنید و سپس به بخش چارچوب‌ها، کتابخانه‌ها و محتوای جاسازی‌شده بروید.

  4. کتابخانه جدید را اضافه کنید: دکمه + را انتخاب کنید و سپس FirebaseAI را از بسته Firebase اضافه کنید.

  5. پس از اتمام انتقال برنامه خود (به بخش‌های باقیمانده در این راهنما مراجعه کنید)، حتماً کتابخانه قدیمی را حذف کنید:
    FirebaseVertexAI-Preview را انتخاب کنید و سپس دکمه‌ی را فشار دهید.

Kotlin

  1. در فایل Gradle ماژول (سطح برنامه) خود (معمولاً <project>/<app-module>/build.gradle.kts یا <project>/<app-module>/build.gradle )، وابستگی‌های قدیمی را (در صورت وجود) با موارد زیر جایگزین کنید.

    توجه داشته باشید که ممکن است مهاجرت کدبیس برنامه (به بخش‌های باقیمانده این راهنما مراجعه کنید) قبل از حذف وابستگی قدیمی، آسان‌تر باشد.

    // BEFORE
    dependencies {
      implementation("com.google.firebase:firebase-vertexai:16.0.0-betaXX")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:34.18.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. پروژه اندروید خود را با فایل‌های Gradle همگام‌سازی کنید.

توجه داشته باشید که اگر تصمیم دارید از Firebase Android BoM استفاده نکنید، کافیست وابستگی مربوط به کتابخانه firebase-ai را اضافه کنید و آخرین نسخه پیشنهادی اندروید استودیو را بپذیرید.

Java

  1. در فایل Gradle ماژول (سطح برنامه) خود (معمولاً <project>/<app-module>/build.gradle.kts یا <project>/<app-module>/build.gradle )، وابستگی‌های قدیمی را (در صورت وجود) با موارد زیر جایگزین کنید.

    توجه داشته باشید که ممکن است مهاجرت کدبیس برنامه (به بخش‌های باقیمانده این راهنما مراجعه کنید) قبل از حذف وابستگی قدیمی، آسان‌تر باشد.

    // BEFORE
    dependencies {
      implementation("com.google.firebase:firebase-vertexai:16.0.0-betaXX")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:34.18.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. پروژه اندروید خود را با فایل‌های Gradle همگام‌سازی کنید.

توجه داشته باشید که اگر تصمیم دارید از Firebase Android BoM استفاده نکنید، کافیست وابستگی مربوط به کتابخانه firebase-ai را اضافه کنید و آخرین نسخه پیشنهادی اندروید استودیو را بپذیرید.

Web

  1. آخرین نسخه Firebase JS SDK برای وب را با استفاده از npm دریافت کنید:

    npm i firebase@latest

    یا

    yarn add firebase@latest
  2. هر جا که کتابخانه را وارد کرده‌اید، دستورات import خود را به‌روزرسانی کنید تا به جای آن firebase/ai استفاده شود.

    توجه داشته باشید که ممکن است مهاجرت کدبیس برنامه (به بخش‌های باقیمانده این راهنما مراجعه کنید) قبل از حذف ایمپورت‌های قدیمی، آسان‌تر باشد.

    // BEFORE
    import { initializeApp } from "firebase/app";
    import { getVertexAI, getGenerativeModel } from "firebase/vertexai-preview";
    
    
    // AFTER
    import { initializeApp } from "firebase/app";
    import { getAI, getGenerativeModel } from "firebase/ai";

Dart

  1. با اجرای دستور زیر از دایرکتوری پروژه Flutter خود، به استفاده از بسته firebase_ai در فایل pubspec.yaml خود به‌روزرسانی کنید:

    flutter pub add firebase_ai
  2. پروژه فلاتر خود را بازسازی کنید:

    flutter run
  3. پس از اتمام انتقال برنامه خود (به بخش‌های باقیمانده در این راهنما مراجعه کنید)، حتماً بسته قدیمی را حذف کنید:

    flutter pub remove firebase_vertexai

وحدت

پشتیبانی از Unity از « Vertex AI در Firebase » در دسترس نبود.

یاد بگیرید که چگونه با Firebase AI Logic SDK برای Unity شروع به کار کنید .

مرحله ۴ : مقداردهی اولیه را در برنامه خود به‌روزرسانی کنید

برای مشاهده محتوا و کد مخصوص ارائه‌دهنده در این صفحه، روی ارائه‌دهنده API Gemini خود کلیک کنید.

پلتفرم عامل

نحوه‌ی مقداردهی اولیه‌ی سرویس برای ارائه‌دهنده‌ی API انتخابی خود را به‌روزرسانی کنید و یک نمونه‌ی GenerativeModel ایجاد کنید.

سویفت


import FirebaseAILogic

// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(modelName: "gemini-3.7-flash")

Kotlin


// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
                        .generativeModel("gemini-3.7-flash")

Java


// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
        .generativeModel("gemini-3.7-flash");

// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);

Web


import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";

// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
  // ...
};

// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);

// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Create a `GenerativeModel` instance with a model that supports your use case.
const model = getGenerativeModel(ai, { model: "gemini-3.7-flash" });

Dart


import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

// Initialize FirebaseApp
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
final model =
      FirebaseAI.googleAI().generativeModel(model: 'gemini-3.7-flash');

وحدت

پشتیبانی از Unity از « Vertex AI در Firebase » در دسترس نبود.

یاد بگیرید که چگونه با Firebase AI Logic SDK برای Unity شروع به کار کنید .

توجه داشته باشید که بسته به قابلیتی که استفاده می‌کنید، ممکن است همیشه یک نمونه GenerativeModel ایجاد نکنید . برای پخش ورودی و خروجی با استفاده از Gemini Live API ، یک نمونه LiveModel ایجاد کنید.

مرحله ۵ : کد خود را بسته به ویژگی‌هایی که استفاده می‌کنید، به‌روزرسانی کنید

این مرحله تغییراتی را شرح می‌دهد که ممکن است بسته به ویژگی‌هایی که استفاده می‌کنید، مورد نیاز باشند.

  • اگر از آدرس‌های اینترنتی Cloud Storage URLs) استفاده می‌کنید و در این انتقال، API توسعه‌دهندگان Gemini را جایگزین کرده‌اید، باید درخواست‌های چندوجهی خود را به‌روزرسانی کنید تا فایل‌ها به عنوان داده‌های درون‌خطی (inline data) لحاظ شوند (یا از آدرس‌های اینترنتی یوتیوب برای ویدیوها استفاده کنید).

  • چندین تغییر برای نسخه‌های GA از SDK های " Vertex AI in Firebase " معرفی شده است. همین تغییرات برای استفاده از SDK های Firebase AI Logic نیز مورد نیاز است. لیست‌های زیر را برای هرگونه تغییری که ممکن است برای تطبیق با SDK Firebase AI Logic در کد خود ایجاد کنید، مرور کنید.

مورد نیاز برای همه زبان‌ها و پلتفرم‌ها

  • فراخوانی تابع
    اگر این ویژگی را قبل از GA پیاده‌سازی کرده‌اید، باید نحوه تعریف طرحواره خود را به‌روزرسانی کنید. توصیه می‌کنیم برای یادگیری نحوه نوشتن اعلان‌های تابع، راهنمای فراخوانی تابع به‌روزرسانی‌شده را مرور کنید.

  • تولید خروجی ساختاریافته (مانند JSON) با استفاده از responseSchema
    اگر این ویژگی را قبل از GA پیاده‌سازی کرده‌اید، باید نحوه تعریف طرحواره خود را به‌روزرسانی کنید. توصیه می‌کنیم برای یادگیری نحوه نوشتن طرحواره‌های JSON، راهنمای جدید خروجی ساختاریافته را مرور کنید.

  • تایم اوت

    • زمان پیش‌فرض برای درخواست‌ها به ۱۸۰ ثانیه تغییر یافت.

مورد نیاز بر اساس پلتفرم یا زبان

سویفت

  • شمارش‌ها

    • اکثر انواع enum با struct ها با متغیرهای استاتیک جایگزین شدند. این تغییر، انعطاف‌پذیری بیشتری را برای تکامل API به روشی سازگار با نسخه‌های قبلی فراهم می‌کند. هنگام استفاده از دستورات switch ، اکنون باید یک مورد default: را برای پوشش مقادیر ناشناخته یا مدیریت نشده، از جمله مقادیر جدیدی که در آینده به SDK اضافه می‌شوند، لحاظ کنید.

    • نام شمارش BlockThreshold به HarmBlockThreshold تغییر یافت؛ این نوع اکنون یک struct است.

    • موارد unknown و unspecified از شمارش‌های زیر (که اکنون struct هستند) حذف شدند: HarmCategory ، HarmBlockThreshold ، HarmProbability ، BlockReason و FinishReason .

    • شمارش ModelContent.Part با پروتکلی به نام Part جایگزین شد تا امکان اضافه کردن انواع جدید به روشی سازگار با نسخه‌های قبلی فراهم شود. این تغییر با جزئیات بیشتر در بخش قطعات محتوا توضیح داده شده است.

  • بخش‌های محتوا

    • پروتکل ThrowingPartsRepresentable حذف شد و مقداردهی اولیه ModelContent ساده‌سازی شد تا از خطاهای گاه به گاه کامپایلر جلوگیری شود. تصاویری که به درستی کدگذاری نمی‌شوند، هنگام استفاده در generateContent همچنان خطا می‌دهند.

    • موارد ModelContent.Part با انواع struct زیر که مطابق با پروتکل Part هستند، جایگزین شدند:

      • .text به TextPart
      • .data به InlineDataPart
      • .fileData به FileDataPart
      • .functionCall به FunctionCallPart
      • .functionResponse به FunctionResponsePart
  • دسته بندی آسیب

    • تغییر داده شد تا HarmCategory دیگر در نوع SafetySetting به صورت تودرتو نباشد. اگر به آن SafetySetting.HarmCategory اشاره می‌کنید، می‌توان آن را با HarmCategory جایگزین کرد.
  • بازخورد ایمنی

    • نوع SafetyFeedback حذف شد، زیرا در هیچ یک از پاسخ‌ها استفاده نشده بود.
  • فراداده استناد

    • نام ویژگی citationSources را در CitationMetadata به citations تغییر داد.
  • کل کاراکترهای قابل پرداخت

    • ویژگی totalBillableCharacters در CountTokensResponse به صورت اختیاری تغییر یافت تا موقعیت‌هایی را که هیچ کاراکتری ارسال نمی‌شود، منعکس کند.
  • پاسخ نامزد

    • برای مطابقت با سایر پلتفرم‌ها، نام CandidateResponse به Candidate تغییر یافت.
  • پیکربندی تولید

    • ویژگی‌های عمومی GenerationConfig به internal تغییر داده شد. همه آنها در مقداردهنده اولیه قابل تنظیم باقی می‌مانند.

Kotlin

  • شمارش‌ها

    • کلاس‌های enum و کلاس‌های sealed با کلاس‌های معمولی جایگزین شدند. این تغییر، انعطاف‌پذیری بیشتری را برای تکامل API به روشی سازگار با نسخه‌های قبلی فراهم می‌کند.

    • نام شمارش BlockThreshold را به HarmBlockThreshold تغییر داد.

    • مقادیر از شمارش‌های زیر حذف شده‌اند: HarmBlockThreshold ، HarmProbability ، HarmSeverity ، BlockReason و FinishReason .

  • روش‌های لکه‌ای

    • تمام متدهایی که Blob به عنوان بخشی از نام خود داشتند، به InlineData تغییر نام دادند.
  • تنظیمات ایمنی

    • method فیلد را به nullable تغییر دادم.
  • کلاس مدت زمان

    • تمام کاربردهای کلاس Duration کاتلین حذف شده و با long جایگزین شده است. این تغییر قابلیت همکاری بهتری با جاوا فراهم می‌کند.
  • فراداده استناد

    • تمام فیلدهایی که قبلاً در CitationMetadata تعریف شده بودند را در یک کلاس جدید به نام Citation قرار داد. Citationها را می‌توان در لیستی به نام citations در CitationMetadata یافت. این تغییر امکان ترازبندی بهتر انواع داده‌ها را در پلتفرم‌های مختلف فراهم می‌کند.
  • تعداد توکن‌ها

    • فیلد totalBillableCharacters به ​​nullable تغییر داده شد.
  • کل کاراکترهای قابل پرداخت

    • ویژگی totalBillableCharacters در CountTokensResponse به صورت اختیاری تغییر یافت تا موقعیت‌هایی را که هیچ کاراکتری ارسال نمی‌شود، منعکس کند.
  • نمونه‌سازی یک مدل

    • پارامتر requestOptions به انتهای لیست پارامترها منتقل شد تا با سایر پلتفرم‌ها هماهنگ شود.
  • Live API

    • مقدار UNSPECIFIED برای کلاس شمارشی ResponseModality حذف شد. به جای آن null استفاده کنید.

    • تغییر نام LiveGenerationConfig.setResponseModalities به LiveGenerationConfig.setResponseModality .

    • کلاس LiveContentResponse.Status حذف شده و در عوض فیلدهای وضعیت به عنوان ویژگی‌های LiveContentResponse تو در تو شده‌اند.

    • Removed the LiveContentResponse class, and instead have provided subclasses of LiveServerMessage that match the responses from the model.

    • Changed LiveModelFutures.connect to return ListenableFuture<LiveSessionFutures> instead of ListenableFuture<LiveSession> .

Java

  • شمارش‌ها

    • Replaced enum classes and sealed classes with regular classes. This change allows more flexibility for evolving the API in a backward compatible way.

    • Renamed the BlockThreshold enumeration to HarmBlockThreshold .

    • Removed values from the following enumerations: HarmBlockThreshold , HarmProbability , HarmSeverity , BlockReason , and FinishReason .

  • Blob methods

    • Renamed all methods that included Blob as part of their name to use InlineData instead.
  • تنظیمات ایمنی

    • Changed the field method to be nullable.
  • Duration class

    • Removed all usages of Kotlin's Duration class, and replaced it with long . This change provides better interoperability with Java.
  • Citation metadata

    • Wrapped all the fields previously declared in CitationMetadata into a new class called Citation . Citations can be found in the list called citations in CitationMetadata . This change allows better alignment of types across platforms.
  • Count tokens

    • Changed the field totalBillableCharacters to be nullable.
  • Total billable characters

    • Changed the totalBillableCharacters property in CountTokensResponse to be optional to reflect situations where no characters are sent.
  • Instantiating a model

    • Moved the requestOptions parameter to the end of the parameter list to align with other platforms.
  • Live API

    • Removed UNSPECIFIED value for enum class ResponseModality . Instead use null .

    • Renamed LiveGenerationConfig.setResponseModalities to LiveGenerationConfig.setResponseModality .

    • Removed the LiveContentResponse.Status class, and instead have nested the status fields as properties of LiveContentResponse .

    • Removed the LiveContentResponse class, and instead have provided subclasses of LiveServerMessage that match the responses from the model.

    • Changed LiveModelFutures.connect to return ListenableFuture<LiveSessionFutures> instead of ListenableFuture<LiveSession> .

  • Changed various Java builder methods to now correctly return the instance of their class, instead of void .

Web

  • شمارش‌ها

    • Removed values from the following enumerations: HarmCategory , BlockThreshold , HarmProbability , HarmSeverity , BlockReason , and FinishReason .
  • دلیل مسدود شدن

    • Changed blockReason in PromptFeedback to be optional.

Changes required only if you're starting to use the Gemini Developer API (instead of the Agent Platform Gemini API (formerly Vertex AI) ):

  • تنظیمات ایمنی

    • Removed usages of the unsupported SafetySetting.method .
  • داده‌های درون‌خطی

    • Removed usages of the unsupported InlineDataPart.videoMetadata .

Dart

  • شمارش‌ها

    • Removed values from the following enumerations: HarmCategory , HarmProbability , BlockReason , and FinishReason .
  • Data part

    • Renamed DataPart to InlineDataPart , and the static data function to inlineData to align with other platforms.
  • Request options

    • Removed RequestOptions since timeout wasn't functional. It will be re-added in the near future, but it will be moved to the GenerativeModel type to match other platforms.
  • Stop sequences

    • Changed the stopSequences parameter in GenerationConfig to be optional and to default to null instead of an empty array.
  • نقل قول‌ها

    • Renamed the citationSources property to citations in CitationMetadata . The CitationSource type was renamed to Citation to match other platforms.
  • Unnecessary public types, methods, and properties

    • Removed the following types, methods, and properties which were unintentionally exposed: defaultTimeout , CountTokensResponseFields , parseCountTokensResponse , parseEmbedContentResponse , parseGenerateContentResponse , parseContent , BatchEmbedContentsResponse , ContentEmbedding , EmbedContentRequest , and EmbedContentResponse .
  • Count tokens

    • Removed extra fields from the countTokens function that are no longer necessary. Only contents is needed.
  • Instantiating a model

    • Moved the systemInstruction parameter to the end of the parameter list to align with other platforms.
  • Embedding functionality

    • Removed unsupported embedding functionality ( embedContent and batchEmbedContents ) from the model.

وحدت

Support for Unity wasn't available from " Vertex AI in Firebase ".

Learn how to get started with the Firebase AI Logic SDK for Unity .

Possible errors related to migrating

As you're migrating to use the GA version of Firebase AI Logic , you might encounter errors if you haven't completed all of the required changes as described in this migration guide.

403 Error: Requests to this API firebasevertexai.googleapis.com ... are blocked.

If you receive a 403 error that says Requests to this API firebasevertexai.googleapis.com ... are blocked. , it usually means that the Firebase API key in your Firebase configuration file or object doesn't have a required API in its allowlist for the product that you're trying to use.

Make sure that the Firebase API key used by your app has all the required APIs included in the key's "API restrictions" allowlist . For Firebase AI Logic , your Firebase API key needs to have at minimum the Firebase AI Logic API in its allowlist. This API should have been automatically added to your API key's allowlist when you enabled the required APIs in the Firebase console .

You can view all your API keys in the APIs & Services > Credentials panel in the Google Cloud console.


Give feedback about your experience with Firebase AI Logic


،


Firebase AI Logic and its client SDKs were formerly called " Vertex AI in Firebase ". To better reflect our expanded services and features (for example, we now support the Gemini Developer API !), we renamed and repackaged our services into Firebase AI Logic .

To securely access Google's generative AI models directly from your mobile or web apps, you can now choose a " Gemini API " provider — either the long-available Agent Platform Gemini API (formerly Vertex AI) or now the Gemini Developer API . This means that you now have the option to use the Gemini Developer API , which provides a no-cost tier with reasonable rate limits and quotas.

Overview of steps to migrate to the Firebase AI Logic SDKs

  • Step 1 : Choose the best "Gemini API" provider for your app and use cases.

  • Step 2 : Enable the required APIs.

  • Step 3 : Update the library used in your app.

  • Step 4 : Update the initialization in your app.

  • Step 5 : Update your code depending on the features that you use.

Step 1 : Choose the best "Gemini API" provider for your app

With this migration, you have a choice in " Gemini API " provider:

  • The old " Vertex AI in Firebase " SDKs could only use the Agent Platform Gemini API (formerly Vertex AI) .

  • The new Firebase AI Logic SDKs let you choose which " Gemini API " provider you want to call directly from your mobile or web app – either the Gemini Developer API or the Agent Platform Gemini API (formerly Vertex AI) .

Review the differences between using the two Gemini API providers , especially in terms of supported features, pricing, and rate limits. For just one example, the Gemini Developer API doesn't support providing files using Cloud Storage URLs, but it might be a good choice if you want to take advantage of its no-cost tier and reasonable quota.

Step 2 : Enable the required APIs

Ensure that all required APIs are enabled in your Firebase project to use your chosen " Gemini API " provider.

Note that you can have both of API providers enabled in your project at the same time.

  1. Sign into the Firebase console , and then select your Firebase project.

  2. In the Firebase console, go to AI Services > AI Logic .

  3. Click Get started to launch a guided workflow that helps you set up the required APIs and resources for your project.

  4. Select the "Gemini API" provider that you'd like to use with the Firebase AI Logic SDKs. You can always set up and use the other API provider later, if you'd like.

    • Gemini Developer APIbilling optional (available on the no-cost Spark pricing plan)
      The console's workflow will enable the required APIs and create a Gemini API key in your project.
      Do not add this Gemini API key into your app's codebase. Learn more.

    • Agent Platform Gemini API (formerly Vertex AI)billing required (requires the pay-as-you-go Blaze pricing plan)
      The console's workflow will enable the required APIs in your project.

  5. Continue in this migration guide to update the library and initialization in your app.

Step 3 : Update the library used in your app

Update your app's codebase to use the Firebase AI Logic library.

سویفت

  1. In Xcode, with your app project open, update your Firebase package to v11.13.0 or later using one of the following options:

    • Option 1 : Update all packages: Navigate to File > Packages > Update to Latest Package Versions .

    • Option 2 : Update Firebase individually: Navigate to the Firebase package in the section called Package Dependencies . Right-click on the Firebase package, and then select Update Package .

  2. Make sure that the Firebase package now shows v11.13.0 or later. If it doesn't, verify that your specified Package Requirements allow updating to v11.13.0 or later.

  3. Select your app's target in the Project Editor, and then navigate to the Frameworks, Libraries, and Embedded Content section.

  4. Add the new library: Select the + button, and then add FirebaseAI from the Firebase package.

  5. After you've finished migrating your app (see the remaining sections in this guide), make sure to remove the old library:
    Select FirebaseVertexAI-Preview , and then press the button.

Kotlin

  1. In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle ), replace old dependencies (as applicable) with the following.

    Note that it might be easier to migrate your app's codebase (see the remaining sections in this guide) before deleting the old dependency.

    // BEFORE
    dependencies {
      implementation("com.google.firebase:firebase-vertexai:16.0.0-betaXX")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:34.18.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. Sync your Android project with Gradle files.

Note that if you choose to not use the Firebase Android BoM , then just add the dependency for the firebase-ai library and accept the latest version that's suggested by Android Studio.

Java

  1. In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle ), replace old dependencies (as applicable) with the following.

    Note that it might be easier to migrate your app's codebase (see the remaining sections in this guide) before deleting the old dependency.

    // BEFORE
    dependencies {
      implementation("com.google.firebase:firebase-vertexai:16.0.0-betaXX")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:34.18.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. Sync your Android project with Gradle files.

Note that if you choose to not use the Firebase Android BoM , then just add the dependency for the firebase-ai library and accept the latest version that's suggested by Android Studio.

Web

  1. Get the latest version of the Firebase JS SDK for Web using npm:

    npm i firebase@latest

    یا

    yarn add firebase@latest
  2. Wherever you've imported the library, update your import statements to use firebase/ai instead.

    Note that it might be easier to migrate your app's codebase (see the remaining sections in this guide) before deleting the old imports.

    // BEFORE
    import { initializeApp } from "firebase/app";
    import { getVertexAI, getGenerativeModel } from "firebase/vertexai-preview";
    
    
    // AFTER
    import { initializeApp } from "firebase/app";
    import { getAI, getGenerativeModel } from "firebase/ai";

Dart

  1. Update to the use the firebase_ai package in your pubspec.yaml file by running the following command from your Flutter project directory:

    flutter pub add firebase_ai
  2. Rebuild your Flutter project:

    flutter run
  3. After you've finished migrating your app (see the remaining sections in this guide), make sure to delete the old package:

    flutter pub remove firebase_vertexai

وحدت

Support for Unity wasn't available from " Vertex AI in Firebase ".

Learn how to get started with the Firebase AI Logic SDK for Unity .

Step 4 : Update the initialization in your app

Click your Gemini API provider to view provider-specific content and code on this page.

Update how you initialize the service for your chosen API provider and create a GenerativeModel instance.

سویفت


import FirebaseAILogic

// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(modelName: "gemini-3.7-flash")

Kotlin


// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
                        .generativeModel("gemini-3.7-flash")

Java


// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
        .generativeModel("gemini-3.7-flash");

// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);

Web


import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";

// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
  // ...
};

// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);

// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Create a `GenerativeModel` instance with a model that supports your use case.
const model = getGenerativeModel(ai, { model: "gemini-3.7-flash" });

Dart


import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

// Initialize FirebaseApp
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
final model =
      FirebaseAI.googleAI().generativeModel(model: 'gemini-3.7-flash');

وحدت

Support for Unity wasn't available from " Vertex AI in Firebase ".

Learn how to get started with the Firebase AI Logic SDK for Unity .

Note that depending on the capability you're using, you might not always create a GenerativeModel instance . To stream input and output using the Gemini Live API , create a LiveModel instance.

Step 5 : Update your code depending on features that you use

This step describes changes that may be required depending on which features you use.

  • If you use Cloud Storage URLs and you swapped to use the Gemini Developer API in this migration, then you must update your multimodal requests to include files as inline data (or use YouTube URLs for videos).

  • Several changes were introduced for the GA versions of the " Vertex AI in Firebase " SDKs. These same changes are required to use the Firebase AI Logic SDKs. Review the following lists for any changes that you might need to make in your code to accommodate taking up the Firebase AI Logic SDK.

Required for all languages and platforms

  • فراخوانی تابع
    If you implemented this feature before GA, then you'll need to make updates to how you define your schema. We recommend reviewing the updated function calling guide to learn how to write your function declarations.

  • Generating structured output (like JSON) using responseSchema
    If you implemented this feature before GA, then you'll need to make updates to how you define your schema. We recommend reviewing the new structured output guide to learn how to write JSON schemas.

  • تایم اوت

    • Changed the default timeout for requests to be 180 seconds.

Required based on platform or language

سویفت

  • شمارش‌ها

    • Replaced most enum types with struct s with static variables. This change allows more flexibility for evolving the API in a backward-compatible way. When using switch statements, you must now include a default: case to cover unknown or unhandled values, including new values that are added to the SDK in the future.

    • Renamed the BlockThreshold enumeration to HarmBlockThreshold ; this type is now a struct .

    • Removed unknown and unspecified cases from the following enumerations (now struct s): HarmCategory , HarmBlockThreshold , HarmProbability , BlockReason , and FinishReason .

    • Replaced the enumeration ModelContent.Part with a protocol named Part to allow new types to be added in a backward-compatible way. This change is described in greater detail in the Content parts section.

  • Content parts

    • Removed the ThrowingPartsRepresentable protocol, and simplified the initializers for ModelContent to avoid occasional compiler errors. Images that don't encode properly will still throw errors when being used in generateContent .

    • Replaced the ModelContent.Part cases with the following struct types conforming to the Part protocol:

      • .text to TextPart
      • .data to InlineDataPart
      • .fileData to FileDataPart
      • .functionCall to FunctionCallPart
      • .functionResponse to FunctionResponsePart
  • Harm category

    • Changed the HarmCategory to no longer be nested in the SafetySetting type. If you're referring to it as SafetySetting.HarmCategory , that can be replaced with HarmCategory .
  • Safety feedback

    • Removed the SafetyFeedback type, since it wasn't used in any of the responses.
  • Citation metadata

    • Renamed the citationSources property to citations in CitationMetadata .
  • Total billable characters

    • Changed the totalBillableCharacters property in CountTokensResponse to be optional to reflect situations where no characters are sent.
  • Candidate response

    • Renamed CandidateResponse to Candidate to match other platforms.
  • Generation configuration

    • Changed the public properties of GenerationConfig to internal . They all remain configurable in the initializer.

Kotlin

  • شمارش‌ها

    • Replaced enum classes and sealed classes with regular classes. This change allows more flexibility for evolving the API in a backward compatible way.

    • Renamed the BlockThreshold enumeration to HarmBlockThreshold .

    • Removed values from the following enumerations: HarmBlockThreshold , HarmProbability , HarmSeverity , BlockReason , and FinishReason .

  • Blob methods

    • Renamed all methods that included Blob as part of their name to use InlineData instead.
  • تنظیمات ایمنی

    • Changed the field method to be nullable.
  • Duration class

    • Removed all usages of Kotlin's Duration class, and replaced it with long . This change provides better interoperability with Java.
  • Citation metadata

    • Wrapped all the fields previously declared in CitationMetadata into a new class called Citation . Citations can be found in the list called citations in CitationMetadata . This change allows better alignment of types across platforms.
  • Count tokens

    • Changed the field totalBillableCharacters to be nullable.
  • Total billable characters

    • Changed the totalBillableCharacters property in CountTokensResponse to be optional to reflect situations where no characters are sent.
  • Instantiating a model

    • Moved the requestOptions parameter to the end of the parameter list to align with other platforms.
  • Live API

    • Removed UNSPECIFIED value for enum class ResponseModality . Instead use null .

    • Renamed LiveGenerationConfig.setResponseModalities to LiveGenerationConfig.setResponseModality .

    • Removed the LiveContentResponse.Status class, and instead have nested the status fields as properties of LiveContentResponse .

    • Removed the LiveContentResponse class, and instead have provided subclasses of LiveServerMessage that match the responses from the model.

    • Changed LiveModelFutures.connect to return ListenableFuture<LiveSessionFutures> instead of ListenableFuture<LiveSession> .

Java

  • شمارش‌ها

    • Replaced enum classes and sealed classes with regular classes. This change allows more flexibility for evolving the API in a backward compatible way.

    • Renamed the BlockThreshold enumeration to HarmBlockThreshold .

    • Removed values from the following enumerations: HarmBlockThreshold , HarmProbability , HarmSeverity , BlockReason , and FinishReason .

  • Blob methods

    • Renamed all methods that included Blob as part of their name to use InlineData instead.
  • تنظیمات ایمنی

    • Changed the field method to be nullable.
  • Duration class

    • Removed all usages of Kotlin's Duration class, and replaced it with long . This change provides better interoperability with Java.
  • Citation metadata

    • Wrapped all the fields previously declared in CitationMetadata into a new class called Citation . Citations can be found in the list called citations in CitationMetadata . This change allows better alignment of types across platforms.
  • Count tokens

    • Changed the field totalBillableCharacters to be nullable.
  • Total billable characters

    • Changed the totalBillableCharacters property in CountTokensResponse to be optional to reflect situations where no characters are sent.
  • Instantiating a model

    • Moved the requestOptions parameter to the end of the parameter list to align with other platforms.
  • Live API

    • Removed UNSPECIFIED value for enum class ResponseModality . Instead use null .

    • Renamed LiveGenerationConfig.setResponseModalities to LiveGenerationConfig.setResponseModality .

    • Removed the LiveContentResponse.Status class, and instead have nested the status fields as properties of LiveContentResponse .

    • Removed the LiveContentResponse class, and instead have provided subclasses of LiveServerMessage that match the responses from the model.

    • Changed LiveModelFutures.connect to return ListenableFuture<LiveSessionFutures> instead of ListenableFuture<LiveSession> .

  • Changed various Java builder methods to now correctly return the instance of their class, instead of void .

Web

  • شمارش‌ها

    • Removed values from the following enumerations: HarmCategory , BlockThreshold , HarmProbability , HarmSeverity , BlockReason , and FinishReason .
  • دلیل مسدود شدن

    • Changed blockReason in PromptFeedback to be optional.

Changes required only if you're starting to use the Gemini Developer API (instead of the Agent Platform Gemini API (formerly Vertex AI) ):

  • تنظیمات ایمنی

    • Removed usages of the unsupported SafetySetting.method .
  • داده‌های درون‌خطی

    • Removed usages of the unsupported InlineDataPart.videoMetadata .

Dart

  • شمارش‌ها

    • Removed values from the following enumerations: HarmCategory , HarmProbability , BlockReason , and FinishReason .
  • Data part

    • Renamed DataPart to InlineDataPart , and the static data function to inlineData to align with other platforms.
  • Request options

    • Removed RequestOptions since timeout wasn't functional. It will be re-added in the near future, but it will be moved to the GenerativeModel type to match other platforms.
  • Stop sequences

    • Changed the stopSequences parameter in GenerationConfig to be optional and to default to null instead of an empty array.
  • نقل قول‌ها

    • Renamed the citationSources property to citations in CitationMetadata . The CitationSource type was renamed to Citation to match other platforms.
  • Unnecessary public types, methods, and properties

    • Removed the following types, methods, and properties which were unintentionally exposed: defaultTimeout , CountTokensResponseFields , parseCountTokensResponse , parseEmbedContentResponse , parseGenerateContentResponse , parseContent , BatchEmbedContentsResponse , ContentEmbedding , EmbedContentRequest , and EmbedContentResponse .
  • Count tokens

    • Removed extra fields from the countTokens function that are no longer necessary. Only contents is needed.
  • Instantiating a model

    • Moved the systemInstruction parameter to the end of the parameter list to align with other platforms.
  • Embedding functionality

    • Removed unsupported embedding functionality ( embedContent and batchEmbedContents ) from the model.

وحدت

Support for Unity wasn't available from " Vertex AI in Firebase ".

Learn how to get started with the Firebase AI Logic SDK for Unity .

Possible errors related to migrating

As you're migrating to use the GA version of Firebase AI Logic , you might encounter errors if you haven't completed all of the required changes as described in this migration guide.

403 Error: Requests to this API firebasevertexai.googleapis.com ... are blocked.

If you receive a 403 error that says Requests to this API firebasevertexai.googleapis.com ... are blocked. , it usually means that the Firebase API key in your Firebase configuration file or object doesn't have a required API in its allowlist for the product that you're trying to use.

Make sure that the Firebase API key used by your app has all the required APIs included in the key's "API restrictions" allowlist . For Firebase AI Logic , your Firebase API key needs to have at minimum the Firebase AI Logic API in its allowlist. This API should have been automatically added to your API key's allowlist when you enabled the required APIs in the Firebase console .

You can view all your API keys in the APIs & Services > Credentials panel in the Google Cloud console.


Give feedback about your experience with Firebase AI Logic


،


Firebase AI Logic and its client SDKs were formerly called " Vertex AI in Firebase ". To better reflect our expanded services and features (for example, we now support the Gemini Developer API !), we renamed and repackaged our services into Firebase AI Logic .

To securely access Google's generative AI models directly from your mobile or web apps, you can now choose a " Gemini API " provider — either the long-available Agent Platform Gemini API (formerly Vertex AI) or now the Gemini Developer API . This means that you now have the option to use the Gemini Developer API , which provides a no-cost tier with reasonable rate limits and quotas.

Overview of steps to migrate to the Firebase AI Logic SDKs

  • Step 1 : Choose the best "Gemini API" provider for your app and use cases.

  • Step 2 : Enable the required APIs.

  • Step 3 : Update the library used in your app.

  • Step 4 : Update the initialization in your app.

  • Step 5 : Update your code depending on the features that you use.

Step 1 : Choose the best "Gemini API" provider for your app

With this migration, you have a choice in " Gemini API " provider:

  • The old " Vertex AI in Firebase " SDKs could only use the Agent Platform Gemini API (formerly Vertex AI) .

  • The new Firebase AI Logic SDKs let you choose which " Gemini API " provider you want to call directly from your mobile or web app – either the Gemini Developer API or the Agent Platform Gemini API (formerly Vertex AI) .

Review the differences between using the two Gemini API providers , especially in terms of supported features, pricing, and rate limits. For just one example, the Gemini Developer API doesn't support providing files using Cloud Storage URLs, but it might be a good choice if you want to take advantage of its no-cost tier and reasonable quota.

Step 2 : Enable the required APIs

Ensure that all required APIs are enabled in your Firebase project to use your chosen " Gemini API " provider.

Note that you can have both of API providers enabled in your project at the same time.

  1. Sign into the Firebase console , and then select your Firebase project.

  2. In the Firebase console, go to AI Services > AI Logic .

  3. Click Get started to launch a guided workflow that helps you set up the required APIs and resources for your project.

  4. Select the "Gemini API" provider that you'd like to use with the Firebase AI Logic SDKs. You can always set up and use the other API provider later, if you'd like.

    • Gemini Developer APIbilling optional (available on the no-cost Spark pricing plan)
      The console's workflow will enable the required APIs and create a Gemini API key in your project.
      Do not add this Gemini API key into your app's codebase. Learn more.

    • Agent Platform Gemini API (formerly Vertex AI)billing required (requires the pay-as-you-go Blaze pricing plan)
      The console's workflow will enable the required APIs in your project.

  5. Continue in this migration guide to update the library and initialization in your app.

Step 3 : Update the library used in your app

Update your app's codebase to use the Firebase AI Logic library.

سویفت

  1. In Xcode, with your app project open, update your Firebase package to v11.13.0 or later using one of the following options:

    • Option 1 : Update all packages: Navigate to File > Packages > Update to Latest Package Versions .

    • Option 2 : Update Firebase individually: Navigate to the Firebase package in the section called Package Dependencies . Right-click on the Firebase package, and then select Update Package .

  2. Make sure that the Firebase package now shows v11.13.0 or later. If it doesn't, verify that your specified Package Requirements allow updating to v11.13.0 or later.

  3. Select your app's target in the Project Editor, and then navigate to the Frameworks, Libraries, and Embedded Content section.

  4. Add the new library: Select the + button, and then add FirebaseAI from the Firebase package.

  5. After you've finished migrating your app (see the remaining sections in this guide), make sure to remove the old library:
    Select FirebaseVertexAI-Preview , and then press the button.

Kotlin

  1. In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle ), replace old dependencies (as applicable) with the following.

    Note that it might be easier to migrate your app's codebase (see the remaining sections in this guide) before deleting the old dependency.

    // BEFORE
    dependencies {
      implementation("com.google.firebase:firebase-vertexai:16.0.0-betaXX")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:34.18.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. Sync your Android project with Gradle files.

Note that if you choose to not use the Firebase Android BoM , then just add the dependency for the firebase-ai library and accept the latest version that's suggested by Android Studio.

Java

  1. In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle ), replace old dependencies (as applicable) with the following.

    Note that it might be easier to migrate your app's codebase (see the remaining sections in this guide) before deleting the old dependency.

    // BEFORE
    dependencies {
      implementation("com.google.firebase:firebase-vertexai:16.0.0-betaXX")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:34.18.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. Sync your Android project with Gradle files.

Note that if you choose to not use the Firebase Android BoM , then just add the dependency for the firebase-ai library and accept the latest version that's suggested by Android Studio.

Web

  1. Get the latest version of the Firebase JS SDK for Web using npm:

    npm i firebase@latest

    یا

    yarn add firebase@latest
  2. Wherever you've imported the library, update your import statements to use firebase/ai instead.

    Note that it might be easier to migrate your app's codebase (see the remaining sections in this guide) before deleting the old imports.

    // BEFORE
    import { initializeApp } from "firebase/app";
    import { getVertexAI, getGenerativeModel } from "firebase/vertexai-preview";
    
    
    // AFTER
    import { initializeApp } from "firebase/app";
    import { getAI, getGenerativeModel } from "firebase/ai";

Dart

  1. Update to the use the firebase_ai package in your pubspec.yaml file by running the following command from your Flutter project directory:

    flutter pub add firebase_ai
  2. Rebuild your Flutter project:

    flutter run
  3. After you've finished migrating your app (see the remaining sections in this guide), make sure to delete the old package:

    flutter pub remove firebase_vertexai

وحدت

Support for Unity wasn't available from " Vertex AI in Firebase ".

Learn how to get started with the Firebase AI Logic SDK for Unity .

Step 4 : Update the initialization in your app

Click your Gemini API provider to view provider-specific content and code on this page.

Update how you initialize the service for your chosen API provider and create a GenerativeModel instance.

سویفت


import FirebaseAILogic

// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(modelName: "gemini-3.7-flash")

Kotlin


// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
                        .generativeModel("gemini-3.7-flash")

Java


// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
        .generativeModel("gemini-3.7-flash");

// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);

Web


import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";

// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
  // ...
};

// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);

// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Create a `GenerativeModel` instance with a model that supports your use case.
const model = getGenerativeModel(ai, { model: "gemini-3.7-flash" });

Dart


import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

// Initialize FirebaseApp
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
final model =
      FirebaseAI.googleAI().generativeModel(model: 'gemini-3.7-flash');

وحدت

Support for Unity wasn't available from " Vertex AI in Firebase ".

Learn how to get started with the Firebase AI Logic SDK for Unity .

Note that depending on the capability you're using, you might not always create a GenerativeModel instance . To stream input and output using the Gemini Live API , create a LiveModel instance.

Step 5 : Update your code depending on features that you use

This step describes changes that may be required depending on which features you use.

  • If you use Cloud Storage URLs and you swapped to use the Gemini Developer API in this migration, then you must update your multimodal requests to include files as inline data (or use YouTube URLs for videos).

  • Several changes were introduced for the GA versions of the " Vertex AI in Firebase " SDKs. These same changes are required to use the Firebase AI Logic SDKs. Review the following lists for any changes that you might need to make in your code to accommodate taking up the Firebase AI Logic SDK.

Required for all languages and platforms

  • فراخوانی تابع
    If you implemented this feature before GA, then you'll need to make updates to how you define your schema. We recommend reviewing the updated function calling guide to learn how to write your function declarations.

  • Generating structured output (like JSON) using responseSchema
    If you implemented this feature before GA, then you'll need to make updates to how you define your schema. We recommend reviewing the new structured output guide to learn how to write JSON schemas.

  • تایم اوت

    • Changed the default timeout for requests to be 180 seconds.

Required based on platform or language

سویفت

  • شمارش‌ها

    • Replaced most enum types with struct s with static variables. This change allows more flexibility for evolving the API in a backward-compatible way. When using switch statements, you must now include a default: case to cover unknown or unhandled values, including new values that are added to the SDK in the future.

    • Renamed the BlockThreshold enumeration to HarmBlockThreshold ; this type is now a struct .

    • Removed unknown and unspecified cases from the following enumerations (now struct s): HarmCategory , HarmBlockThreshold , HarmProbability , BlockReason , and FinishReason .

    • Replaced the enumeration ModelContent.Part with a protocol named Part to allow new types to be added in a backward-compatible way. This change is described in greater detail in the Content parts section.

  • Content parts

    • Removed the ThrowingPartsRepresentable protocol, and simplified the initializers for ModelContent to avoid occasional compiler errors. Images that don't encode properly will still throw errors when being used in generateContent .

    • Replaced the ModelContent.Part cases with the following struct types conforming to the Part protocol:

      • .text to TextPart
      • .data to InlineDataPart
      • .fileData to FileDataPart
      • .functionCall to FunctionCallPart
      • .functionResponse to FunctionResponsePart
  • Harm category

    • Changed the HarmCategory to no longer be nested in the SafetySetting type. If you're referring to it as SafetySetting.HarmCategory , that can be replaced with HarmCategory .
  • Safety feedback

    • Removed the SafetyFeedback type, since it wasn't used in any of the responses.
  • Citation metadata

    • Renamed the citationSources property to citations in CitationMetadata .
  • Total billable characters

    • Changed the totalBillableCharacters property in CountTokensResponse to be optional to reflect situations where no characters are sent.
  • Candidate response

    • Renamed CandidateResponse to Candidate to match other platforms.
  • Generation configuration

    • Changed the public properties of GenerationConfig to internal . They all remain configurable in the initializer.

Kotlin

  • شمارش‌ها

    • Replaced enum classes and sealed classes with regular classes. This change allows more flexibility for evolving the API in a backward compatible way.

    • Renamed the BlockThreshold enumeration to HarmBlockThreshold .

    • Removed values from the following enumerations: HarmBlockThreshold , HarmProbability , HarmSeverity , BlockReason , and FinishReason .

  • Blob methods

    • Renamed all methods that included Blob as part of their name to use InlineData instead.
  • تنظیمات ایمنی

    • Changed the field method to be nullable.
  • Duration class

    • Removed all usages of Kotlin's Duration class, and replaced it with long . This change provides better interoperability with Java.
  • Citation metadata

    • Wrapped all the fields previously declared in CitationMetadata into a new class called Citation . Citations can be found in the list called citations in CitationMetadata . This change allows better alignment of types across platforms.
  • Count tokens

    • Changed the field totalBillableCharacters to be nullable.
  • Total billable characters

    • Changed the totalBillableCharacters property in CountTokensResponse to be optional to reflect situations where no characters are sent.
  • Instantiating a model

    • Moved the requestOptions parameter to the end of the parameter list to align with other platforms.
  • Live API

    • Removed UNSPECIFIED value for enum class ResponseModality . Instead use null .

    • Renamed LiveGenerationConfig.setResponseModalities to LiveGenerationConfig.setResponseModality .

    • Removed the LiveContentResponse.Status class, and instead have nested the status fields as properties of LiveContentResponse .

    • Removed the LiveContentResponse class, and instead have provided subclasses of LiveServerMessage that match the responses from the model.

    • Changed LiveModelFutures.connect to return ListenableFuture<LiveSessionFutures> instead of ListenableFuture<LiveSession> .

Java

  • شمارش‌ها

    • Replaced enum classes and sealed classes with regular classes. This change allows more flexibility for evolving the API in a backward compatible way.

    • Renamed the BlockThreshold enumeration to HarmBlockThreshold .

    • Removed values from the following enumerations: HarmBlockThreshold , HarmProbability , HarmSeverity , BlockReason , and FinishReason .

  • Blob methods

    • Renamed all methods that included Blob as part of their name to use InlineData instead.
  • تنظیمات ایمنی

    • Changed the field method to be nullable.
  • Duration class

    • Removed all usages of Kotlin's Duration class, and replaced it with long . This change provides better interoperability with Java.
  • Citation metadata

    • Wrapped all the fields previously declared in CitationMetadata into a new class called Citation . Citations can be found in the list called citations in CitationMetadata . This change allows better alignment of types across platforms.
  • Count tokens

    • Changed the field totalBillableCharacters to be nullable.
  • Total billable characters

    • Changed the totalBillableCharacters property in CountTokensResponse to be optional to reflect situations where no characters are sent.
  • Instantiating a model

    • Moved the requestOptions parameter to the end of the parameter list to align with other platforms.
  • Live API

    • Removed UNSPECIFIED value for enum class ResponseModality . Instead use null .

    • Renamed LiveGenerationConfig.setResponseModalities to LiveGenerationConfig.setResponseModality .

    • Removed the LiveContentResponse.Status class, and instead have nested the status fields as properties of LiveContentResponse .

    • Removed the LiveContentResponse class, and instead have provided subclasses of LiveServerMessage that match the responses from the model.

    • Changed LiveModelFutures.connect to return ListenableFuture<LiveSessionFutures> instead of ListenableFuture<LiveSession> .

  • Changed various Java builder methods to now correctly return the instance of their class, instead of void .

Web

  • شمارش‌ها

    • Removed values from the following enumerations: HarmCategory , BlockThreshold , HarmProbability , HarmSeverity , BlockReason , and FinishReason .
  • دلیل مسدود شدن

    • Changed blockReason in PromptFeedback to be optional.

Changes required only if you're starting to use the Gemini Developer API (instead of the Agent Platform Gemini API (formerly Vertex AI) ):

  • تنظیمات ایمنی

    • Removed usages of the unsupported SafetySetting.method .
  • داده‌های درون‌خطی

    • Removed usages of the unsupported InlineDataPart.videoMetadata .

Dart

  • شمارش‌ها

    • Removed values from the following enumerations: HarmCategory , HarmProbability , BlockReason , and FinishReason .
  • Data part

    • Renamed DataPart to InlineDataPart , and the static data function to inlineData to align with other platforms.
  • Request options

    • Removed RequestOptions since timeout wasn't functional. It will be re-added in the near future, but it will be moved to the GenerativeModel type to match other platforms.
  • Stop sequences

    • Changed the stopSequences parameter in GenerationConfig to be optional and to default to null instead of an empty array.
  • نقل قول‌ها

    • Renamed the citationSources property to citations in CitationMetadata . The CitationSource type was renamed to Citation to match other platforms.
  • Unnecessary public types, methods, and properties

    • Removed the following types, methods, and properties which were unintentionally exposed: defaultTimeout , CountTokensResponseFields , parseCountTokensResponse , parseEmbedContentResponse , parseGenerateContentResponse , parseContent , BatchEmbedContentsResponse , ContentEmbedding , EmbedContentRequest , and EmbedContentResponse .
  • Count tokens

    • Removed extra fields from the countTokens function that are no longer necessary. Only contents is needed.
  • Instantiating a model

    • Moved the systemInstruction parameter to the end of the parameter list to align with other platforms.
  • Embedding functionality

    • Removed unsupported embedding functionality ( embedContent and batchEmbedContents ) from the model.

وحدت

Support for Unity wasn't available from " Vertex AI in Firebase ".

Learn how to get started with the Firebase AI Logic SDK for Unity .

Possible errors related to migrating

As you're migrating to use the GA version of Firebase AI Logic , you might encounter errors if you haven't completed all of the required changes as described in this migration guide.

403 Error: Requests to this API firebasevertexai.googleapis.com ... are blocked.

If you receive a 403 error that says Requests to this API firebasevertexai.googleapis.com ... are blocked. , it usually means that the Firebase API key in your Firebase configuration file or object doesn't have a required API in its allowlist for the product that you're trying to use.

Make sure that the Firebase API key used by your app has all the required APIs included in the key's "API restrictions" allowlist . For Firebase AI Logic , your Firebase API key needs to have at minimum the Firebase AI Logic API in its allowlist. This API should have been automatically added to your API key's allowlist when you enabled the required APIs in the Firebase console .

You can view all your API keys in the APIs & Services > Credentials panel in the Google Cloud console.


Give feedback about your experience with Firebase AI Logic