diff --git a/README.md b/README.md index b5d9b85..49a1263 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,15 @@ Convert Kiro accounts to OpenAI / Anthropic compatible API service. [English](README.md) | [中文](README_CN.md) +If this project helps you, a Star would mean a lot. + ## Features -- 🔄 **Anthropic Claude API** - Full support for `/v1/messages` endpoint -- 🤖 **OpenAI Chat API** - Compatible with `/v1/chat/completions` -- ⚖️ **Multi-Account Pool** - Round-robin load balancing -- 🔐 **Auto Token Refresh** - Seamless token management -- 📡 **Streaming** - Real-time SSE responses -- 🎛️ **Web Admin Panel** - Easy account management -- 🔑 **Multiple Auth Methods** - AWS Builder ID, IAM Identity Center (Enterprise SSO), SSO Token, Local Cache, Credentials -- 📊 **Usage Tracking** - Monitor requests, tokens, and credits -- 📦 **Account Export/Import** - Compatible with Kiro Account Manager format -- 🔄 **Dynamic Model List** - Auto-synced from Kiro API with caching -- 🔔 **Version Update Check** - Automatic new version notification -- 🌐 **i18n** - Chinese / English admin panel +- Anthropic `/v1/messages` & OpenAI `/v1/chat/completions` +- Multi-account pool with round-robin load balancing +- Auto token refresh, SSE streaming, Web admin panel +- Multiple auth: AWS Builder ID, IAM Identity Center (Enterprise SSO), SSO Token, local cache, credentials JSON +- Usage tracking, account import/export, i18n (CN / EN) ## Quick Start @@ -30,19 +25,13 @@ Convert Kiro accounts to OpenAI / Anthropic compatible API service. ```bash git clone https://github.com/Quorinex/Kiro-Go.git cd Kiro-Go - -# Create data directory for persistence mkdir -p data - docker-compose up -d ``` ### Docker Run ```bash -# Create data directory -mkdir -p /path/to/data - docker run -d \ --name kiro-go \ -p 8080:8080 \ @@ -52,8 +41,6 @@ docker run -d \ ghcr.io/quorinex/kiro-go:latest ``` -> 📁 The `/app/data` volume stores `config.json` with accounts and settings. Mount it for data persistence. - ### Build from Source ```bash @@ -63,22 +50,29 @@ go build -o kiro-go . ./kiro-go ``` -## Configuration +Config is auto-created at `data/config.json`. Mount `/app/data` for persistence. The default admin password is `changeme` — override it via the `ADMIN_PASSWORD` env var or change it in the admin panel before going to production. -Config file is auto-created at `data/config.json` on first run: +## Usage -```json -{ - "password": "changeme", - "port": 8080, - "host": "127.0.0.1", - "requireApiKey": false, - "apiKey": "", - "accounts": [] -} +Open `http://localhost:8080/admin`, log in, add accounts, then call the API: + +```bash +# Claude +curl http://localhost:8080/v1/messages \ + -H "Content-Type: application/json" \ + -H "anthropic-version: 2023-06-01" \ + -d '{"model":"claude-sonnet-4.5","max_tokens":1024,"messages":[{"role":"user","content":"Hello!"}]}' + +# OpenAI +curl http://localhost:8080/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer any" \ + -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello!"}]}' ``` -> ⚠️ **Change the default password before production use!** +## Thinking Mode + +Append a suffix (default `-thinking`) to the model name, e.g. `claude-sonnet-4.5-thinking`. Configure output format in the admin panel under Settings - Thinking Mode. ## Environment Variables @@ -87,168 +81,17 @@ Config file is auto-created at `data/config.json` on first run: | `CONFIG_PATH` | Config file path | `data/config.json` | | `ADMIN_PASSWORD` | Admin panel password (overrides config) | - | -## Usage +## Contributing -### 1. Access Admin Panel +Friendly discussion is welcome. If you run into issues, try asking Claude Code, Codex, or similar tools for help first — most problems can be solved that way. PRs are even better. -Open `http://localhost:8080/admin` and login with your password. +## Friend Links -### 2. Add Accounts - -Multiple methods available: - -| Method | Description | -|--------|-------------| -| **AWS Builder ID** | Login with AWS Builder ID (personal accounts) | -| **IAM Identity Center (Enterprise SSO)** | Login with IAM Identity Center (enterprise accounts) | -| **SSO Token** | Import `x-amz-sso_authn` token from browser | -| **Kiro Local Cache** | Import from local Kiro IDE cache files | -| **Credentials JSON** | Import JSON from Kiro Account Manager | - -#### Credentials Format - -```json -{ - "refreshToken": "eyJ...", - "accessToken": "eyJ...", - "clientId": "xxx", - "clientSecret": "xxx" -} -``` - -### 3. Call API - -#### Claude API - -```bash -curl http://localhost:8080/v1/messages \ - -H "Content-Type: application/json" \ - -H "anthropic-version: 2023-06-01" \ - -d '{ - "model": "claude-sonnet-4-20250514", - "max_tokens": 1024, - "messages": [{"role": "user", "content": "Hello!"}] - }' -``` - -#### OpenAI API - -```bash -curl http://localhost:8080/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer any" \ - -d '{ - "model": "gpt-4o", - "messages": [{"role": "user", "content": "Hello!"}] - }' -``` - -## Model Mapping - -| Request Model | Actual Model | -|---------------|--------------| -| `claude-sonnet-4-20250514` | claude-sonnet-4-20250514 | -| `claude-sonnet-4.5` | claude-sonnet-4.5 | -| `claude-haiku-4.5` | claude-haiku-4.5 | -| `claude-opus-4.5` | claude-opus-4.5 | -| `claude-opus-4.6` | claude-opus-4.6 | -| `gpt-4o`, `gpt-4` | claude-sonnet-4-20250514 | -| `gpt-3.5-turbo` | claude-sonnet-4-20250514 | - -## Thinking Mode - -Enable extended thinking by adding a suffix to the model name (default: `-thinking`). - -### Usage - -```bash -# OpenAI API with thinking -curl http://localhost:8080/v1/chat/completions \ - -H "Content-Type: application/json" \ - -d '{ - "model": "claude-sonnet-4.5-thinking", - "messages": [{"role": "user", "content": "Solve this step by step: 15 * 23"}], - "stream": true - }' - -# Claude API with thinking -curl http://localhost:8080/v1/messages \ - -H "Content-Type: application/json" \ - -H "anthropic-version: 2023-06-01" \ - -d '{ - "model": "claude-sonnet-4.5-thinking", - "max_tokens": 4096, - "messages": [{"role": "user", "content": "Analyze this problem"}] - }' -``` - -### Configuration - -Configure thinking mode in the Admin Panel under **Settings > Thinking Mode Settings**: - -| Setting | Description | Options | -|---------|-------------|---------| -| **Trigger Suffix** | Model name suffix to enable thinking | Default: `-thinking` (customizable, e.g., `-think`, `-reason`) | -| **OpenAI Output Format** | How thinking content is returned in OpenAI API | `reasoning_content` (DeepSeek compatible), `` tag, `` tag | -| **Claude Output Format** | How thinking content is returned in Claude API | `` tag (default), `` tag, plain text | - -### Output Formats - -**OpenAI API (`/v1/chat/completions`)**: -- `reasoning_content` - Thinking in separate `reasoning_content` field (DeepSeek compatible) -- `thinking` - Thinking wrapped in `...` tags in content -- `think` - Thinking wrapped in `...` tags in content - -**Claude API (`/v1/messages`)**: -- `thinking` - Thinking wrapped in `...` tags (default) -- `think` - Thinking wrapped in `...` tags -- `reasoning_content` - Plain text output - -## API Endpoints - -| Endpoint | Description | -|----------|-------------| -| `GET /health` | Health check | -| `GET /v1/models` | List models | -| `GET /v1/stats` | Statistics | -| `POST /v1/messages` | Claude Messages API | -| `POST /v1/messages/count_tokens` | Token counting | -| `POST /v1/chat/completions` | OpenAI Chat API | -| `GET /admin` | Admin panel | - -## Project Structure - -``` -Kiro-Go/ -├── main.go # Entry point -├── version.json # Version info for update check -├── config/ # Configuration management -├── pool/ # Account pool & load balancing -├── proxy/ # API handlers & Kiro client -│ ├── handler.go # HTTP routing & admin API -│ ├── kiro.go # Kiro API client -│ ├── kiro_api.go # Kiro REST API (usage, models) -│ └── translator.go # Request/response conversion -├── auth/ # Authentication -│ ├── builderid.go # AWS Builder ID login -│ ├── iam_sso.go # IAM SSO login -│ ├── oidc.go # OIDC token refresh -│ └── sso_token.go # SSO token import -├── web/ # Admin panel frontend -├── Dockerfile -└── docker-compose.yml -``` +- [LINUX DO](https://linux.do) ## Disclaimer -This project is provided for **educational and research purposes only**. - -- This software is not affiliated with, endorsed by, or associated with Amazon, AWS, or Kiro in any way -- Users are solely responsible for ensuring their use complies with all applicable terms of service and laws -- The authors assume no liability for any misuse or violations arising from the use of this software -- Use at your own risk - -By using this software, you acknowledge that you have read and understood this disclaimer. +For educational and research purposes only. Not affiliated with Amazon, AWS, or Kiro. Users are responsible for complying with applicable terms of service and laws. Use at your own risk. ## License diff --git a/README_CN.md b/README_CN.md index 750884b..b6b79d2 100644 --- a/README_CN.md +++ b/README_CN.md @@ -8,20 +8,15 @@ [English](README.md) | 中文 +如果这个项目帮到了你,欢迎点个 Star 支持一下。 + ## 功能特性 -- 🔄 **Anthropic Claude API** - 完整支持 `/v1/messages` 端点 -- 🤖 **OpenAI Chat API** - 兼容 `/v1/chat/completions` -- ⚖️ **多账号池** - 轮询负载均衡 -- 🔐 **自动刷新 Token** - 无缝 Token 管理 -- 📡 **流式响应** - 实时 SSE 输出 -- 🎛️ **Web 管理面板** - 便捷的账号管理 -- 🔑 **多种认证方式** - AWS Builder ID、IAM Identity Center (企业 SSO)、SSO Token、本地缓存、凭证 JSON -- 📊 **用量追踪** - 监控请求数、Token、Credits -- 📦 **账号导入导出** - 兼容 Kiro Account Manager 格式 -- 🔄 **动态模型列表** - 自动从 Kiro API 同步并缓存 -- 🔔 **版本更新检测** - 自动提醒新版本 -- 🌐 **中英双语** - 管理面板支持中文 / 英文 +- Anthropic `/v1/messages` 与 OpenAI `/v1/chat/completions` +- 多账号池轮询负载均衡 +- 自动 Token 刷新、SSE 流式输出、Web 管理面板 +- 多种认证方式:AWS Builder ID、IAM Identity Center (企业 SSO)、SSO Token、本地缓存、凭证 JSON +- 用量追踪、账号导入导出、中英双语 ## 快速开始 @@ -30,19 +25,13 @@ ```bash git clone https://github.com/Quorinex/Kiro-Go.git cd Kiro-Go - -# 创建数据目录用于持久化 mkdir -p data - docker-compose up -d ``` ### Docker 运行 ```bash -# 创建数据目录 -mkdir -p /path/to/data - docker run -d \ --name kiro-go \ -p 8080:8080 \ @@ -52,8 +41,6 @@ docker run -d \ ghcr.io/quorinex/kiro-go:latest ``` -> 📁 `/app/data` 卷存储 `config.json`(包含账号和设置),挂载此目录以实现数据持久化。 - ### 源码编译 ```bash @@ -63,22 +50,29 @@ go build -o kiro-go . ./kiro-go ``` -## 配置 +首次运行会在 `data/config.json` 自动生成配置,挂载 `/app/data` 以持久化。默认管理密码为 `changeme`,生产环境请务必通过 `ADMIN_PASSWORD` 环境变量或在管理面板中修改。 -首次运行会自动创建 `data/config.json`: +## 使用方法 -```json -{ - "password": "changeme", - "port": 8080, - "host": "127.0.0.1", - "requireApiKey": false, - "apiKey": "", - "accounts": [] -} +访问 `http://localhost:8080/admin` 登录、添加账号,然后调用 API: + +```bash +# Claude +curl http://localhost:8080/v1/messages \ + -H "Content-Type: application/json" \ + -H "anthropic-version: 2023-06-01" \ + -d '{"model":"claude-sonnet-4.5","max_tokens":1024,"messages":[{"role":"user","content":"你好!"}]}' + +# OpenAI +curl http://localhost:8080/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer any" \ + -d '{"model":"gpt-4o","messages":[{"role":"user","content":"你好!"}]}' ``` -> ⚠️ **生产环境请务必修改默认密码!** +## 思考模式 + +在模型名后加后缀(默认 `-thinking`)即可启用,例如 `claude-sonnet-4.5-thinking`。输出格式可在管理面板「设置 - Thinking 模式」中配置。 ## 环境变量 @@ -87,168 +81,17 @@ go build -o kiro-go . | `CONFIG_PATH` | 配置文件路径 | `data/config.json` | | `ADMIN_PASSWORD` | 管理面板密码(覆盖配置文件) | - | -## 使用方法 +## 参与贡献 -### 1. 访问管理面板 +欢迎友好交流。遇到问题时,建议先让 Claude Code、Codex 等工具帮忙排查一下,大部分问题都能自己解决。如果能直接提个 PR 就更好了。 -打开 `http://localhost:8080/admin`,输入密码登录。 +## 友情链接 -### 2. 添加账号 - -支持多种方式: - -| 方式 | 说明 | -|------|------| -| **AWS Builder ID** | 通过 AWS Builder ID 授权登录(个人账号) | -| **IAM Identity Center (企业 SSO) 登录** | 通过 IAM Identity Center (企业 SSO) 授权登录(企业账号) | -| **SSO Token** | 通过浏览器 `x-amz-sso_authn` Token 添加账号 | -| **Kiro 本地缓存** | 通过 Kiro IDE 本地缓存文件添加账号 | -| **凭证 JSON** | 通过 Kiro Account Manager 导出的凭证添加账号 | - -#### 凭证格式 - -```json -{ - "refreshToken": "eyJ...", - "accessToken": "eyJ...", - "clientId": "xxx", - "clientSecret": "xxx" -} -``` - -### 3. 调用 API - -#### Claude API - -```bash -curl http://localhost:8080/v1/messages \ - -H "Content-Type: application/json" \ - -H "anthropic-version: 2023-06-01" \ - -d '{ - "model": "claude-sonnet-4-20250514", - "max_tokens": 1024, - "messages": [{"role": "user", "content": "你好!"}] - }' -``` - -#### OpenAI API - -```bash -curl http://localhost:8080/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer any" \ - -d '{ - "model": "gpt-4o", - "messages": [{"role": "user", "content": "你好!"}] - }' -``` - -## 模型映射 - -| 请求模型 | 实际模型 | -|---------|---------| -| `claude-sonnet-4-20250514` | claude-sonnet-4-20250514 | -| `claude-sonnet-4.5` | claude-sonnet-4.5 | -| `claude-haiku-4.5` | claude-haiku-4.5 | -| `claude-opus-4.5` | claude-opus-4.5 | -| `claude-opus-4.6` | claude-opus-4.6 | -| `gpt-4o`, `gpt-4` | claude-sonnet-4-20250514 | -| `gpt-3.5-turbo` | claude-sonnet-4-20250514 | - -## 思考模式 - -在模型名称后添加后缀(默认:`-thinking`)即可启用扩展思考模式。 - -### 使用方法 - -```bash -# OpenAI API 启用思考 -curl http://localhost:8080/v1/chat/completions \ - -H "Content-Type: application/json" \ - -d '{ - "model": "claude-sonnet-4.5-thinking", - "messages": [{"role": "user", "content": "一步步解决:15 * 23"}], - "stream": true - }' - -# Claude API 启用思考 -curl http://localhost:8080/v1/messages \ - -H "Content-Type: application/json" \ - -H "anthropic-version: 2023-06-01" \ - -d '{ - "model": "claude-sonnet-4.5-thinking", - "max_tokens": 4096, - "messages": [{"role": "user", "content": "分析这个问题"}] - }' -``` - -### 配置 - -在管理面板的 **设置 > Thinking 模式设置** 中配置: - -| 设置 | 说明 | 选项 | -|-----|------|------| -| **触发后缀** | 启用思考的模型名称后缀 | 默认:`-thinking`(可自定义,如 `-think`、`-sikao`) | -| **OpenAI 输出格式** | OpenAI API 中思考内容的返回方式 | `reasoning_content`(DeepSeek 兼容)、`` 标签、`` 标签 | -| **Claude 输出格式** | Claude API 中思考内容的返回方式 | `` 标签(默认)、`` 标签、纯文本 | - -### 输出格式说明 - -**OpenAI API (`/v1/chat/completions`)**: -- `reasoning_content` - 思考内容放在单独的 `reasoning_content` 字段(DeepSeek 兼容) -- `thinking` - 思考内容用 `...` 标签包裹在 content 中 -- `think` - 思考内容用 `...` 标签包裹在 content 中 - -**Claude API (`/v1/messages`)**: -- `thinking` - 思考内容用 `...` 标签包裹(默认) -- `think` - 思考内容用 `...` 标签包裹 -- `reasoning_content` - 纯文本输出 - -## API 端点 - -| 端点 | 说明 | -|-----|------| -| `GET /health` | 健康检查 | -| `GET /v1/models` | 模型列表 | -| `GET /v1/stats` | 统计数据 | -| `POST /v1/messages` | Claude Messages API | -| `POST /v1/messages/count_tokens` | Token 计数 | -| `POST /v1/chat/completions` | OpenAI Chat API | -| `GET /admin` | 管理面板 | - -## 项目结构 - -``` -Kiro-Go/ -├── main.go # 入口 -├── version.json # 版本信息(用于更新检测) -├── config/ # 配置管理 -├── pool/ # 账号池 & 负载均衡 -├── proxy/ # API 处理 & Kiro 客户端 -│ ├── handler.go # HTTP 路由 & 管理 API -│ ├── kiro.go # Kiro API 客户端 -│ ├── kiro_api.go # Kiro REST API(用量、模型) -│ └── translator.go # 请求/响应转换 -├── auth/ # 认证 -│ ├── builderid.go # AWS Builder ID 登录 -│ ├── iam_sso.go # IAM SSO 登录 -│ ├── oidc.go # OIDC Token 刷新 -│ └── sso_token.go # SSO Token 导入 -├── web/ # 管理面板前端 -├── Dockerfile -└── docker-compose.yml -``` +- [LINUX DO](https://linux.do) ## 免责声明 -本项目仅供**学习和研究目的**使用。 - -- 本软件与 Amazon、AWS 或 Kiro 没有任何关联、认可或合作关系 -- 用户需自行确保其使用行为符合所有适用的服务条款和法律法规 -- 作者不对因使用本软件而产生的任何滥用或违规行为承担责任 -- 使用风险自负 - -使用本软件即表示您已阅读并理解本免责声明。 +本项目仅供学习和研究目的使用,与 Amazon、AWS 或 Kiro 没有任何关联。用户需自行确保使用行为符合所有适用的服务条款和法律法规,使用风险自负。 ## 许可证