gemini-2.5-pro| input-price: 1.25 output-price: 10 max-context-length: 200_000 (cost: $0.03) Β· Anfrage: 2025-09-25T20:13:47.800328
Generated by rs-summarizer Version unbekannt
Abstract:
This document is a technical migration guide for developers transitioning from the legacy google-generativeai library to the new, streamlined Google GenAI SDK (google-genai). The guide highlights the core architectural change: the introduction of a centralized Client object that serves as the single entry point for all API interactions, replacing previous ad-hoc methods. It provides comprehensive "before-and-after" code examples in Python, demonstrating key changes across various functionalities. These include simplified authentication, a more consistent structure for content generation, configuration, and safety settings. The guide also details updated workflows for advanced features like chat sessions, function calling, code execution, file management, context caching, and model tuning, emphasizing an improved and more uniform developer experience.
Migrating to the New Google GenAI SDK: Key Changes and Updates
genai.Client() object. This client now serves as the single entry point for all API services like models, chats, files, and tuning.pip install google-genai. Authentication is streamlined, as the client can automatically use an API key from the GEMINI_API_KEY environment variable, or it can be passed explicitly during client initialization.genai.upload_file or model.generate_content are now unified as methods on the client object (e.g., client.files.upload(), client.models.generate_content()). This creates a more predictable and uniform structure.temperature, max_output_tokens, safety_settings, and response_mime_type) are now passed together in a single config argument, which can be a dictionary or a types.GenerateContentConfig object.client.chats.create(), making the process more explicit and separating it from the model definition.generate_content. Tools such as code_execution and google_search are enabled within the config argument, providing a unified way to add capabilities to the model.client.files and client.caches), improving clarity over the previous global functions.client.tunings.tune() method, which launches the tuning job and polls for completion, reducing the manual steps required previously.