Skip to content

[Bug/Feature] 支持Google Vertex AI的API接入 #7653

@starmiaoa

Description

@starmiaoa

What happened / 发生了什么

  1. 问题描述 (Description)
    在当前版本的 Astrbot 中, 无可用的Google Vertex AI API预设,如果用户尝试接入 Google Cloud Vertex AI 节点,使用其他的模型供应商预设(例如Open AI Google Gemini),会出现 404 Not Found 错误,导致无法获取模型列表或调用模型。

底层原因是 Astrbot 目前没有专门给Vertex AI API调用的预设,如果使用Google Gemini预设是不行的,因为Astrbot 的 google-genai SDK 默认按照 Google AI Studio 的路由规则工作。当用户在界面的 API Base URL 填入 Vertex AI 的企业级网关地址时,底层 SDK 会强制在末尾拼接 AI Studio 专属的路径(如 /v1beta/models),导致在 Vertex AI 服务器上无法命中路由。

解决方法:
建立一个新的模型供应商预设
https://docs.cloud.google.com/vertex-ai/generative-ai/docs/model-reference/function-calling?hl=zh-cn#functiondeclaration
这是Google提供的vertex-ai API接入参考文档
(内容有AI生成部分,谨慎参考)

Reproduce / 如何复现?

PS(复现是复现相同错误代码,由于Astrbot目前没有专门给Google Vertex AI用的模型供应室预设,这里使用Google Gemini预设)

在模型供应室界面创建Google Gemini预设,API Base URL填入https://aiplatform.googleapis.com,API Key填写可用的API密钥,保存并获取模型列表,发现此报错

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

Astrbot版本:v4.20.1
部署方式: uv tool install astrbot
使用的供应商:Gemini预设 API Base URL 自己填写的是https://aiplatform.googleapis.com
消息平台适配器: OneBot v11 走的Napcat

OS

Linux

Logs / 报错日志

[2026-04-19 00:17:40.184] [Core] [ERRO] [v4.20.1] [routes.config:1006]: Traceback (most recent call last):

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/astrbot/core/provider/sources/gemini_source.py", line 832, in get_models

models = await self.client.models.list()

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/google/genai/models.py", line 8099, in list

await self._list(config=config),

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/google/genai/models.py", line 7229, in _list

response = await self._api_client.async_request(

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/google/genai/_api_client.py", line 1448, in async_request

result = await self._async_request(

^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/google/genai/_api_client.py", line 1381, in _async_request

return await self._async_retry( # type: ignore[no-any-return]

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/tenacity/asyncio/init.py", line 112, in call

do = await self.iter(retry_state=retry_state)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/tenacity/asyncio/init.py", line 157, in iter

result = await action(retry_state)

^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/tenacity/_utils.py", line 111, in inner

return call(*args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/tenacity/init.py", line 413, in exc_check

raise retry_exc.reraise()

^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/tenacity/init.py", line 184, in reraise

raise self.last_attempt.result()

^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/lib/python3.12/concurrent/futures/_base.py", line 449, in result

return self.__get_result()

^^^^^^^^^^^^^^^^^^^

File "/usr/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result

raise self._exception

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/tenacity/asyncio/init.py", line 116, in call

result = await fn(*args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/google/genai/_api_client.py", line 1326, in _async_request_once

await errors.APIError.raise_for_async_response(response)

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/google/genai/errors.py", line 216, in raise_for_async_response

await cls.raise_error_async(status_code, response_json, response)

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/google/genai/errors.py", line 238, in raise_error_async

raise ClientError(status_code, response_json, response)

google.genai.errors.ClientError: 404 Not Found. {'message': '\n\n \n \n <title>Error 404 (Not Found)!!1</title>\n <style>\n {margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px} > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n </style>\n \n

404. That’s an error.\n

The requested URL /v1beta/models was not found on this server. That’s all we know.\n', 'status': 'Not Found'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/astrbot/dashboard/routes/config.py", line 982, in get_provider_source_models

models = await inst.get_models()

^^^^^^^^^^^^^^^^^^^^^^^

File "/home/ubuntu/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/astrbot/core/provider/sources/gemini_source.py", line 841, in get_models

raise Exception(f"获取模型列表失败: {e.message}")

Exception: 获取模型列表失败:

<title>Error 404 (Not Found)!!1</title> <style> *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px} </style>

404. That’s an error.

The requested URL /v1beta/models was not found on this server. That’s all we know.

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions