返回全部资讯
Google Gen AI Python SDK 发布T2·开发与工程

谷歌 Python GenAI SDK 升 3.0 默认 API 切至 v1

作者:release-please[bot]原标题:v3.0.0
42AI 研判分

谷歌发布 python-genai SDK 3.0.0,将 Gemini Developer API 的默认版本从 v1beta 改为 v1,属于破坏性变更。部分模型别名、-preview 模型、Live API 与上下文缓存仅在 v1beta 提供,需显式回退;Vertex AI 客户端默认值不受影响。

报道正文

本文目录5 个章节

3.0.0 (2026-11-05)

⚠ BREAKING CHANGES

  • Default Gemini Developer API version is now v1 (was v1beta) (2d0f947)

  • Clients targeting the Gemini Developer API now default to API version v1 instead of v1beta.

  • No effect on Gemini Enterprise (Vertex AI) defaults: Clients with vertexai=True / enterprise=True are unaffected by this default change and continue to default to v1beta1.

  • Some models are not available on v1, notably: the gemini-flash-latest, gemini-flash-lite-latest and gemini-pro-latest aliases, and some -preview models. They exist only on v1beta. To keep using them, use a specific stable model version, or switch back to v1beta as shown below.

  • The Live API and context caching (caches) are not available on v1. The Gemini Developer API serves them only on v1beta. To keep using them, switch back to v1beta as shown below.

  • Some model aliases are not available on v1, notably: gemini-flash-latest, gemini-flash-lite-latest and gemini-pro-latest. They exist only on v1beta. To keep using them, use a specific model version, or switch back to v1beta as shown below.

  • How to configure or restore the previous default via environment variable: Set GOOGLE_GENAI_API_VERSION (works for both Gemini Developer API and Enterprise / Vertex AI clients when no version is set in code):

  • How to set the API version in code: Pass api_version in HttpOptions (takes precedence over GOOGLE_GENAI_API_VERSION):

  • Default HTTP client is now httpx2 (was httpx), and httpx is no longer installed by default (51285c8)

  • httpx is no longer installed by default. httpx2 is now the required dependency and default HTTP client.

  • How to restore the previous httpx default via environment variable: Because httpx2 is installed by default, installing google-genai[httpx] alone only makes import httpx available; to switch the SDK's default client back to httpx without code changes, both install the httpx extra and set GOOGLE_GENAI_HTTP_CLIENT=httpx:

  • How to pass an httpx client in code: After installing google-genai[httpx], you can pass httpx.Client / httpx.AsyncClient directly via HttpOptions:

  • Migrating existing httpx code to httpx2: In most cases, updating your imports with import httpx2 as httpx is sufficient.

  • SSL certificate verification: By default, httpx2 uses the OS certificate trust store (via truststore / httpx2.create_ssl_context()) instead of certifi when SSL_CERT_FILE and SSL_CERT_DIR are not set.

  • When httpx vs. httpx2 types matter: Package-specific objects passed in HttpOptions(client_args=..., async_client_args=...) (such as Timeout, Limits, MockTransport / BaseTransport, or custom Auth subclasses) and unwrapped transport exceptions caught from client.models, client.files, etc. (TimeoutException, ConnectError, HTTPError) must match the active HTTP client. (When GOOGLE_GENAI_HTTP_CLIENT is unset or auto, passing httpx objects in HttpOptions will also auto-select the httpx backend if google-genai[httpx] is installed.)

  • interactions: CodeExecutionResultStep.result changes from string to the CodeExecutionResultStepResult union. Code that reads result as a string must now check which variant is present and read the string from it. The JSON for text-only results is unchanged.

Features

  • Add source_text to AudioTranscriptionConfig and SmartTranscriptionMode. (1ac3c91)
  • Add MALFORMED_RESPONSE to FinishReason (6eb8523), refs #2937
  • cli: Use gemini-3.5-transcribe as default model for transcribe command (b18fd3c)
  • Default Gemini API version to v1 instead of v1beta across SDKs (2d0f947)
  • Disable GenerateVideos for Gemini API, update tests/READMEs (8ddc655)
  • interactions: Add Office and OpenDocument MIME types (753cc1c)
  • interactions: Support multimodal content in CodeExecutionResultStep.result (a216d95)
  • Support GOOGLE_GENAI_API_VERSION environment variable across SDKs (2d0f947)
  • Switch default HTTP client to httpx2 and use OS trust store by default (51285c8)
  • Update discovery doc (5647e1e)

Bug Fixes

  • interactions: Retries = attempts - 1 (0f688a6)
  • Preserve unknown fields and open-union variants in Interactions models (2eaf2d8)
  • Respect configured and default API version for Gemini API file uploads across SDKs (ddc45d0)

Documentation

  • Update embedding examples from gemini-embedding-2-preview to gemini-embedding-2 (d97752a)
  • Update remaining documentation links from ai.google.dev to aistudio.google.com. (0e34831)