标签 CPA 下的文章

配置多实例 CPA 和代理池~【不推荐使用】更正:【反重力 2api】antigravity-manager 的 429 频率和 CPA 没有太大区别 继续讨论:

既然 CPA 和 antigravity-Manager 没有本质区别,而 CPA 的部署方式更符合我的习惯,那就微调下前端吧

前排叠甲:非官方功能,谨慎使用,如有封禁,概不负责

为认证文件 单独 / 批量代理配置:

设置后会对 json 文件的 proxy_url 进行覆盖操作,已设置的显示为黄色。

反重力凭证,批量 / 单个配置 User Agent header

目前反重力的 user agent 字段写死的老版本值,会在请求时候带上

让 cc 分析了代码,应该会穿透到真实请求上,待测试 (测试完毕会去除这个文本)

凭证 JSON 文件编辑

把原来的凭证信息按钮给删掉了,感觉没啥用,换成了原始 JSON 在线编辑

一些无关紧要的:

信息脱敏按钮

偏好设置浏览器保存:

原来是修改后,更换页面就失效,现在会存在浏览器中,主要是 分页配置 和 脱敏展示按钮

使用方式:

config.yaml 的 panel-github-repository 字段更换为我的仓库地址 https://github.com/escapeWu/Cli-Proxy-API-Management-Center

项目地址:


📌 转载信息
原作者:
shan_CW
转载时间:
2026/1/23 09:04:55

背景

使用 CPA 作为 API 代理,配合 OpenCode,想要通过 OpenAI 兼容格式调用 Gemini 3
系列模型。

环境配置:

  • CPA 部署在自用云服务器,配置了 OpenAI 兼容转发
  • 上游服务:https://***.com(支持多模型的 API 服务|newapi)
  • 本地客户端:OpenCode


问题现象

  1. 第一个错误:404 Not Found
  • POST “/v1/models/gemini-3-flash-preview:streamGenerateContent?alt=sse” 404

  • 请求直接返回 404,模型无法调用。

  1. 第二个错误:Invalid Role
  • 修复 404 后,出现新错误:

  • Invalid param: Please use a valid role: user, model.


问题分析

  1. 404 问题分析
  • 查看 CPA 日志发现请求路径是:/v1/models/gemini-3-flash-preview:streamGenerateContent?alt=sse; 这是 Gemini 原生 API 格式,而不是 OpenAI 兼容格式 (/v1/chat/completions)。

  • 原因:OpenCode 检测到模型名包含 gemini 关键字,自动切换到 Gemini 原生协议。

  1. Invalid Role 问题分析
  • 修复 404 后,查看日志发现请求走的是:POST “/v1/responses” 400; 这是 OpenAI 新的 Responses API(用于 GPT-5.x 等新模型),而不是传统的 /v1/chat/completions。

  • 原因:OpenCode 配置中 openai provider 包含 reasoningEffort 等参数,触发了新 API 格式。而 Responses API 使用 role: “assistant”,Gemini API 期望 role:“model”,上游服务没有正确转换角色名。


解决方案

  1. 步骤 1:CPA 配置 - 给 Gemini 模型设置别名

修改服务器上的 /path/to/cpa/config.yaml,给 Gemini 模型设置不含 “gemini” 关键字的别名:

 openai-compatibility: - name: claude base-url: https://***.com/v1 api-key-entries: - api-key: sk-xxxxx models: # Claude 模型 - name: claude-opus-4-5-20251101 alias: claude-opus-4-5 # Gemini 模型 - 使用不含 "gemini" 的别名 - name: gemini-3-flash-preview alias: "g3-flash-preview" - name: gemini-3-pro-preview alias: "g3-pro-preview" - name: gemini-3-pro-image-preview alias: "g3-pro-image-preview" 

