# Antigravity CLI

Antigravity CLI（`agy`）可以向 AISIX 发送 Gemini 生成请求。无论上游是 Google AI Studio，还是 GitHub Copilot Chat 等提供 OpenAI Chat Completions 的服务，客户端都使用 Gemini 协议。此集成需要 v1.12.0 或更高版本的 AISIX 网关。

## 选择上游[​](#choose-the-upstream "选择上游的直接链接")

向网关管理员获取 AISIX 代理 URL、调用方 API Key，以及该 Key 有权访问的模型别名。配置别名时，创建[直连模型](https://docs.apiseven.com/ai-gateway/models/model-aliases.md#create-a-direct-model)，填写 `display_name`、`model_name` 和 `provider_key_id`，并将该模型的访问权限授予调用方 Key。下例使用 `gemini-3.8-flash` 作为客户端请求的别名。实际处理请求的服务由服务提供方密钥和上游模型 ID 决定。

| 上游             | AISIX 中的服务提供方密钥                                                                                                                                                                                                                                                                           | 上游模型与请求                                                                                                                                     |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| Google AI Studio | 选择目录中的 `google`，使用官方端点和 Google API Key。在 AISIX OSS 中，将 `apis.gemini.base` 设为 `https://generativelanguage.googleapis.com/v1beta`。参阅 [Gemini 服务提供方指南](https://docs.apiseven.com/ai-gateway/providers/gemini.md)。                                                     | 将 `model_name` 设为可用的 Google 模型 ID。AISIX 通过 Google 原生生成端点调用该模型，并在 `x-goog-api-key` 中传递服务提供方凭证。                  |
| Copilot Chat     | 使用已有的 Chat Completions 服务提供方密钥，或配置[自带上游的服务提供方密钥](https://docs.apiseven.com/ai-gateway/models/provider-keys.md#set-provider-and-adapter)，填写 `provider: byo`、`adapter: openai`、`api_base: https://api.githubcopilot.com` 以及该端点接受的凭证。省略 `apis.gemini`。 | 将 `model_name` 设为该集成有权在 `/chat/completions` 上调用且支持工具的模型。AISIX 将请求转为 Chat Completions，并以 Gemini 格式向客户端返回结果。 |

## 配置 Antigravity[​](#configure-antigravity "配置 Antigravity的直接链接")

在运行 `agy` 的 shell 中设置 AISIX 代理的源地址，省略末尾斜杠和 API 版本。填写 AISIX 颁发的调用方 Key。Antigravity 会将其作为 Bearer Token 发送。

```
export AGY_LLM_GATEWAY_URL="https://gateway.example.com"

export AGY_LLM_GATEWAY_API_KEY="YOUR_AISIX_CALLER_KEY"

export AGY_LLM_GATEWAY_WIRE_PROTOCOL="genai"

export AGY_LLM_GATEWAY_MODELS="gemini-3.8-flash"



agy --model gemini-3.8-flash -p "Reply with PONG."
```

在受管理的工作站上，管理员可分发如下 `admin_settings.json`（Linux 路径为 `/etc/antigravity/admin_settings.json`）。每位开发者通过 `AGY_LLM_GATEWAY_API_KEY` 提供自己的调用方 Key。CLI 逐项读取配置，管理员文件优先，其次是环境变量，最后是用户的 `~/.antigravity/settings.json`。参阅 [Google 的网关配置说明](https://docs.cloud.google.com/gemini/enterprise/docs/ai-developer-tools/deploy-enterprise-gateway#settings-precedence)。

admin\_settings.json

```
{

  "gateway": {

    "enabled": true,

    "url": "https://gateway.example.com",

    "wireProtocol": "genai"

  },

  "models": {

    "defaultModelId": "gemini-3.8-flash",

    "list": [{"modelId": "gemini-3.8-flash"}]

  }

}
```

## 验证生成与工具调用[​](#verify-generation-and-tool-calls "验证生成与工具调用的直接链接")

使用同一别名和调用方 Key 向网关发送请求，即可获取单个 JSON 响应。

```
curl -sS "$AGY_LLM_GATEWAY_URL/v1beta/models/gemini-3.8-flash:generateContent" \

  -H "Authorization: Bearer $AGY_LLM_GATEWAY_API_KEY" \

  -H "Content-Type: application/json" \

  -d '{"contents":[{"role":"user","parts":[{"text":"Reply with PONG."}]}]}'
```

成功响应的 `candidates[].content.parts[]` 中包含文本。要逐条接收服务器发送事件（SSE），请使用 `curl -N`，并将后缀改为 `:streamGenerateContent?alt=sse`。两种操作均使用 `POST`，网关支持以下两种路径前缀。

* `/v1beta/models/{alias}`
* `/v1beta1/projects/{project}/locations/{location}/publishers/google/models/{alias}`

两种前缀都由 AISIX 解析模型别名。如果现有的[透传路由](https://docs.apiseven.com/ai-gateway/endpoints/provider-passthrough.md)匹配主机或路径，网关优先使用该路由。要确认实际调用的上游，请查看上游请求日志。Google 收到的路径为 `/v1beta/models/{upstream-model}` 加对应的生成操作。Copilot 收到的路径为 `/chat/completions`，上游模型 ID 位于 JSON 请求体中。

要验证工具往返，请在新的工作目录中创建一个文件，再启动交互会话。

```
cd "$(mktemp -d)"

openssl rand -hex 16 > marker.txt

agy --model gemini-3.8-flash -i "Use read_file to read marker.txt and reply with its exact contents."
```

上游分别采用 Google 的 `gemini-3.6-flash` 和 Copilot Chat 的 `claude-haiku-5.5` 时，`agy` 1.5.15 都通过 `:streamGenerateContent?alt=sse` 收到 `read_file` 调用，在本地读取文件，并用 `functionResponse` 回传内容。最终回复与文件内容一致。转发至 Copilot 时，AISIX 会将未携带 ID 的结果与最早发出且尚未收到结果的同名调用配对，并填写匹配的 Chat Completions `tool_call_id`。转发至 Google 时，网关保留原生工具调用历史，包括模型返回的 `thoughtSignature`。
