opencode-foxcode-aws-cache
v1.0.4
Published
OpenCode plugin that enables prompt caching for Foxcode AWS channel by injecting metadata.user_id
Maintainers
Readme
为什么需要
Foxcode 的 AWS 渠道要求请求中必须包含 metadata.user_id 字段才能启用 Prompt 缓存。
没有此插件:每次请求都按全价计费 💸
使用此插件:自动注入 user_id,启用缓存,节省费用 ✨
🎁 还没有 Foxcode 账号?点击注册
安装
npm install -g opencode-foxcode-aws-cache配置
1. 添加插件
在 opencode.json 中添加:
{
"plugin": ["opencode-foxcode-aws-cache"]
}2. 配置 Provider
{
"provider": {
"foxcode-aws": {
"npm": "@ai-sdk/anthropic",
"options": {
"baseURL": "https://code.newcli.com/claude/droid/v1",
"litellmProxy": true
},
"models": {
"claude-opus-4-5": {
"name": "claude-opus-4-5",
"thinking": true
},
"claude-sonnet-4-5": {
"name": "claude-sonnet-4-5",
"thinking": true
},
"claude-haiku-4-5-20251001": {
"name": "claude-haiku-4-5-20251001"
}
}
}
}
}💡 关于
litellmProxy:当使用 LiteLLM 代理(如 Foxcode)时,必须设置litellmProxy: true。这可以解决 OpenCode 在上下文压缩时 API 请求格式不兼容的问题。
3. 配置 API Key
⚠️ 重要:必须使用
/connect命令创建auth.json配置 API Key,foxcode-aws 才能生效。
在 OpenCode 中运行:
/connect foxcode-aws按照提示输入你的 Foxcode API Key,这将自动创建 auth.json 配置文件。
工作原理
插件通过自定义 fetch 拦截 Anthropic API 请求,自动注入 metadata.user_id:
{
"model": "claude-...",
"messages": [...],
"metadata": {
"user_id": "user_{projectId}_account__session_{sessionId}"
}
}注意事项
⚠️ 此插件使用了未在官方文档中记录的
auth.loaderhook,未来版本可能不兼容。
致谢
本插件的实现思路参考了 @GangWangAI 在 PR #8138 中提出的方案。
许可证
MIT