重启 CPA 容器:
docker restart cpa

  1. 步骤 2:OpenCode 配置 - 创建独立 Provider
    关键点:不要把 Gemini 模型放在带有 reasoningEffort 等参数的 openai provider
    下,否则会触发 Responses API。
    创建一个独立的 provider:
{ "provider": { "openai": { "name": "OpenAI", "options": { "baseURL": "https://***.com/v1", "apiKey": "your-key", "reasoningEffort": "medium" // 这会触发 Responses API }, "models": { "gpt-5.2": { ... } // GPT 模型放这里 } }, "openai-compat": { "name": "Gemini via CPA", "options": { "baseURL": "https://***.com/v1", "apiKey": "your-key" // 注意:不要加 reasoningEffort 等参数! }, "models": { "g3-pro-preview": { "name": "Gemini 3 Pro Preview", "limit": { "context": 1048576, "output": 65535 } }, "g3-flash-preview": { "name": "Gemini 3 Flash Preview", "limit": { "context": 1048576, "output": 65535 } }, "g3-pro-image-preview": { "name": "Gemini 3 Pro Image Preview", "limit": { "context": 1048576, "output": 65536 } } } } } } 


问题总结

问题原因解决方案
404 错误模型名含 gemini,OpenCode 自动用 Gemini 原生协议设置不含 gemini 的别名
Invalid RolereasoningEffort 参数触发 Responses API,角色名不兼容创建独立 provider,不加 reasoning 参数


关键

  1. 模型名称很重要:某些客户端会根据模型名自动选择协议,避免使用原厂商关键字(如 gemini、claude)可以强制走 OpenAI 兼容格式。
  2. OpenAI API 有两套格式:
    • 传统:/v1/chat/completions
    • 新版:/v1/responses(GPT-5.x,带 reasoning 功能)

自用经验仅供参考


📌 转载信息
转载时间:
2026/1/21 21:42:07

目前账号是 anti-gravity tools 工具,但是反代要用到 cpa,每次授权两次很麻烦,于是写了一个格式互转的工具以及 cpa 反重力 429 服务修复。现在如果要导入导出到 cpa 或者 anti-gravity tools 工具是相当方便了

https://lovable.dev/


📌 转载信息
原作者:
124sadas
转载时间:
2026/1/20 11:07:31

昨晚开始开始入手 OpenCode ,整理了一份从零开始的安装与配置笔记,分享给各位佬友。

第一阶段:基础安装与核心插件

1. 安装 OpenCode

推荐使用 brew 安装,稳定性更高:

  • macOS/Linux: brew install anomalyco/tap/opencode
  • Node 环境: npm i -g opencode-ai

2. 必装 “全家桶” 插件

安装完成后先输入 opencode 启动(能白嫖 GLM4.7),然后在会话中直接粘贴以下链接安装 oh-my-opencode

Install and configure by following the instructions here https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/refs/heads/master/README.md

进阶推荐:

  • opencode-dcp: 自动清理对话历史中过时的工具输出,显著减少 Token 消耗。

第二阶段:进阶配置(接入 OneAPI / 中转站)

由于 OpenCode CLI 执行任务时会有大量 Tool Use 调用,普通 URL 转发容易协议报错。这里推荐使用 CLIProxyAPI (CPA) 进行协议转换。

1. 部署 CPA 环境

建议直接走 Source Build,日志更透明:

git clone https://github.com/router-for-me/CLIProxyAPI.git
cd CLIProxyAPI
go mod download
go run main.go # 启动 

2. CPA 核心配置 (config.yaml)

坑点: 字段名必须准确,否则会静默失败。

  • 确保使用 auth-dir 而不是旧版的 credentials-directory
  • 供应商字段是 openai-api-keys(复数,带 s)。
port: 8317 auth-dir: "/绝对路径/auth" allow-unauthenticated: true # 本地调试建议开启 openai-api-keys: - api-key: "sk-OneAPI令牌" base-url: "https://OneAPI地址/v1" models: - id: "claude-opus-4-5" # OpenCode 中显示的名称 map-to: "claude-opus-4-5-20251101" # OneAPI 后台真实 ID 

第三阶段:OpenCode 配置文件打通

修改 ~/.config/opencode/opencode.json。因为 CPA 侧开了免密,这里直接配置 Provider 即可:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": [
    "oh-my-opencode",
    "@tarquinen/opencode-dcp@latest"
  ],
  "provider": {
    "anthropic": {
      "options": {
        "baseURL": "http://127.0.0.1:8317/v1"
      }
    }
  }
}

踩坑

  1. 代理污染(502 报错):如果终端开了 http_proxy,请求 localhost 可能会被劫持导致失败。执行前记得:unset http_proxy https_proxy all_proxy 或者使用 curl -v --noproxy “*” http://127.0.0.1:8317/v1/models 测试连通性。
  2. Thinking 模式没显示?:按 Ctrl + P,搜索 think 即可手动开启或关闭思维链显示。
  3. YAML 解析失败:Go 解析路径时对~/ 支持不佳,建议在 config.yaml 中全部使用绝对路径。

管理端 UI


📌 转载信息
转载时间:
2026/1/15 18:27:44

继【 OpenCode - CPA - OneAPI 】 :

现象:

ValidationException: messages: text content blocks must be non-empty

原因分析:

  1. OpenCode 在工具调用后,assistant 消息可能只有 tool_calls 没有文字内容
  2. CPA 转换时设置 content: “”(空字符串)
  3. AWS Bedrock 比标准 OpenAI API 更严格,不接受空的 content

解决:

修改 CPA 源码 internal/translator/openai/claude/openai_claude_request.go

// 修复前
msgJSON, _ = sjson.Set(msgJSON, "content", "")

// 修复后:用空格替代空字符串
msgJSON, _ = sjson.Set(msgJSON, "content", " ")


📌 转载信息
转载时间:
2026/1/15 18:13:43

之前分享了一个 opencode 的配置,大家也给我提了很多意见,感谢大家!!!

但是我在使用 opencode 的时候当上下文快满的时候自动进行上下文压缩,但是会报错,然后我尝试了手动压缩 /compact 指令,我发现了一个很有意思的现象,当我不使用工具调用的时候可以正常压缩,但是我只要使用工具调用就报错:Bad Request: Improperly formed request. 所以我就猜测是因为思考块里面带了工具调用,致使 CPA 不支持,所以我就开始改 CPA,修复逻辑如下

然后吭哧吭哧改了两天,调了很多次,最后可以正常压缩了,但是工具调用的时候一直循环,无奈宣告失败。。。

但是,我在查文档的时候发现压缩上下文的也是一个子代理,默认使用的是主模型,那既然这样,我换一个模型不就行了,直接开干,因为我设置了 google 的 api 所以我用的是 google 模型。



正常工作,果然,opencode 的高自定义程度名不虚传,好玩爱玩,如果有佬有更好的方法,欢迎分享,在此献上我的 opencode.json 文件,大家可以看看:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "cpa-claude/kiro-claude-opus-4-5-agentic(high)",
  "agent": {
    "compaction": {
      "model": "google/antigravity-gemini-3-pro-low"
    }
  },
  "plugin": [
    "oh-my-opencode",
    "opencode-antigravity-auth@1.2.8",
    "opencode-openai-codex-auth@4.3.0"
  ],
  "provider": {
    "cpa-claude": {
      "npm": "@ai-sdk/anthropic",
      "name": "cpa-claude",
      "options": {
        "baseURL": "http://127.0.0.1:8317/v1"},
      "models": {
        "gemini-claude-opus-4-5-thinking(high)": {
          "name": "gemini-claude-opus-4-5-thinking(high)",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        },
        "gemini-claude-sonnet-4-5-thinking(high)": {
          "name": "gemini-claude-sonnet-4-5-thinking(high)",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        },
        "kiro-claude-sonnet-4-5-agentic": {
          "name": "claude-sonnet-4-5-nothinking",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kiro-claude-sonnet-4-5-agentic(high)": {
          "name": "claude-sonnet-4-5",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        },
        "kiro-claude-opus-4-5-agentic(high)": {
          "name": "claude-opus-4-5",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        }
      }
    },
    "cpa-gemini": {
      "name": "cpa-gemini",
      "options": {
        "baseURL": "http://127.0.0.1:8317/v1"
      },
      "models": {
        "gemini-3-pro-preview": {
          "name": "gemini-3-pro-preview",
          "limit": {
            "context": 1048576,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        },
        "gemini-3-flash-preview": {
          "name": "gemini-3-flash-preview",
          "limit": {
            "context": 1048576,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        }
      }
    },
    "google": {
      "name": "Google",
      "models": {
        "antigravity-gemini-3-pro-high": {
          "name": "Gemini 3 Pro High (Antigravity)",
          "thinking": true,
          "attachment": true,
          "limit": {
            "context": 1048576,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          }
        },
        "antigravity-gemini-3-pro-low": {
          "name": "Gemini 3 Pro Low (Antigravity)",
          "thinking": true,
          "attachment": true,
          "limit": {
            "context": 1048576,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          }
        },
        "antigravity-gemini-3-flash": {
          "name": "Gemini 3 Flash (Antigravity)",
          "attachment": true,
          "limit": {
            "context": 1048576,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          }
        }
      }
    },
    "openai": {
      "name": "OpenAI",
      "options": {
        "reasoningEffort": "medium",
        "reasoningSummary": "auto",
        "textVerbosity": "medium",
        "include": [
          "reasoning.encrypted_content"
        ],
        "store": false
      },
      "models": {
        "gpt-5.2": {
          "name": "GPT 5.2 (OAuth)",
          "limit": {
            "context": 272000,
            "output": 128000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          },
          "variants": {
            "none": {
              "reasoningEffort": "none",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "low": {
              "reasoningEffort": "low",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "medium": {
              "reasoningEffort": "medium",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "high": {
              "reasoningEffort": "high",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            }
          }
        },
        "gpt-5.2-codex": {
          "name": "GPT 5.2 Codex (OAuth)",
          "limit": {
            "context": 272000,
            "output": 128000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          },
          "variants": {
            "low": {
              "reasoningEffort": "low",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "medium": {
              "reasoningEffort": "medium",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "high": {
              "reasoningEffort": "high",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            }
          }
        },
        "gpt-5.1-codex-max": {
          "name": "GPT 5.1 Codex Max (OAuth)",
          "limit": {
            "context": 272000,
            "output": 128000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          },
          "variants": {
            "low": {
              "reasoningEffort": "low",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "medium": {
              "reasoningEffort": "medium",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "high": {
              "reasoningEffort": "high",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            }
          }
        }
      }
    }
  }
}

除了使用 google/antigravity-gemini-3-pro-low 还可以使用 opencode 提供的免费模型,比如 GLM4.7。

当然,这个只是一个曲线救国的方法,如果有佬有更好的方法,欢迎分享!!!

配置问题可以看看之前那个帖子


📌 转载信息
原作者:
shenning
转载时间:
2026/1/14 18:31:16