[Bug]: vertex_ai text-to-speech ignores `vertex_location` when building the endpoint (always global unless `api_base` is the full URL)

在 LiteLLM 中通过 /v1/audio/speech 调用 vertex_ai/* 的 TTS 模型(如 Chirp 3 HD)且配置了 vertex_location: eu 时,请求仍然发往全局端点 texttospeech.googleapis.com ,即 [Bug]: vertex

快速结论:在 LiteLLM 中通过 /v1/audio/speech 调用 vertex_ai/* 的 TTS 模型(如 Chirp 3 HD)且配置了 vertex_location: eu 时,请求仍然发往全局端点 texttospeech.googleapis.com,即 [Bug]: vertex_ai text-to-speech ignores vertex_location when building the endpoint (always global unless api_base is the full URL)。优先排查 api_base 是否设置为完整的区域 URL,或升级到包含 #50255 修复的版本。

适用环境:LiteLLM Proxy v1.106.0(Issue 中注明在 v1.106.6 与 main 分支同样存在)、Vertex AI、Cloud Text-to Speech;问题已确认的 TTS 模型为 Chirp 3 HD,语音示例 fr-FR-Chirp3-HD-Aoede。Issue 未提供操作系统、Python、CUDA 或显卡信息。

最快修复方案:Issue 中经复现确认有效的规避方式是把 api_base 设为完整区域 URL,例如 https://eu-texttospeech.googleapis.com/v1/text:synthesize,此时激活路径 VertexAITextToSpeechConfig.get_complete_url 会采用它。根本修复为 PR #50255(已合并)。

注意事项:api_base 必须包含完整路径 /v1/text:synthesize,只写主机名不足以生效;Cloud Text-to-Speech 只有 eu- 与 us- 两个多区域端点,europe-west4-texttospeech.googleapis.com 之类的主机不存在。Issue 正文中引用的硬编码 url: Final 位于旧的 VertexTextToSpeechAPI 处理器,并非实际激活路径。升级版本后 europe-west4/europe-west1 等区域如何映射到 eu 主机,请以 PR #50255 合并后的代码为准。

问题场景

用户通过 LiteLLM Proxy 的 /v1/audio/speech 接口调用 vertex_ai/chirp 这类 Vertex AI TTS 模型,并在模型配置中设置了 vertex_location: eu,期望请求发往欧盟区域端点以满足数据驻留要求。配置示例如下:

model_list:
  - model_name: chirp-3-hd
    litellm_params:
      model: vertex_ai/chirp
      vertex_project: my-project
      vertex_location: eu          # or any other value, or api_base

调用请求本身返回成功,因此没有明显报警,但通过 pre_call 日志或 additional_args.api_base 可以看到出站请求的主机始终是 texttospeech.googleapis.com。同一套配置下,语音转文字(STT)路径会正确使用 {location}-speech.googleapis.com。

报错原文

[Bug]: vertex_ai text-to-speech ignores `vertex_location` when building the endpoint (always global unless `api_base` is the full URL)

url: Final = "https://texttospeech.googleapis.com/v1/text:synthesize"

该问题不会抛出异常,表现为“请求成功但端点错误”,需要通过日志检查出站 URL。

原因分析

经 Issue 作者后续更正,真正的原因如下:当前激活的 TTS 路径是 VertexAITextToSpeechConfig,其 get_complete_url 会采用 api_base,但只有在 api_base 为完整 URL 时才有效;vertex_location 并未参与主机构造,未设置 api_base 时便会静默回落到全局端点 texttospeech.googleapis.com。

Issue 正文中列出的硬编码 url: Final 常量位于旧的 VertexTextToSpeechAPI 处理器,按 main.py 的说明该处理器已被替代,不在激活路径上,因此引用它会误判故障位置。此外,区域 TTS 端点并非对任意 location 都存在,Cloud Text-to-Speech 只有 eu-texttospeech.googleapis.com 和 us-texttospeech.googleapis.com 两个多区域主机;litellm/llms/vertex_ai/text_to_speech/transformation.py 中的 _GEMINI_CLOUD_TTS_LOCATIONS 已负责把 Vertex 区域(如 europe-west4、europe-west1)映射为 eu。修复方向即为复用这套映射与 validate_vertex_location 校验。

环境排查

  • 确认 LiteLLM 版本:Issue 指出 v1.106.0、v1.106.6 与 main 均存在该问题,需确认是否已包含 PR #50255 的修复。
  • 确认是否使用 /v1/audio/speech 与 vertex_ai/* TTS 模型(如 vertex_ai/chirp)。
  • 检查模型配置中的 vertex_project、vertex_location、api_base 三个参数。
  • 若使用 api_base 规避,确认其为完整 URL,包含协议与 /v1/text:synthesize 路径。
  • 确认目标 voice 在区域端点可用:Issue 已验证 fr-FR-Chirp3-HD-Aoede 在 eu-texttospeech.googleapis.com 与全局端点上均可成功合成。
  • Issue 未提供操作系统、Python、CUDA、PyTorch 或显卡相关信息,无需据此排查。

解决步骤

  1. 临时规避(可优先尝试):在模型配置中显式设置完整的区域 api_base,例如 https://eu-texttospeech.googleapis.com/v1/text:synthesize,该方式已在 Issue 复现中确认生效。
  2. 若不需要区域端点、可接受全局端点,可暂时不设置 vertex_location 并接受默认行为;但若出于数据驻留要求必须走区域端点,不应依赖此方式。
  3. 根本修复:升级到已合并 PR #50255 的 LiteLLM 版本。修复后,未设置 api_base 时会根据位置构造主机:global 或未设置保持 texttospeech.googleapis.com,其他位置经 validate_vertex_location 校验并映射为对应的 eu-/us- 主机。
  4. 升级后移除临时添加的 api_base,让位置映射逻辑接管,避免两处配置互相干扰。
  5. 不要尝试 europe-west4-texttospeech.googleapis.com 这类主机,它并不存在;如需手动指定,只能使用 eu- 或 us- 两个多区域主机。

验证方法

发送一次 /v1/audio/speech 请求,然后检查出站请求的日志(pre_call 日志中的 additional_args.api_base 或其等价字段):配置 vertex_location: eu 且不设 api_base 时,主机应为 eu-texttospeech.googleapis.com,而非 texttospeech.googleapis.com;未设置位置或设置为 global 时,应仍为 texttospeech.googleapis.com。同时确认合成结果正常返回。

参考来源

BerriAI/litellm #50219

修复 PR:BerriAI/litellm #50255

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 33136

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注