diff --git a/README-JA.md b/README-JA.md index 0e46ab8..7e3e848 100644 --- a/README-JA.md +++ b/README-JA.md @@ -4,7 +4,7 @@ # AIClient-2-API 🚀 -**複数のクライアント専用大規模言語モデルAPI(Gemini CLI、Qwen Code Plus、Kiro Claude...)を模擬リクエストし、ローカルのOpenAI互換インターフェースに統一的にラッピングする強力なプロキシ。** +**複数のクライアント専用大規模言語モデルAPI(Gemini CLI、Antigravity、Qwen Code、Kiro ...)を模擬リクエストし、ローカルのOpenAI互換インターフェースに統一的にラッピングする強力なプロキシ。** @@ -14,14 +14,15 @@ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Node.js](https://img.shields.io/badge/Node.js-≥20.0.0-green.svg)](https://nodejs.org/) -[![Docker](https://img.shields.io/badge/docker-≥20.0.0-blue.svg)](https://aiproxy.justlikemaki.vip/ja/docs/installation/docker-deployment.html) +[![Docker](https://img.shields.io/badge/docker-≥20.0.0-blue.svg)](https://hub.docker.com/r/justlikemaki/aiclient-2-api) +[![GitHub stars](https://img.shields.io/github/stars/justlovemaki/AIClient-2-API.svg?style=flat&label=Star)](https://github.com/justlovemaki/AIClient-2-API/stargazers) +[![GitHub issues](https://img.shields.io/github/issues/justlovemaki/AIClient-2-API.svg)](https://github.com/justlovemaki/AIClient-2-API/issues) - -[**中文**](./README-ZH.md) | [**English**](./README.md) | [**日本語**](./README-JA.md) | [**📚 完全ドキュメント**](https://aiproxy.justlikemaki.vip/ja/) +[中文](./README-ZH.md) | [English](./README.md) | [**👉 日本語**](./README-JA.md) | [**📚 完全ドキュメント**](https://aiproxy.justlikemaki.vip/ja/) -`AIClient2API` はクライアント制限を突破するAPIプロキシサービスで、元々クライアント内でのみ使用可能な無料大規模モデル(Gemini CLI、Qwen Code Plus、Kiro Claudeなど)を、あらゆるアプリケーションから呼び出せる標準OpenAI互換インターフェースに変換します。Node.jsをベースに構築され、OpenAI、Claude、Geminiの3大プロトコル間のインテリジェント変換をサポートし、Cherry-Studio、NextChat、Clineなどのツールで、Claude Sonnet 4.5、Gemini 2.5 Flash、Qwen3 Coder Plusなどの高度なモデルを大規模に無料で使用できるようにします。プロジェクトはストラテジーパターンとアダプターパターンに基づくモジュラーアーキテクチャを採用し、アカウントプール管理、インテリジェントポーリング、自動フェイルオーバー、ヘルスチェック機構を内蔵し、99.9%のサービス可用性を保証します。 +`AIClient2API` はクライアント制限を突破するAPIプロキシサービスで、Gemini、Antigravity、Qwen Code、Kiroなど、元々クライアント内でのみ使用可能な無料大規模モデルを、あらゆるアプリケーションから呼び出せる標準OpenAI互換インターフェースに変換します。Node.jsをベースに構築され、OpenAI、Claude、Geminiの3大プロトコル間のインテリジェント変換をサポートし、Cherry-Studio、NextChat、Clineなどのツールで、Claude Opus 4.5、Gemini 3.0 Pro、Qwen3 Coder Plusなどの高度なモデルを大規模に無料で使用できるようにします。プロジェクトはストラテジーパターンとアダプターパターンに基づくモジュラーアーキテクチャを採用し、アカウントプール管理、インテリジェントポーリング、自動フェイルオーバー、ヘルスチェック機構を内蔵し、99.9%のサービス可用性を保証します。 > [!NOTE] > **🎉 重要なマイルストーン** @@ -33,31 +34,30 @@ > - **2025.12.11** - Dockerイメージが自動的にビルドされ、Docker Hubで公開されました: [justlikemaki/aiclient-2-api](https://hub.docker.com/r/justlikemaki/aiclient-2-api) > - **2025.11.30** - Antigravityプロトコルサポートの追加、Google内部インターフェース経由でGemini 3 Pro、Claude Sonnet 4.5などのモデルへのアクセスをサポート > - **2025.11.16** - Ollamaプロトコルサポートの追加、統一インターフェースでサポートされるすべてのモデルにアクセス -> - **2025.11.11** - Web UI管理コントロールコンソールの追加、リアルタイム設定管理与健康状態モニタリングをサポート +> - **2025.11.11** - Web UI管理コントロールコンソールの追加、リアルタイム設定管理と健康状態モニタリングをサポート > - **2025.11.06** - Gemini 3 プレビュー版のサポートを追加、モデル互換性とパフォーマンス最適化を向上 > - **2025.10.18** - Kiroオープン登録、新規アカウントに500クレジット付与、Claude Sonnet 4.5を完全サポート > - **2025.09.01** - Qwen Code CLIを統合、`qwen3-coder-plus`モデルサポートを追加 > - **2025.08.29** - アカウントプール管理機能をリリース、マルチアカウントポーリング、自動フェイルオーバー、自動ダウングレード戦略をサポート > - 設定方法:config.jsonに`PROVIDER_POOLS_FILE_PATH`パラメータを追加 > - 参考設定:[provider_pools.json](./provider_pools.json.example) +> - **開発済み履歴** +> - Gemini CLI、Kiroなどのクライアント2APIをサポート +> - OpenAI、Claude、Geminiの3つのプロトコル相互変換、自動インテリジェント切り替え --- ## 💡 コアアドバンテージ ### 🎯 統一アクセス、ワンストップ管理 -* **マルチモデル統一インターフェース**:標準OpenAI互換プロトコルを通じて、一度の設定でGemini、Claude、GPT、Qwen Code、Kimi K2、GLM-4.6などの主流大規模モデルにアクセス -* **柔軟な切り替えメカニズム**:起動パラメータ、Pathルーティング、環境変数の3つの方法で動的にモデルを切り替え、異なるシナリオのニーズに対応 +* **マルチモデル統一インターフェース**:標準OpenAI互換プロトコルを通じて、一度の設定でGemini、Claude、Qwen Code、Kimi K2、MiniMax M2などの主流大規模モデルにアクセス +* **柔軟な切り替えメカニズム**:Pathルーティング、起動パラメータ、環境変数の3つの方法で動的にモデルを切り替え、異なるシナリオのニーズに対応 * **ゼロコスト移行**:OpenAI API仕様と完全互換、Cherry-Studio、NextChat、Clineなどのツールを変更なしで使用可能 * **マルチプロトコルインテリジェント変換**:OpenAI、Claude、Geminiの3大プロトコル間のインテリジェント変換をサポートし、クロスプロトコルモデル呼び出しを実現 - * OpenAIプロトコルでClaudeモデルを呼び出す:`claude-custom`または`claude-kiro-oauth`プロバイダーを使用 - * OpenAIプロトコルでGeminiモデルを呼び出す:`gemini-cli-oauth`プロバイダーを使用 - * ClaudeプロトコルでGeminiモデルを呼び出す:`gemini-cli-oauth`プロバイダーを使用 - * ClaudeプロトコルでOpenAIモデルを呼び出す:`openai-custom`または`openai-qwen-oauth`プロバイダーを使用 ### 🚀 制限を突破、効率を向上 -* **公式制限の回避**:OAuth認証メカニズムを利用して、Geminiなどの無料APIのレート制限と割り当て制限を効果的に突破 -* **無料高度モデル**:Kiro APIモードでClaude Sonnet 4.5を無料使用、Qwen OAuthモードでQwen3 Coder Plusを使用し、使用コストを削減 +* **公式制限の回避**:OAuth認証メカニズムを利用して、Gemini、Antigravityなどの無料APIのレート制限と割り当て制限を効果的に突破 +* **無料高度モデル**:Kiro APIモードでClaude Opus 4.5を無料使用、Qwen OAuthモードでQwen3 Coder Plusを使用し、使用コストを削減 * **インテリジェントアカウントプールスケジューリング**:マルチアカウントポーリング、自動フェイルオーバー、設定ダウングレードをサポートし、99.9%のサービス可用性を保証 ### 🛡️ 安全で制御可能、データ透明 @@ -66,105 +66,44 @@ * **システムプロンプト管理**:オーバーライドと追加の2つのモードをサポートし、統一された基本指示と個別拡張の完璧な組み合わせを実現 ### 🔧 開発者フレンドリー、拡張が容易 +* **Web UI管理コントロールコンソール**:リアルタイム設定管理、健全性モニタリング、APIテスト、ログ表示 * **モジュラーアーキテクチャ**:ストラテジーパターンとアダプターパターンに基づき、新しいモデルプロバイダーの追加はわずか3ステップ * **完全なテストカバレッジ**:統合テストと単体テストのカバレッジ90%+、コード品質を保証 * **コンテナ化デプロイ**:Dockerサポートを提供、ワンクリックデプロイ、クロスプラットフォーム実行 -* **MCPプロトコルサポート**:Model Context Protocolと完全互換、機能を簡単に拡張 --- ## 📑 クイックナビゲーション -- [🐳 Docker デプロイ](https://aiproxy.justlikemaki.vip/ja/docs/installation/docker-deployment.html) -- [🎨 モデルプロトコルとプロバイダー関係図](#-モデルプロトコルとプロバイダー関係図) +- [🐳 Docker デプロイ](https://hub.docker.com/r/justlikemaki/aiclient-2-api) - [🔧 使用方法](#-使用方法) -- [🚀 プロジェクト起動パラメータ](#-プロジェクト起動パラメータ) - [📄 オープンソースライセンス](#-オープンソースライセンス) - [🙏 謝辞](#-謝辞) - [⚠️ 免責事項](#-免責事項) --- -## 🎨 モデルプロトコルとプロバイダー関係図 - -本プロジェクトは異なるプロトコルを通じて複数のモデルプロバイダーをサポートします。以下はそれらの関係の概要です: - -* **OpenAIプロトコル (P_OPENAI)**:`openai-custom`、`gemini-cli-oauth`、`claude-custom`、`claude-kiro-oauth`、`openai-qwen-oauth`、`openaiResponses-custom`モデルプロバイダーによって実装。 -* **Claudeプロトコル (P_CLAUDE)**:`claude-custom`、`claude-kiro-oauth`、`gemini-cli-oauth`、`openai-custom`、`openai-qwen-oauth`、`openaiResponses-custom`モデルプロバイダーによって実装。 -* **Geminiプロトコル (P_GEMINI)**:`gemini-cli-oauth`モデルプロバイダーによって実装。 - -詳細な関係図: - - ```mermaid - - graph TD - subgraph Core_Protocols["コアプロトコル"] - P_OPENAI[OpenAI Protocol] - P_GEMINI[Gemini Protocol] - P_CLAUDE[Claude Protocol] - end - - subgraph Supported_Model_Providers["サポートモデルプロバイダー"] - MP_OPENAI[openai-custom] - MP_GEMINI[gemini-cli-oauth] - MP_CLAUDE_C[claude-custom] - MP_CLAUDE_K[claude-kiro-oauth] - MP_QWEN[openai-qwen-oauth] - MP_OPENAI_RESP[openaiResponses-custom] - end - - P_OPENAI ---|サポート| MP_OPENAI - P_OPENAI ---|サポート| MP_QWEN - P_OPENAI ---|サポート| MP_GEMINI - P_OPENAI ---|サポート| MP_CLAUDE_C - P_OPENAI ---|サポート| MP_CLAUDE_K - P_OPENAI ---|サポート| MP_OPENAI_RESP - - P_GEMINI ---|サポート| MP_GEMINI - - P_CLAUDE ---|サポート| MP_CLAUDE_C - P_CLAUDE ---|サポート| MP_CLAUDE_K - P_CLAUDE ---|サポート| MP_GEMINI - P_CLAUDE ---|サポート| MP_OPENAI - P_CLAUDE ---|サポート| MP_QWEN - P_CLAUDE ---|サポート| MP_OPENAI_RESP - - style P_OPENAI fill:#f9f,stroke:#333,stroke-width:2px - style P_GEMINI fill:#ccf,stroke:#333,stroke-width:2px - style P_CLAUDE fill:#cfc,stroke:#333,stroke-width:2px - - ``` - ---- - ## 🔧 使用方法 -### 🚀 install-and-run スクリプトでクイックスタート +### 🚀 クイックスタート -AIClient-2-APIを使い始める最も簡単な方法は、自動的にインストールと起動を実行するスクリプトを使用することです。Linux/macOS版とWindows版の2つのバージョンを提供: +AIClient-2-APIを使い始める最も推奨される方法は、自動起動スクリプトを使用し、**Web UIコンソール**で直接ビジュアル設定を行うことです。 -#### Linux/macOS ユーザー向け -```bash -# スクリプトに実行権限を付与して実行 -chmod +x install-and-run.sh -./install-and-run.sh -``` +#### 1. 起動スクリプトの実行 +* **Linux/macOS**: `chmod +x install-and-run.sh && ./install-and-run.sh` +* **Windows**: `install-and-run.bat` をダブルクリックして実行 -#### Windows ユーザー向け -```cmd -# バッチファイルを実行 -install-and-run.bat -``` +#### 2. コンソールへのアクセス +サーバー起動後、ブラウザで以下にアクセスしてください: +👉 [**http://localhost:3000**](http://localhost:3000) -#### スクリプトの機能 +> **デフォルトパスワード**: `admin123` (ログイン後、コンソールまたは `pwd` ファイルの変更で変更可能) -`install-and-run` スクリプトは自動的に以下の操作を実行します: - -1. **Node.js インストール確認**:Node.js がインストールされているかを確認し、不足の場合はダウンロードリンクを提供 -2. **依存関係管理**:`node_modules` が存在しない場合、npm 依存関係を自動インストール -3. **ファイル検証**:すべての必要なプロジェクトファイルが存在することを確認 -4. **サーバー起動**:`http://localhost:3000` で API サーバーを起動 -5. **Web UI アクセス**:管理コンソールへの直接アクセスを提供 +#### 3. ビジュアル設定 (推奨) +**「設定管理」** ページに入ると、以下を直接行えます: +* ✅ 各プロバイダーの API Key の入力または OAuth 認証情報のアップロード +* ✅ デフォルトモデルプロバイダーのリアルタイム切り替え +* ✅ 健全性ステータスとリアルタイムリクエストログの監視 #### スクリプト実行例 ``` @@ -201,7 +140,7 @@ install-and-run.bat **📊 ダッシュボード**:システム概要、インタラクティブなルーティング例、クライアント設定ガイド -**⚙️ 設定管理**:全プロバイダー(Gemini、OpenAI、Claude、Kiro、Qwen)のリアルタイムパラメータ修正、高度設定、ファイルアップロード対応 +**⚙️ 設定管理**:全プロバイダー(Gemini、Antigravity、OpenAI、Claude、Kiro、Qwen)のリアルタイムパラメータ修正、高度設定、ファイルアップロード対応 **🔗 プロバイダープール**:アクティブ接続監視、プロバイダー健全性統計、有効化/無効化管理 @@ -209,38 +148,46 @@ install-and-run.bat **📜 リアルタイムログ**:システムログとリクエストログのライブ表示、管理コントロール付き -**🔐 ログイン**:認証が必要(デフォルト:`admin123`、`pwd`ファイルで変更可能) +**🔐 ログイン認証**:デフォルトパスワード `admin123`、`pwd`ファイルで変更可能 アクセス:`http://localhost:3000` → ログイン → サイドバーナビゲーション → 即座有効 -#### MCPプロトコルサポート -本プロジェクトは**Model Context Protocol (MCP)**と完全互換で、MCPをサポートするクライアントとシームレスに統合し、強力な機能拡張を実現します。 - #### マルチモーダル入力機能 画像、ドキュメントなど様々なタイプの入力をサポートし、よりリッチなインタラクティブ体験とより強力なアプリケーションシナリオを提供します。 #### 最新モデルサポート -以下の最新大規模モデルをシームレスにサポート、[`config.json`](./config.json)で対応するOpenAIまたはClaude互換インターフェースを設定するだけで使用可能: -* **Kimi K2** - 月之暗面の最新フラッグシップモデル -* **GLM-4.5** - 智譜AIの最新バージョン -* **Qwen Code** - アリババ通義千問のコード専用モデル -* **Gemini 3** - Googleの最新プレビューモデル -* **Claude Sonnet 4.5** - Anthropicの最新フラッグシップモデル +以下の最新大規模モデルをシームレスにサポート、Web UIまたは[`config.json`](./config.json)で対応するエンドポイントを設定するだけで使用可能: +* **Claude 4.5 Opus** - Anthropic史上最強モデル、Kiro、Antigravity経由でサポート +* **Gemini 3 Pro** - Google次世代アーキテクチャプレビュー版、Gemini、Antigravity経由でサポート +* **Qwen3 Coder Plus** - アリババ通義千問の最新コード専用モデル、Qwen Code経由でサポート +* **Kimi K2 / MiniMax M2** - 国内トップフラッグシップモデルの同期サポート、カスタムOpenAI、Claude経由でサポート --- ### 🔐 認証設定ガイド +> **💡 ヒント**:最適な体験を得るために、**Web UIコンソール**を通じてビジュアルに認証管理を行うことを推奨します。 + +#### 🌐 Web UI クイック認証 (推奨) +Web UI管理インターフェースでは、極めて迅速に認証設定を完了できます: +1. **認証の生成**:**「プロバイダープール」** ページまたは **「設定管理」** ページで、対応するプロバイダー(Gemini、Qwenなど)の右上にある **「認証生成」** ボタンをクリックします。 +2. **スキャン/ログイン**:認証ダイアログが表示されるので、**「ブラウザで開く」** をクリックしてログイン検証を行います。Qwenの場合はウェブログインを完了するだけ、Gemini、Antigravityの場合はGoogleアカウントの認証を完了させます。 +3. **自動保存**:認証成功後、システムは自動的に資格情報を取得し、`configs/` の対応するディレクトリに保存します。**「設定ファイル」** ページで新しく生成された資格情報を確認できます。 +4. **ビジュアル管理**:Web UIでいつでも資格情報のアップロードや削除、または **「クイック関連付け」** 機能を使用して既存の資格情報ファイルをワンクリックでプロバイダーにバインドできます。 + #### Gemini CLI OAuth設定 1. **OAuth認証情報の取得**:[Google Cloud Console](https://console.cloud.google.com/)にアクセスしてプロジェクトを作成し、Gemini APIを有効化 -2. **初回認証**:Geminiサービス使用後、コマンドラインにGoogle認証ページが表示されるので、ページをブラウザにコピーして認証し、コマンドラインに戻る -3. **認証情報の保存**:認証成功後、`oauth_creds.json`ファイルが自動生成され、`~/.gemini`ディレクトリに保存される -4. **プロジェクト設定**:有効なGoogle CloudプロジェクトIDを提供する必要があり、起動パラメータ`--project-id`で指定可能 +2. **プロジェクト設定**:有効なGoogle CloudプロジェクトIDを提供する必要があり、起動パラメータ`--project-id`で指定可能 +3. **プロジェクトIDの確認**:Web UIで設定する際、入力したプロジェクトIDが Google Cloud Console および Gemini CLI で表示されるプロジェクトIDと一致していることを確認してください。 + +#### Antigravity OAuth設定 +1. **個人アカウント**:個人アカウントは個別に認証が必要ですが、申請チャンネルは閉鎖されています。 +2. **Pro会員**:Antigravity は一時的に Pro 会員に開放されています。まず Pro 会員を購入する必要があります。 +3. **組織アカウント**:組織アカウントは個別に認証が必要です。管理者に連絡して認証を取得してください。 #### Qwen Code OAuth設定 -1. **初回認証**:サービス起動後、システムが自動的にブラウザで認証ページを開く -2. **認証情報の保存**:認証成功後、`oauth_creds.json`ファイルが自動生成され、`~/.qwen`ディレクトリに保存される -3. **推奨パラメータ**:最良の結果を得るために公式デフォルトパラメータを使用 +1. **初回認証**:Qwenサービス設定後、システムが自動的にブラウザで認証ページを開きます +2. **推奨パラメータ**:最良の結果を得るために公式デフォルトパラメータを使用 ```json { "temperature": 0, @@ -249,56 +196,37 @@ install-and-run.bat ``` #### Kiro API設定 -1. **環境準備**:[Kiroクライアントをダウンロードしてインストール](https://aibook.ren/archives/kiro-install) +1. **環境準備**:[Kiroクライアントをダウンロードしてインストール](https://kiro.dev/pricing/) 2. **認証完了**:クライアントでアカウントにログインし、`kiro-auth-token.json`認証情報ファイルを生成 3. **ベストプラクティス**:**Claude Code**との併用を推奨、最適な体験を得られる -4. **重要なお知らせ**:Kiroサービス使用ポリシーが更新されました、最新の使用制限と条件については公式ウェブサイトをご確認ください +4. **重要なお知らせ**:Kiroサービス使用ポリシーが更新されました、最新の使用制限と条件については公式ウェブサイトをご確認ください。 #### アカウントプール管理設定 1. **プール設定ファイルの作成**:[provider_pools.json.example](./provider_pools.json.example) を参考に設定ファイルを作成します 2. **プールパラメータの設定**:config.json で `PROVIDER_POOLS_FILE_PATH` を設定し、プール設定ファイルを指定します 3. **起動パラメータ設定**:`--provider-pools-file ` パラメータを使用してプール設定ファイルのパスを指定します -4. **ヘルスチェック**:システムは定期的にヘルスチェックを自動実行し、健全でないプロバイダーを削除します - -#### OpenAI Responses API -* **適用シナリオ**:Codexなど、OpenAI Responses APIを使用した構造化対話が必要なシナリオに適用 -* **設定方法**: - * 方法1:[`config.json`](./config.json)で`MODEL_PROVIDER`を`openaiResponses-custom`に設定 - * 方法2:起動パラメータ`--model-provider openaiResponses-custom`を使用 - * 方法3:パスルーティング`/openaiResponses-custom`を使用 -* **必須パラメータ**:有効なAPIキーとベースURLを提供 +4. **ヘルスチェック**:システムは定期的にヘルスチェックを自動実行し、健全でないプロバイダーを使用しません --- -### 🔄 モデルプロバイダー切り替え +### 📁 認証ファイル保存パス -本プロジェクトは2つの柔軟なモデル切り替え方法を提供し、異なる使用シナリオのニーズに対応します。 +各サービスの認証情報ファイルのデフォルト保存場所: -APIリクエストパスでプロバイダー識別子を指定して即座に切り替え: +| サービス | デフォルトパス | 説明 | +|------|---------|------| +| **Gemini** | `~/.gemini/oauth_creds.json` | OAuth認証情報 | +| **Kiro** | `~/.aws/sso/cache/kiro-auth-token.json` | Kiro認証トークン | +| **Qwen** | `~/.qwen/oauth_creds.json` | Qwen OAuth認証情報 | +| **Antigravity** | `~/.antigravity/oauth_creds.json` | Antigravity OAuth認証情報 (Claude 4.5 Opus サポート) | +> **説明**:`~`はユーザーホームディレクトリを表します(Windows: `C:\Users\ユーザー名`、Linux/macOS: `/home/ユーザー名`または`/Users/ユーザー名`) +> +> **カスタムパス**:設定ファイルの関連パラメータまたは環境変数でカスタム保存場所を指定可能 -| ルートパス | 説明 | 使用ケース | -|---------|------|---------| -| `/claude-custom` | 設定ファイルのClaude APIを使用 | 公式Claude API呼び出し | -| `/claude-kiro-oauth` | Kiro OAuth経由でClaudeにアクセス | Claude Sonnet 4.5の無料使用 | -| `/openai-custom` | OpenAIプロバイダーでリクエストを処理 | 標準OpenAI API呼び出し | -| `/gemini-cli-oauth` | Gemini CLI OAuth経由でアクセス | Gemini無料制限の突破 | -| `/openai-qwen-oauth` | Qwen OAuth経由でアクセス | Qwen Code Plusの使用 | -| `/openaiResponses-custom` | OpenAI Responses API | 構造化対話シナリオ | -| `/ollama` | Ollama APIプロトコル | サポートされるすべてのモデルへの統一アクセス | - -**使用例**: -```bash -# Cline、Kiloなどのプログラミングエージェントで設定 -API_ENDPOINT=http://localhost:3000/claude-kiro-oauth - -# 直接API呼び出し -curl http://localhost:3000/gemini-cli-oauth/v1/chat/completions \ - -H "Content-Type: application/json" \ - -d '{"model":"gemini-2.0-flash-exp","messages":[...]}' -``` +--- -#### Ollamaプロトコル使用例 +### 🦙 Ollamaプロトコル使用例 本プロジェクトはOllamaプロトコルをサポートしており、統一インターフェースを通じてすべてのサポートモデルにアクセスできます。Ollamaエンドポイントは`/api/tags`、`/api/chat`、`/api/generate`などの標準インターフェースを提供します。 @@ -329,174 +257,6 @@ curl http://localhost:3000/ollama/api/chat \ - `[Qwen CLI]` - Qwen OAuth経由でアクセス --- - -### 📁 認証ファイル保存パス - -各サービスの認証情報ファイルのデフォルト保存場所: - -| サービス | デフォルトパス | 説明 | -|------|---------|------| -| **Gemini** | `~/.gemini/oauth_creds.json` | OAuth認証情報 | -| **Kiro** | `~/.aws/sso/cache/kiro-auth-token.json` | Kiro認証トークン | -| **Qwen** | `~/.qwen/oauth_creds.json` | Qwen OAuth認証情報 | -| **Antigravity** | `~/.antigravity/oauth_creds.json` | Antigravity OAuth認証情報 | - -> **説明**:`~`はユーザーホームディレクトリを表します(Windows: `C:\Users\ユーザー名`、Linux/macOS: `/home/ユーザー名`または`/Users/ユーザー名`) -> -> **カスタムパス**:設定ファイルの関連パラメータまたは環境変数でカスタム保存場所を指定可能 - ---- - -## 🚀 プロジェクト起動パラメータ - -本プロジェクトは豊富なコマンドラインパラメータ設定をサポートし、必要に応じてサービスの動作を柔軟に調整できます。以下は機能別にグループ化されたすべての起動パラメータの詳細説明です: - -### 🔧 サーバー設定パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--host` | string | localhost | サーバーリッスンアドレス | -| `--port` | number | 3000 | サーバーリッスンポート | -| `--api-key` | string | 123456 | 認証用APIキー | - -### 🤖 モデルプロバイダー設定パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--model-provider` | string | gemini-cli-oauth | AIモデルプロバイダー、選択可能値:openai-custom, claude-custom, gemini-cli-oauth, claude-kiro-oauth, openai-qwen-oauth, openaiResponses-custom, gemini-antigravity | - -### 🧠 OpenAI互換プロバイダーパラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--openai-api-key` | string | null | OpenAI APIキー(`model-provider`が`openai-custom`の場合必須) | -| `--openai-base-url` | string | null | OpenAI APIベースURL(`model-provider`が`openai-custom`の場合必須) | - -### 🖥️ Claude互換プロバイダーパラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--claude-api-key` | string | null | Claude APIキー(`model-provider`が`claude-custom`の場合必須) | -| `--claude-base-url` | string | null | Claude APIベースURL(`model-provider`が`claude-custom`の場合必須) | - -### 🔐 Gemini OAuth認証パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--gemini-oauth-creds-base64` | string | null | Gemini OAuth認証情報のBase64文字列(`model-provider`が`gemini-cli-oauth`の場合オプション、`--gemini-oauth-creds-file`と二者択一) | -| `--gemini-oauth-creds-file` | string | null | Gemini OAuth認証情報JSONファイルパス(`model-provider`が`gemini-cli-oauth`の場合オプション、`--gemini-oauth-creds-base64`と二者択一) | -| `--project-id` | string | null | Google CloudプロジェクトID(`model-provider`が`gemini-cli-oauth`の場合必須) | - -### 🎮 Kiro OAuth認証パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--kiro-oauth-creds-base64` | string | null | Kiro OAuth認証情報のBase64文字列(`model-provider`が`claude-kiro-oauth`の場合オプション、`--kiro-oauth-creds-file`と二者択一) | -| `--kiro-oauth-creds-file` | string | null | Kiro OAuth認証情報JSONファイルパス(`model-provider`が`claude-kiro-oauth`の場合オプション、`--kiro-oauth-creds-base64`と二者択一) | - -### 🐼 Qwen OAuth認証パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--qwen-oauth-creds-file` | string | null | Qwen OAuth認証情報JSONファイルパス(`model-provider`が`openai-qwen-oauth`の場合必須) | - -### 🌌 Antigravity OAuth認証パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--antigravity-oauth-creds-file` | string | null | Antigravity OAuth認証情報JSONファイルパス(`model-provider`が`gemini-antigravity`の場合オプション) | - -### 🔄 OpenAI Responses APIパラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--model-provider` | string | openaiResponses-custom | モデルプロバイダー、OpenAI Responses API使用時は`openaiResponses-custom`に設定 | -| `--openai-api-key` | string | null | OpenAI APIキー(`model-provider`が`openaiResponses-custom`の場合必須) | -| `--openai-base-url` | string | null | OpenAI APIベースURL(`model-provider`が`openaiResponses-custom`の場合必須) | - -### 📝 システムプロンプト設定パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--system-prompt-file` | string | input_system_prompt.txt | システムプロンプトファイルパス | -| `--system-prompt-mode` | string | overwrite | システムプロンプトモード、選択可能値:overwrite(上書き)、append(追加) | - -### 📊 ログ設定パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--log-prompts` | string | none | プロンプトログモード、選択可能値:console(コンソール)、file(ファイル)、none(なし) | -| `--prompt-log-base-name` | string | prompt_log | プロンプトログファイルベース名 | - -### 🔄 リトライ機構パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--request-max-retries` | number | 3 | APIリクエスト失敗時の自動リトライ最大回数 | -| `--request-base-delay` | number | 1000 | 自動リトライ間の基本遅延時間(ミリ秒)、各リトライ後に遅延が増加 | - -### ⏰ 定期タスクパラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--cron-near-minutes` | number | 15 | OAuthトークンリフレッシュタスクの間隔時間(分) | -| `--cron-refresh-token` | boolean | true | OAuthトークン自動リフレッシュタスクを有効にするか | - -### 🎯 アカウントプール設定パラメータ - -| パラメータ | タイプ | デフォルト値 | 説明 | -|------|------|--------|------| -| `--provider-pools-file` | string | null | プロバイダーアカウントプール設定ファイルパス | - -### 使用例 - -```bash -# 基本的な使用法 -node src/api-server.js - -# ポートとAPIキーを指定 -node src/api-server.js --port 8080 --api-key my-secret-key - -# OpenAIプロバイダーを使用 -node src/api-server.js --model-provider openai-custom --openai-api-key sk-xxx --openai-base-url https://api.openai.com/v1 - -# Claudeプロバイダーを使用 -node src/api-server.js --model-provider claude-custom --claude-api-key sk-ant-xxx --claude-base-url https://api.anthropic.com - -# OpenAI Responses APIプロバイダーを使用 -node src/api-server.js --model-provider openaiResponses-custom --openai-api-key sk-xxx --openai-base-url https://api.openai.com/v1 - -# Geminiプロバイダーを使用(Base64認証情報) -node src/api-server.js --model-provider gemini-cli-oauth --gemini-oauth-creds-base64 eyJ0eXBlIjoi... --project-id your-project-id - -# Geminiプロバイダーを使用(認証情報ファイル) -node src/api-server.js --model-provider gemini-cli-oauth --gemini-oauth-creds-file /path/to/credentials.json --project-id your-project-id - -# システムプロンプトを設定 -node src/api-server.js --system-prompt-file custom-prompt.txt --system-prompt-mode append - -# ログを設定 -node src/api-server.js --log-prompts console -node src/api-server.js --log-prompts file --prompt-log-base-name my-logs - -# アカウントプールの設定 -node src/api-server.js --provider-pools-file ./provider_pools.json - -# 完全な例 -node src/api-server.js \ - --host 0.0.0.0 \ - --port 3000 \ - --api-key my-secret-key \ - --model-provider gemini-cli-oauth \ - --project-id my-gcp-project \ - --gemini-oauth-creds-file ./credentials.json \ - --system-prompt-file ./custom-system-prompt.txt \ - --system-prompt-mode overwrite \ - --log-prompts file \ - --prompt-log-base-name api-logs \ - --provider-pools-file ./provider_pools.json -``` ---- ## 📄 オープンソースライセンス @@ -505,6 +265,7 @@ node src/api-server.js \ ## 🙏 謝辞 本プロジェクトの開発は公式Google Gemini CLIから大きなインスピレーションを受け、Cline 3.18.0版 `gemini-cli.ts` の一部のコード実装を参考にしました。ここにGoogle公式チームとCline開発チームの優れた仕事に心より感謝申し上げます! + ### 貢献者リスト AIClient-2-APIプロジェクトに貢献してくれたすべての開発者に感謝します: @@ -512,7 +273,8 @@ AIClient-2-APIプロジェクトに貢献してくれたすべての開発者に [![Contributors](https://contrib.rocks/image?repo=justlovemaki/AIClient-2-API)](https://github.com/justlovemaki/AIClient-2-API/graphs/contributors) -## 🌟 Star History +### 🌟 Star History + [![Star History Chart](https://api.star-history.com/svg?repos=justlovemaki/AIClient-2-API&type=Timeline)](https://www.star-history.com/#justlovemaki/AIClient-2-API&Timeline) @@ -521,17 +283,13 @@ AIClient-2-APIプロジェクトに貢献してくれたすべての開発者に ## ⚠️ 免責事項 ### 使用リスクの注意 - -本プロジェクト(AIClient-2-API)は学習と研究目的のみです。ユーザーは本プロジェクト使用時、すべてのリスクを自己負担する必要があります。作者は本プロジェクトの使用により生じた直接的、間接的、結果的損失について一切の責任を負いません。 +本プロジェクト(AIClient-2-API)は学習と研究目的のみです。ユーザーは本プロジェクト使用時、すべてのリスクを自己負担する必要があります。作者は本プロジェクトの使用により生じた直接的、間接的、または結果的な損失について一切の責任を負いません。 ### サードパーティサービスの責任説明 - 本プロジェクトはAPIプロキシツールであり、AIモデルサービスを提供していません。すべてのAIモデルサービスは対応するサードパーティプロバイダー(Google、OpenAI、Anthropicなど)により提供されます。ユーザーが本プロジェクトを通じてこれらのサードパーティサービスにアクセスする際は、各サードパーティサービスの利用規約とポリシーを遵守する必要があります。作者はサードパーティサービスの可用性、品質、セキュリティ、合法性について責任を負いません。 ### データプライバシー説明 - 本プロジェクトはローカルで実行され、ユーザーのデータを収集またはアップロードしません。ただし、ユーザーは本プロジェクト使用時、APIキーやその他の機密情報を保護することに注意する必要があります。定期的にAPIキーを確認・更新し、安全でないネットワーク環境での本プロジェクトの使用を避けることを推奨します。 ### 法的コンプライアンスの注意 - ユーザーは本プロジェクト使用時、所在国/地域の法律法規を遵守する必要があります。本プロジェクトを違法な目的に使用することは厳禁です。ユーザーが法律法規に違反したことによるいかなる結果も、ユーザー自身がすべての責任を負うものとします。 diff --git a/README-ZH.md b/README-ZH.md index f29b7f4..734fd44 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -4,7 +4,7 @@ # AIClient-2-API 🚀 -**一个能将多种仅客户端内使用的大模型 API(Gemini CLI, Qwen Code Plus, Kiro Claude...),模拟请求,统一封装为本地 OpenAI 兼容接口的强大代理。** +**一个能将多种仅客户端内使用的大模型 API(Gemini CLI, Antigravity, Qwen Code, Kiro ...),模拟请求,统一封装为本地 OpenAI 兼容接口的强大代理。** @@ -14,14 +14,15 @@ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Node.js](https://img.shields.io/badge/Node.js-≥20.0.0-green.svg)](https://nodejs.org/) -[![Docker](https://img.shields.io/badge/docker-≥20.0.0-blue.svg)](https://aiproxy.justlikemaki.vip/zh/docs/installation/docker-deployment.html) +[![Docker](https://img.shields.io/badge/docker-≥20.0.0-blue.svg)](https://hub.docker.com/r/justlikemaki/aiclient-2-api) +[![GitHub stars](https://img.shields.io/github/stars/justlovemaki/AIClient-2-API.svg?style=flat&label=Star)](https://github.com/justlovemaki/AIClient-2-API/stargazers) +[![GitHub issues](https://img.shields.io/github/issues/justlovemaki/AIClient-2-API.svg)](https://github.com/justlovemaki/AIClient-2-API/issues) - -[**中文**](./README-ZH.md) | [**English**](./README.md) | [**日本語**](./README-JA.md) | [**📚 完整文档**](https://aiproxy.justlikemaki.vip/zh/) +[**👉 中文**](./README-ZH.md) | [English](./README.md) | [日本語](./README-JA.md) | [**📚 完整文档**](https://aiproxy.justlikemaki.vip/zh/) -`AIClient2API` 是一个突破客户端限制的 API 代理服务,将 Gemini CLI、Qwen Code Plus、Kiro Claude 等原本仅限客户端使用的免费大模型,转换为可供任何应用调用的标准 OpenAI 兼容接口。基于 Node.js 构建,支持 OpenAI、Claude、Gemini 三大协议的智能互转,让 Cherry-Studio、NextChat、Cline 等工具能够免费大量使用 Claude Sonnet 4.5、Gemini 2.5 Flash、Qwen3 Coder Plus 等高级模型。项目采用策略模式和适配器模式的模块化架构,内置账号池管理、智能轮询、自动故障转移和健康检查机制,确保 99.9% 的服务可用性。 +`AIClient2API` 是一个突破客户端限制的 API 代理服务,将 Gemini、Antigravity、Qwen Code、Kiro 等原本仅限客户端内使用的免费大模型,转换为可供任何应用调用的标准 OpenAI 兼容接口。基于 Node.js 构建,支持 OpenAI、Claude、Gemini 三大协议的智能互转,让 Cherry-Studio、NextChat、Cline 等工具能够免费大量使用 Claude Opus 4.5、Gemini 3.0 Pro、Qwen3 Coder Plus 等高级模型。项目采用策略模式和适配器模式的模块化架构,内置账号池管理、智能轮询、自动故障转移和健康检查机制,确保 99.9% 的服务可用性。 > [!NOTE] > **🎉 重要里程碑** @@ -40,24 +41,22 @@ > - **2025.08.29** - 发布账号池管理功能,支持多账号轮询、智能故障转移和自动降级策略 > - 配置方式:在 config.json 中添加 `PROVIDER_POOLS_FILE_PATH` 参数 > - 参考配置:[provider_pools.json](./provider_pools.json.example) - +> - **历史已开发** +> - 支持 Gemini CLI、Kiro 等客户端2API +> - OpenAI ,Claude ,Gemini 三协议互转,自动智能切换 --- ## 💡 核心优势 ### 🎯 统一接入,一站式管理 -* **多模型统一接口**:通过标准 OpenAI 兼容协议,一次配置即可接入 Gemini、Claude、GPT、Qwen Code、Kimi K2、GLM-4.6 等主流大模型 -* **灵活切换机制**:支持通过启动参数、Path 路由、环境变量三种方式动态切换模型,满足不同场景需求 +* **多模型统一接口**:通过标准 OpenAI 兼容协议,一次配置即可接入 Gemini、Claude、Qwen Code、Kimi K2、MiniMax M2 等主流大模型 +* **灵活切换机制**:Path 路由、支持通过启动参数、环境变量三种方式动态切换模型,满足不同场景需求 * **零成本迁移**:完全兼容 OpenAI API 规范,Cherry-Studio、NextChat、Cline 等工具无需修改即可使用 * **多协议智能转换**:支持 OpenAI、Claude、Gemini 三大协议间的智能转换,实现跨协议模型调用 - * 使用 OpenAI 协议调用 Claude 模型:可使用 `claude-custom` 或 `claude-kiro-oauth` 提供商 - * 使用 OpenAI 协议调用 Gemini 模型:可使用 `gemini-cli-oauth` 提供商 - * 使用 Claude 协议调用 Gemini 模型:可使用 `gemini-cli-oauth` 提供商 - * 使用 Claude 协议调用 OpenAI 模型:可使用 `openai-custom` 或 `openai-qwen-oauth` 提供商 ### 🚀 突破限制,提升效率 -* **绕过官方限制**:利用 OAuth 授权机制,有效突破 Gemini 等服务的免费 API 速率和配额限制 -* **免费高级模型**:通过 Kiro API 模式免费使用 Claude Sonnet 4.5,通过 Qwen OAuth 模式使用 Qwen3 Coder Plus,降低使用成本 +* **绕过官方限制**:利用 OAuth 授权机制,有效突破 Gemini, Antigravity 等服务的免费 API 速率和配额限制 +* **免费高级模型**:通过 Kiro API 模式免费使用 Claude Opus 4.5,通过 Qwen OAuth 模式使用 Qwen3 Coder Plus,降低使用成本 * **账号池智能调度**:支持多账号轮询、自动故障转移和配置降级,确保 99.9% 服务可用性 ### 🛡️ 安全可控,数据透明 @@ -70,103 +69,40 @@ * **模块化架构**:基于策略模式和适配器模式,新增模型提供商仅需 3 步 * **完整测试保障**:集成测试和单元测试覆盖率 90%+,确保代码质量 * **容器化部署**:提供 Docker 支持,一键部署,跨平台运行 -* **MCP 协议支持**:完美兼容 Model Context Protocol,轻松扩展功能 --- ## 📑 快速导航 -- [🐳 Docker 部署](https://aiproxy.justlikemaki.vip/zh/docs/installation/docker-deployment.html) -- [🎨 模型协议与提供商关系图](#-模型协议与提供商关系图) +- [🐳 Docker 部署](https://hub.docker.com/r/justlikemaki/aiclient-2-api) - [🔧 使用说明](#-使用说明) -- [🚀 项目启动参数](#-项目启动参数) - [📄 开源许可](#-开源许可) - [🙏 致谢](#-致谢) - [⚠️ 免责声明](#-免责声明) --- -## 🎨 模型协议与提供商关系图 - -本项目通过不同的协议(Protocol)支持多种模型提供商(Model Provider)。以下是它们之间的关系概述: - -* **OpenAI 协议 (P_OPENAI)**:由 `openai-custom`, `gemini-cli-oauth`, `claude-custom`, `claude-kiro-oauth` 和 `openai-qwen-oauth` 等模型提供商实现。 -* **Claude 协议 (P_CLAUDE)**:由 `claude-custom`, `claude-kiro-oauth`, `gemini-cli-oauth`, `openai-custom` 和 `openai-qwen-oauth` 等模型提供商实现。 -* **Gemini 协议 (P_GEMINI)**:由 `gemini-cli-oauth` 模型提供商实现。 - -详细关系图如下: - - - ```mermaid - - graph TD - subgraph Core_Protocols["核心协议"] - P_OPENAI[OpenAI Protocol] - P_GEMINI[Gemini Protocol] - P_CLAUDE[Claude Protocol] - end - - subgraph Supported_Model_Providers["支持的模型提供商"] - MP_OPENAI[openai-custom] - MP_GEMINI[gemini-cli-oauth] - MP_CLAUDE_C[claude-custom] - MP_CLAUDE_K[claude-kiro-oauth] - MP_QWEN[openai-qwen-oauth] - MP_OPENAI_RESP[openaiResponses-custom] - end - - P_OPENAI ---|支持| MP_OPENAI - P_OPENAI ---|支持| MP_QWEN - P_OPENAI ---|支持| MP_GEMINI - P_OPENAI ---|支持| MP_CLAUDE_C - P_OPENAI ---|支持| MP_CLAUDE_K - P_OPENAI ---|支持| MP_OPENAI_RESP - - P_GEMINI ---|支持| MP_GEMINI - - P_CLAUDE ---|支持| MP_CLAUDE_C - P_CLAUDE ---|支持| MP_CLAUDE_K - P_CLAUDE ---|支持| MP_GEMINI - P_CLAUDE ---|支持| MP_OPENAI - P_CLAUDE ---|支持| MP_QWEN - P_CLAUDE ---|支持| MP_OPENAI_RESP - - style P_OPENAI fill:#f9f,stroke:#333,stroke-width:2px - style P_GEMINI fill:#ccf,stroke:#333,stroke-width:2px - style P_CLAUDE fill:#cfc,stroke:#333,stroke-width:2px - - ``` - ---- - ## 🔧 使用说明 -### 🚀 install-and-run 脚本快速启动 +### 🚀 快速启动 -使用 AIClient-2-API 最简单的方式是使用我们的自动化安装启动脚本。我们提供了 Linux/macOS 和 Windows 两个版本: +使用 AIClient-2-API 最推荐的方式是通过自动化脚本启动,并直接在 **Web UI 控制台** 进行可视化配置。 -#### Linux/macOS 用户 -```bash -# 给脚本添加执行权限并运行 -chmod +x install-and-run.sh -./install-and-run.sh -``` +#### 1. 运行启动脚本 +* **Linux/macOS**: `chmod +x install-and-run.sh && ./install-and-run.sh` +* **Windows**: 双击运行 `install-and-run.bat` -#### Windows 用户 -```cmd -# 运行批处理文件 -install-and-run.bat -``` +#### 2. 访问控制台 +服务器启动后,打开浏览器访问: +👉 [**http://localhost:3000**](http://localhost:3000) -#### 脚本功能说明 +> **默认密码**: `admin123` (登录后可在控制台或修改 `pwd` 文件变更) -`install-and-run` 脚本会自动执行以下操作: - -1. **检查 Node.js 安装**:验证 Node.js 是否已安装,如缺失则提供下载链接 -2. **依赖管理**:如果 `node_modules` 不存在,自动安装 npm 依赖包 -3. **文件验证**:确保所有必需的项目文件都存在 -4. **服务器启动**:在 `http://localhost:3000` 启动 API 服务器 -5. **Web UI 访问**:直接提供管理控制台的访问地址 +#### 3. 可视化配置 (推荐) +进入 **"配置管理"** 页面,您可以直接: +* ✅ 填入各提供商的 API Key 或上传 OAuth 凭据文件 +* ✅ 实时切换默认模型提供商 +* ✅ 监控健康状态和实时请求日志 #### 脚本执行示例 ``` @@ -203,7 +139,7 @@ install-and-run.bat **📊 仪表盘**:系统概览、交互式路由示例、客户端配置指南 -**⚙️ 配置管理**:实时参数修改,支持所有提供商(Gemini、OpenAI、Claude、Kiro、Qwen),包含高级设置和文件上传 +**⚙️ 配置管理**:实时参数修改,支持所有提供商(Gemini、Antigravity、OpenAI、Claude、Kiro、Qwen),包含高级设置和文件上传 **🔗 提供商池**:监控活动连接、提供商健康统计、启用/禁用管理 @@ -215,34 +151,42 @@ install-and-run.bat 访问:`http://localhost:3000` → 登录 → 侧边栏导航 → 立即生效 -#### MCP 协议支持 -本项目完全兼容 **Model Context Protocol (MCP)**,可与支持 MCP 的客户端无缝集成,实现强大的功能扩展。 - #### 多模态输入能力 支持图片、文档等多种类型的输入,为您提供更丰富的交互体验和更强大的应用场景。 #### 最新模型支持 -无缝支持以下最新大模型,仅需在 [`config.json`](./config.json) 中配置相应的 OpenAI 或 Claude 兼容接口: -* **Kimi K2** - 月之暗面最新旗舰模型 -* **GLM-4.5** - 智谱 AI 最新版本 -* **Qwen Code** - 阿里通义千问代码专用模型 -* **Gemini 3** - Google 最新预览版模型 -* **Claude Sonnet 4.5** - Anthropic 最新旗舰模型 +无缝支持以下最新大模型,仅需在 Web UI 或 [`config.json`](./config.json) 中配置相应的端点: +* **Claude 4.5 Opus** - Anthropic 史上最强模型,现已通过 Kiro, Antigravity 支持 +* **Gemini 3 Pro** - Google 下一代架构预览版,现已通过 Gemini, Antigravity 支持 +* **Qwen3 Coder Plus** - 阿里通义千问最新代码专用模型,现已通过Qwen Code 支持 +* **Kimi K2 / MiniMax M2** - 国内顶级旗舰模型同步支持,现已通过自定义OpenAI,Claude 支持 --- ### 🔐 授权配置指南 +> **💡 提示**:为了获得最佳体验,建议通过 **Web UI 控制台** 进行可视化授权管理。 + +#### 🌐 Web UI 快捷授权 (推荐) +在 Web UI 管理界面中,您可以极速完成授权配置: +1. **生成授权**:在 **“提供商池”** 页面或**“配置管理”** 页面,点击对应提供商(如 Gemini, Qwen)右上角的 **“生成授权”** 按钮。 +2. **扫码/登录**:系统将弹出授权对话框,您可以点击 **“在浏览器中打开”** 进行登录验证。对于 Qwen,只需完成网页登录;对于 Gemini,Antigravity 需完成 Google 账号授权。 +3. **自动保存**:授权成功后,系统会自动获取凭据并保存至 `configs/` 对应目录下,您可以在 **“配置文件”** 页面看到新生成的凭据。 +4. **可视化管理**:您可以随时在 Web UI 中上传、删除凭据,或通过 **“快速关联”** 功能将已有的凭据文件一键绑定到提供商。 + #### Gemini CLI OAuth 配置 1. **获取OAuth凭据**:访问 [Google Cloud Console](https://console.cloud.google.com/) 创建项目,启用Gemini API -2. **首次授权**:使用Gemini服务后,命令行会打印Google授权页面,复制页面到浏览器授权,完成后返回命令行 -3. **凭据存储**:授权成功后,`oauth_creds.json` 文件将自动生成并保存至 `~/.gemini` 目录 -4. **项目配置**:需要提供有效的Google Cloud项目ID,可通过启动参数 `--project-id` 指定 +2. **项目配置**:可能需要提供有效的Google Cloud项目ID,可通过启动参数 `--project-id` 指定 +3. **确保项目ID**:在 Web UI 中配置时,确保输入的项目ID与 Google Cloud Console 和 Gemini CLI 中显示的项目ID一致。 + +#### Antigravity OAuth 配置 +1. **个人账号**:个人账号需要单独授权,已关闭申请渠道。 +2. **Pro会员**:Antigravity 暂时对 Pro 会员开放,需要先购买 Pro 会员。 +3. **组织账号**:组织账号需要单独授权,联系管理员获取授权。 #### Qwen Code OAuth 配置 -1. **首次授权**:启动服务后,系统会自动在浏览器中打开授权页面 -2. **凭据存储**:授权成功后,`oauth_creds.json` 文件将自动生成并保存至 `~/.qwen` 目录 -3. **推荐参数**:使用官方默认参数以获得最佳效果 +1. **首次授权**:配置Qwen服务后,系统会自动在浏览器中打开授权页面 +2. **推荐参数**:使用官方默认参数以获得最佳效果 ```json { "temperature": 0, @@ -251,7 +195,7 @@ install-and-run.bat ``` #### Kiro API 配置 -1. **环境准备**:[下载并安装 Kiro 客户端](https://aibook.ren/archives/kiro-install) +1. **环境准备**:[下载并安装 Kiro 客户端](https://kiro.dev/pricing/) 2. **完成授权**:在客户端中登录账号,生成 `kiro-auth-token.json` 凭据文件 3. **最佳实践**:推荐配合 **Claude Code** 使用,可获得最优体验 4. **重要提示**:Kiro 服务使用政策已更新,请访问官方网站查看最新使用限制和条款 @@ -260,36 +204,26 @@ install-and-run.bat 1. **创建号池配置文件**:参考 [provider_pools.json.example](./provider_pools.json.example) 创建配置文件 2. **配置号池参数**:在 config.json 中设置 `PROVIDER_POOLS_FILE_PATH` 指向号池配置文件 3. **启动参数配置**:使用 `--provider-pools-file ` 参数指定号池配置文件路径 -4. **健康检查**:系统会定期自动执行健康检查,移除不健康的提供商 +4. **健康检查**:系统会定期自动执行健康检查,不使用不健康的提供商 --- -### 🔄 模型提供商切换 +### 📁 授权文件存储路径 -本项目提供两种灵活的模型切换方式,满足不同使用场景的需求。 +各服务的授权凭据文件默认存储位置: -通过在 API 请求路径中指定提供商标识,实现即时切换: +| 服务 | 默认路径 | 说明 | +|------|---------|------| +| **Gemini** | `~/.gemini/oauth_creds.json` | OAuth 认证凭据 | +| **Kiro** | `~/.aws/sso/cache/kiro-auth-token.json` | Kiro 认证令牌 | +| **Qwen** | `~/.qwen/oauth_creds.json` | Qwen OAuth 凭据 | +| **Antigravity** | `~/.antigravity/oauth_creds.json` | Antigravity OAuth 凭据 (支持 Claude 4.5 Opus) | -| 路由路径 | 说明 | 适用场景 | -|---------|------|---------| -| `/claude-custom` | 使用配置文件中的 Claude API | 官方 Claude API 调用 | -| `/claude-kiro-oauth` | 通过 Kiro OAuth 访问 Claude | 免费使用 Claude Sonnet 4.5 | -| `/openai-custom` | 使用 OpenAI 提供商处理请求 | 标准 OpenAI API 调用 | -| `/gemini-cli-oauth` | 通过 Gemini CLI OAuth 访问 | 突破 Gemini 免费限制 | -| `/openai-qwen-oauth` | 通过 Qwen OAuth 访问 | 使用 Qwen Code Plus | -| `/openaiResponses-custom` | OpenAI Responses API | 结构化对话场景 | -| `/ollama` | Ollama API 协议 | 统一访问所有支持的模型 | - -**使用示例**: -```bash -# 在 Cline、Kilo 等编程 Agent 中配置 -API_ENDPOINT=http://localhost:3000/claude-kiro-oauth +> **说明**:`~` 表示用户主目录(Windows: `C:\Users\用户名`,Linux/macOS: `/home/用户名` 或 `/Users/用户名`) +> +> **自定义路径**:可通过配置文件中的相关参数或环境变量指定自定义存储位置 -# 直接 API 调用 -curl http://localhost:3000/gemini-cli-oauth/v1/chat/completions \ - -H "Content-Type: application/json" \ - -d '{"model":"gemini-2.0-flash-exp","messages":[...]}' -``` +--- ### 🦙 Ollama 协议使用示例 @@ -323,175 +257,6 @@ curl http://localhost:3000/ollama/api/chat \ --- -### 📁 授权文件存储路径 - -各服务的授权凭据文件默认存储位置: - -| 服务 | 默认路径 | 说明 | -|------|---------|------| -| **Gemini** | `~/.gemini/oauth_creds.json` | OAuth 认证凭据 | -| **Kiro** | `~/.aws/sso/cache/kiro-auth-token.json` | Kiro 认证令牌 | -| **Qwen** | `~/.qwen/oauth_creds.json` | Qwen OAuth 凭据 | -| **Antigravity** | `~/.antigravity/oauth_creds.json` | Antigravity OAuth 凭据 | - -> **说明**:`~` 表示用户主目录(Windows: `C:\Users\用户名`,Linux/macOS: `/home/用户名` 或 `/Users/用户名`) -> -> **自定义路径**:可通过配置文件中的相关参数或环境变量指定自定义存储位置 - ---- - -## 🚀 项目启动参数 - -本项目支持丰富的命令行参数配置,可以根据需要灵活调整服务行为。以下是对所有启动参数的详细说明,按功能分组展示: - -### 🔧 服务器配置参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--host` | string | localhost | 服务器监听地址 | -| `--port` | number | 3000 | 服务器监听端口 | -| `--api-key` | string | 123456 | 用于 API 身份验证的密钥 | - -### 🤖 模型提供商配置参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--model-provider` | string | gemini-cli-oauth | AI 模型提供商,可选值:openai-custom, claude-custom, gemini-cli-oauth, claude-kiro-oauth, openai-qwen-oauth, openaiResponses-custom, gemini-antigravity | - -### 🧠 OpenAI 兼容提供商参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--openai-api-key` | string | null | OpenAI API 密钥 (当 `model-provider` 为 `openai-custom` 时必需) | -| `--openai-base-url` | string | null | OpenAI API 基础 URL (当 `model-provider` 为 `openai-custom` 时必需) | - -### 🖥️ Claude 兼容提供商参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--claude-api-key` | string | null | Claude API 密钥 (当 `model-provider` 为 `claude-custom` 时必需) | -| `--claude-base-url` | string | null | Claude API 基础 URL (当 `model-provider` 为 `claude-custom` 时必需) | - -### 🔐 Gemini OAuth 认证参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--gemini-oauth-creds-base64` | string | null | Gemini OAuth 凭据的 Base64 字符串 (当 `model-provider` 为 `gemini-cli-oauth` 时可选,与 `--gemini-oauth-creds-file` 二选一) | -| `--gemini-oauth-creds-file` | string | null | Gemini OAuth 凭据 JSON 文件路径 (当 `model-provider` 为 `gemini-cli-oauth` 时可选,与 `--gemini-oauth-creds-base64` 二选一) | -| `--project-id` | string | null | Google Cloud 项目 ID (当 `model-provider` 为 `gemini-cli-oauth` 时必需) | - -### 🎮 Kiro OAuth 认证参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--kiro-oauth-creds-base64` | string | null | Kiro OAuth 凭据的 Base64 字符串 (当 `model-provider` 为 `claude-kiro-oauth` 时可选,与 `--kiro-oauth-creds-file` 二选一) | -| `--kiro-oauth-creds-file` | string | null | Kiro OAuth 凭据 JSON 文件路径 (当 `model-provider` 为 `claude-kiro-oauth` 时可选,与 `--kiro-oauth-creds-base64` 二选一) | - -### 🐼 Qwen OAuth 认证参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--qwen-oauth-creds-file` | string | null | Qwen OAuth 凭据 JSON 文件路径 (当 `model-provider` 为 `openai-qwen-oauth` 时可选) | - -### 🌌 Antigravity OAuth 认证参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--antigravity-oauth-creds-file` | string | null | Antigravity OAuth 凭据 JSON 文件路径 (当 `model-provider` 为 `gemini-antigravity` 时可选) | - -### 🔄 OpenAI Responses API 参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--model-provider` | string | openaiResponses-custom | 模型提供商,使用OpenAI Responses API时设置为 `openaiResponses-custom` | -| `--openai-api-key` | string | null | OpenAI API 密钥 (当 `model-provider` 为 `openaiResponses-custom` 时必需) | -| `--openai-base-url` | string | null | OpenAI API 基础 URL (当 `model-provider` 为 `openaiResponses-custom` 时必需) | - -### 📝 系统提示配置参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--system-prompt-file` | string | input_system_prompt.txt | 系统提示文件路径 | -| `--system-prompt-mode` | string | overwrite | 系统提示模式,可选值:overwrite(覆盖), append(追加) | - -### 📊 日志配置参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--log-prompts` | string | none | 提示日志模式,可选值:console(控制台), file(文件), none(无) | -| `--prompt-log-base-name` | string | prompt_log | 提示日志文件基础名称 | - -### 🔄 重试机制参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--request-max-retries` | number | 3 | API 请求失败时,自动重试的最大次数 | -| `--request-base-delay` | number | 1000 | 自动重试之间的基础延迟时间(毫秒),每次重试后延迟会增加 | - -### ⏰ 定时任务参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--cron-near-minutes` | number | 15 | OAuth 令牌刷新任务计划的间隔时间(分钟) | -| `--cron-refresh-token` | boolean | true | 是否开启 OAuth 令牌自动刷新任务 | - -### 🎯 号池配置参数 - -| 参数 | 类型 | 默认值 | 说明 | -|------|------|--------|------| -| `--provider-pools-file` | string | null | 提供商号池配置文件路径 | - -### 使用示例 - -```bash -# 基本用法 -node src/api-server.js - -# 指定端口和API密钥 -node src/api-server.js --port 8080 --api-key my-secret-key - -# 使用OpenAI提供商 -node src/api-server.js --model-provider openai-custom --openai-api-key sk-xxx --openai-base-url https://api.openai.com/v1 - -# 使用Claude提供商 -node src/api-server.js --model-provider claude-custom --claude-api-key sk-ant-xxx --claude-base-url https://api.anthropic.com - -# 使用OpenAI Responses API提供商 -node src/api-server.js --model-provider openaiResponses-custom --openai-api-key sk-xxx --openai-base-url https://api.openai.com/v1 - -# 使用Gemini提供商(Base64凭据) -node src/api-server.js --model-provider gemini-cli-oauth --gemini-oauth-creds-base64 eyJ0eXBlIjoi... --project-id your-project-id - -# 使用Gemini提供商(凭据文件) -node src/api-server.js --model-provider gemini-cli-oauth --gemini-oauth-creds-file /path/to/credentials.json --project-id your-project-id - -# 配置系统提示 -node src/api-server.js --system-prompt-file custom-prompt.txt --system-prompt-mode append - -# 配置日志 -node src/api-server.js --log-prompts console -node src/api-server.js --log-prompts file --prompt-log-base-name my-logs - -# 配置号池 -node src/api-server.js --provider-pools-file ./provider_pools.json - -# 完整示例 -node src/api-server.js \ - --host 0.0.0.0 \ - --port 3000 \ - --api-key my-secret-key \ - --model-provider gemini-cli-oauth \ - --project-id my-gcp-project \ - --gemini-oauth-creds-file ./credentials.json \ - --system-prompt-file ./custom-system-prompt.txt \ - --system-prompt-mode overwrite \ - --log-prompts file \ - --prompt-log-base-name api-logs \ - --provider-pools-file ./provider_pools.json -``` - ---- - ## 📄 开源许可 本项目遵循 [**GNU General Public License v3 (GPLv3)**](https://www.gnu.org/licenses/gpl-3.0) 开源许可。详情请查看根目录下的 `LICENSE` 文件。 @@ -505,7 +270,7 @@ node src/api-server.js \ [![Contributors](https://contrib.rocks/image?repo=justlovemaki/AIClient-2-API)](https://github.com/justlovemaki/AIClient-2-API/graphs/contributors) -## 🌟 Star History +### 🌟 Star History [![Star History Chart](https://api.star-history.com/svg?repos=justlovemaki/AIClient-2-API&type=Timeline)](https://www.star-history.com/#justlovemaki/AIClient-2-API&Timeline) diff --git a/README.md b/README.md index ec51eb7..e5c361f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # AIClient-2-API 🚀 -**A powerful proxy that can unify the requests of various large model APIs (Gemini CLI, Qwen Code Plus, Kiro Claude...) that are only used within the client into a local OpenAI compatible interface.** +**A powerful proxy that can unify the requests of various client-only large model APIs (Gemini CLI, Antigravity, Qwen Code, Kiro ...), simulate requests, and encapsulate them into a local OpenAI-compatible interface.** @@ -14,14 +14,15 @@ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Node.js](https://img.shields.io/badge/Node.js-≥20.0.0-green.svg)](https://nodejs.org/) -[![Docker](https://img.shields.io/badge/docker-≥20.0.0-blue.svg)](https://aiproxy.justlikemaki.vip/en/docs/installation/docker-deployment.html) +[![Docker](https://img.shields.io/badge/docker-≥20.0.0-blue.svg)](https://hub.docker.com/r/justlikemaki/aiclient-2-api) +[![GitHub stars](https://img.shields.io/github/stars/justlovemaki/AIClient-2-API.svg?style=flat&label=Star)](https://github.com/justlovemaki/AIClient-2-API/stargazers) +[![GitHub issues](https://img.shields.io/github/issues/justlovemaki/AIClient-2-API.svg)](https://github.com/justlovemaki/AIClient-2-API/issues) - -[**中文**](./README-ZH.md) | [**English**](./README.md) | [**日本語**](./README-JA.md) | [**📚 Complete Documentation**](https://aiproxy.justlikemaki.vip/en/) +[中文](./README-ZH.md) | [**👉 English**](./README.md) | [日本語](./README-JA.md) | [**📚 Documentation**](https://aiproxy.justlikemaki.vip/en/) -`AIClient2API` is an API proxy service that breaks through client limitations, converting free large models originally restricted to client use only (such as Gemini CLI, Qwen Code Plus, Kiro Claude) into standard OpenAI-compatible interfaces that can be called by any application. Built on Node.js, it supports intelligent conversion between three major protocols (OpenAI, Claude, Gemini), enabling tools like Cherry-Studio, NextChat, and Cline to freely use advanced models such as Claude Sonnet 4.5, Gemini 2.5 Flash, and Qwen3 Coder Plus at scale. The project adopts a modular architecture based on strategy and adapter patterns, with built-in account pool management, intelligent polling, automatic failover, and health check mechanisms, ensuring 99.9% service availability. +`AIClient2API` is an API proxy service that breaks through client limitations, converting free large models originally restricted to client use only (such as Gemini, Antigravity, Qwen Code, Kiro) into standard OpenAI-compatible interfaces that can be called by any application. Built on Node.js, it supports intelligent conversion between OpenAI, Claude, and Gemini protocols, enabling tools like Cherry-Studio, NextChat, and Cline to freely use advanced models such as Claude Opus 4.5, Gemini 3.0 Pro, and Qwen3 Coder Plus at scale. The project adopts a modular architecture based on strategy and adapter patterns, with built-in account pool management, intelligent polling, automatic failover, and health check mechanisms, ensuring 99.9% service availability. > [!NOTE] > **🎉 Important Milestone** @@ -40,24 +41,23 @@ > - **2025.08.29** - Released account pool management feature, supporting multi-account polling, intelligent failover, and automatic degradation strategies > - Configuration: Add `PROVIDER_POOLS_FILE_PATH` parameter in config.json > - Reference configuration: [provider_pools.json](./provider_pools.json.example) +> - **History Developed** +> - Support Gemini CLI, Kiro and other client2API +> - OpenAI, Claude, Gemini three-protocol mutual conversion, automatic intelligent switching --- ## 💡 Core Advantages ### 🎯 Unified Access, One-Stop Management -* **Multi-Model Unified Interface**: Through standard OpenAI-compatible protocol, configure once to access mainstream large models including Gemini, Claude, GPT, Qwen Code, Kimi K2, GLM-4.6 -* **Flexible Switching Mechanism**: Support dynamic model switching via startup parameters, Path routing, or environment variables to meet different scenario requirements +* **Multi-Model Unified Interface**: Through standard OpenAI-compatible protocol, configure once to access mainstream large models including Gemini, Claude, Qwen Code, Kimi K2, MiniMax M2 +* **Flexible Switching Mechanism**: Path routing, support dynamic model switching via startup parameters or environment variables to meet different scenario requirements * **Zero-Cost Migration**: Fully compatible with OpenAI API specifications, tools like Cherry-Studio, NextChat, Cline can be used without modification * **Multi-Protocol Intelligent Conversion**: Support intelligent conversion between OpenAI, Claude, and Gemini protocols for cross-protocol model invocation - * Call Claude models using OpenAI protocol: Use `claude-custom` or `claude-kiro-oauth` providers - * Call Gemini models using OpenAI protocol: Use `gemini-cli-oauth` provider - * Call Gemini models using Claude protocol: Use `gemini-cli-oauth` provider - * Call OpenAI models using Claude protocol: Use `openai-custom` or `openai-qwen-oauth` providers ### 🚀 Break Through Limitations, Improve Efficiency -* **Bypass Official Restrictions**: Utilize OAuth authorization mechanism to effectively break through rate and quota limits of free APIs like Gemini -* **Free Advanced Models**: Use Claude Sonnet 4.5 for free via Kiro API mode, use Qwen3 Coder Plus via Qwen OAuth mode, reducing usage costs +* **Bypass Official Restrictions**: Utilize OAuth authorization mechanism to effectively break through rate and quota limits of services like Gemini, Antigravity +* **Free Advanced Models**: Use Claude Opus 4.5 for free via Kiro API mode, use Qwen3 Coder Plus via Qwen OAuth mode, reducing usage costs * **Intelligent Account Pool Scheduling**: Support multi-account polling, automatic failover, and configuration degradation, ensuring 99.9% service availability ### 🛡️ Secure and Controllable, Data Transparent @@ -66,106 +66,46 @@ * **System Prompt Management**: Support override and append modes, achieving perfect combination of unified base instructions and personalized extensions ### 🔧 Developer-Friendly, Easy to Extend +* **Web UI Management Console**: Real-time configuration management, health status monitoring, API testing and log viewing * **Modular Architecture**: Based on strategy and adapter patterns, adding new model providers requires only 3 steps * **Complete Test Coverage**: Integration and unit test coverage 90%+, ensuring code quality * **Containerized Deployment**: Provides Docker support, one-click deployment, cross-platform operation -* **MCP Protocol Support**: Perfectly compatible with Model Context Protocol, easily extend functionality --- ## 📑 Quick Navigation -- [🐳 Docker Deployment](https://aiproxy.justlikemaki.vip/en/docs/installation/docker-deployment.html) -- [🎨 Model Protocol and Provider Relationship Diagram](#-model-protocol-and-provider-relationship-diagram) +- [🐳 Docker Deployment](https://hub.docker.com/r/justlikemaki/aiclient-2-api) - [🔧 Usage Instructions](#-usage-instructions) -- [🚀 Project Startup Parameters](#-project-startup-parameters) - [📄 Open Source License](#-open-source-license) - [🙏 Acknowledgements](#-acknowledgements) - [⚠️ Disclaimer](#-disclaimer) --- -## 🎨 Model Protocol and Provider Relationship Diagram - -This project supports multiple model providers through different protocols. The following is an overview of their relationships: - -* **OpenAI Protocol (P_OPENAI)**: Implemented by `openai-custom`, `gemini-cli-oauth`, `claude-custom`, `claude-kiro-oauth`, `openai-qwen-oauth`, and `openaiResponses-custom` model providers. -* **Claude Protocol (P_CLAUDE)**: Implemented by `claude-custom`, `claude-kiro-oauth`, `gemini-cli-oauth`, `openai-custom`, `openai-qwen-oauth`, and `openaiResponses-custom` model providers. -* **Gemini Protocol (P_GEMINI)**: Implemented by `gemini-cli-oauth` model provider. - -Detailed relationship diagram: - - ```mermaid - - graph TD - subgraph Core_Protocols["Core Protocols"] - P_OPENAI[OpenAI Protocol] - P_GEMINI[Gemini Protocol] - P_CLAUDE[Claude Protocol] - end - - subgraph Supported_Model_Providers["Supported Model Providers"] - MP_OPENAI[openai-custom] - MP_GEMINI[gemini-cli-oauth] - MP_CLAUDE_C[claude-custom] - MP_CLAUDE_K[claude-kiro-oauth] - MP_QWEN[openai-qwen-oauth] - MP_OPENAI_RESP[openaiResponses-custom] - end - - P_OPENAI ---|Support| MP_OPENAI - P_OPENAI ---|Support| MP_QWEN - P_OPENAI ---|Support| MP_GEMINI - P_OPENAI ---|Support| MP_CLAUDE_C - P_OPENAI ---|Support| MP_CLAUDE_K - P_OPENAI ---|Support| MP_OPENAI_RESP - - P_GEMINI ---|Support| MP_GEMINI - - P_CLAUDE ---|Support| MP_CLAUDE_C - P_CLAUDE ---|Support| MP_CLAUDE_K - P_CLAUDE ---|Support| MP_GEMINI - P_CLAUDE ---|Support| MP_OPENAI - P_CLAUDE ---|Support| MP_QWEN - P_CLAUDE ---|Support| MP_OPENAI_RESP - - style P_OPENAI fill:#f9f,stroke:#333,stroke-width:2px - style P_GEMINI fill:#ccf,stroke:#333,stroke-width:2px - style P_CLAUDE fill:#cfc,stroke:#333,stroke-width:2px - - ``` - ---- - ## 🔧 Usage Instructions -### 🚀 Quick Start with install-and-run Script +### 🚀 Quick Start -The easiest way to get started with AIClient-2-API is to use our automated installation and startup scripts. We provide both Linux/macOS and Windows versions: +The most recommended way to use AIClient-2-API is to start it through an automated script and configure it visually directly in the **Web UI console**. -#### For Linux/macOS Users -```bash -# Make the script executable and run it -chmod +x install-and-run.sh -./install-and-run.sh -``` +#### 1. Run the startup script +* **Linux/macOS**: `chmod +x install-and-run.sh && ./install-and-run.sh` +* **Windows**: Double-click `install-and-run.bat` -#### For Windows Users -```cmd -# Run the batch file -install-and-run.bat -``` +#### 2. Access the console +After the server starts, open your browser and visit: +👉 [**http://localhost:3000**](http://localhost:3000) -#### What the Script Does +> **Default Password**: `admin123` (can be changed in the console or by modifying the `pwd` file after login) -The `install-and-run` script automatically: -1. **Checks Node.js Installation**: Verifies Node.js is installed and provides download link if missing -2. **Dependency Management**: Automatically installs npm dependencies if `node_modules` doesn't exist -3. **File Validation**: Ensures all required project files are present -4. **Server Startup**: Launches the API server on `http://localhost:3000` -5. **Web UI Access**: Provides direct access to the management console +#### 3. Visual Configuration (Recommended) +Go to the **"Configuration"** page, you can: +* ✅ Fill in the API Key for each provider or upload OAuth credential files +* ✅ Switch default model providers in real-time +* ✅ Monitor health status and real-time request logs -#### Script Output Example +#### Script Execution Example ``` ======================================== AI Client 2 API Quick Install Script @@ -196,50 +136,58 @@ The `install-and-run` script automatically: ![Web UI](src/img/web.png) -A comprehensive web-based management interface offering: +A functional Web management interface, including: -**📊 Dashboard**: System overview, interactive routing examples, and client configuration guides +**📊 Dashboard**: System overview, interactive routing examples, client configuration guide -**⚙️ Configuration**: Real-time parameter modification for all providers (Gemini, OpenAI, Claude, Kiro, Qwen) with advanced settings and file upload support +**⚙️ Configuration**: Real-time parameter modification, supporting all providers (Gemini, Antigravity, OpenAI, Claude, Kiro, Qwen), including advanced settings and file uploads -**🔗 Provider Pools**: Monitor active connections, provider health statistics, and enable/disable providers +**🔗 Provider Pools**: Monitor active connections, provider health statistics, enable/disable management -**📁 Config Files**: Centralized OAuth credential management with search, filtering, and file operations +**📁 Config Files**: Centralized OAuth credential management, supporting search filtering and file operations -**📜 Logs**: Real-time system and request logs with management controls +**📜 Real-time Logs**: Real-time display of system and request logs, with management controls -**🔐 Login**: Authentication required (default: `admin123`, modify via `pwd` file) +**🔐 Login Verification**: Default password `admin123`, can be modified via `pwd` file -Access: `http://localhost:3000` → Login → Sidebar navigation → Immediate effect changes - -#### MCP Protocol Support -This project is fully compatible with **Model Context Protocol (MCP)**, enabling seamless integration with MCP-supporting clients for powerful functional extensions. +Access: `http://localhost:3000` → Login → Sidebar navigation → Take effect immediately #### Multimodal Input Capabilities -Supports various input types including images and documents, providing richer interactive experiences and more powerful application scenarios. +Supports various input types such as images and documents, providing you with a richer interaction experience and more powerful application scenarios. #### Latest Model Support -Seamlessly supports the following latest large models, simply configure the corresponding OpenAI or Claude compatible interface in [`config.json`](./config.json): -* **Kimi K2** - Moonshot AI's latest flagship model -* **GLM-4.5** - Zhipu AI's latest version -* **Qwen Code** - Alibaba Tongyi Qianwen code-specific model -* **Gemini 3** - Google's latest preview model -* **Claude Sonnet 4.5** - Anthropic's latest flagship model +Seamlessly support the following latest large models, just configure the corresponding endpoint in Web UI or [`config.json`](./config.json): +* **Claude 4.5 Opus** - Anthropic's strongest model ever, now supported via Kiro, Antigravity +* **Gemini 3 Pro** - Google's next-generation architecture preview, now supported via Gemini, Antigravity +* **Qwen3 Coder Plus** - Alibaba Tongyi Qianwen's latest code-specific model, now supported via Qwen Code +* **Kimi K2 / MiniMax M2** - Synchronized support for top domestic flagship models, now supported via custom OpenAI, Claude --- ### 🔐 Authorization Configuration Guide +> **💡 Tip**: For the best experience, it is recommended to manage authorization visually through the **Web UI console**. + +#### 🌐 Web UI Quick Authorization (Recommended) +In the Web UI management interface, you can complete authorization configuration rapidly: +1. **Generate Authorization**: On the **"Provider Pools"** page or **"Configuration"** page, click the **"Generate Authorization"** button in the upper right corner of the corresponding provider (e.g., Gemini, Qwen). +2. **Scan/Login**: An authorization dialog will pop up, you can click **"Open in Browser"** for login verification. For Qwen, just complete the web login; for Gemini and Antigravity, complete the Google account authorization. +3. **Auto-Save**: After successful authorization, the system will automatically obtain credentials and save them to the corresponding directory in `configs/`. You can see the newly generated credentials on the **"Config Files"** page. +4. **Visual Management**: You can upload or delete credentials at any time in the Web UI, or use the **"Quick Associate"** function to bind existing credential files to providers with one click. + #### Gemini CLI OAuth Configuration 1. **Obtain OAuth Credentials**: Visit [Google Cloud Console](https://console.cloud.google.com/) to create a project and enable Gemini API -2. **First Authorization**: After using Gemini service, the command line will print Google authorization page, copy the page to browser for authorization, then return to command line -3. **Credential Storage**: After successful authorization, `oauth_creds.json` file will be automatically generated and saved to `~/.gemini` directory -4. **Project Configuration**: Need to provide a valid Google Cloud project ID, can be specified via startup parameter `--project-id` +2. **Project Configuration**: You may need to provide a valid Google Cloud project ID, which can be specified via the startup parameter `--project-id` +3. **Ensure Project ID**: When configuring in the Web UI, ensure the project ID entered matches the project ID displayed in the Google Cloud Console and Gemini CLI. + +#### Antigravity OAuth Configuration +1. **Personal Account**: Personal accounts require separate authorization, application channels have been closed. +2. **Pro Member**: Antigravity is temporarily open to Pro members, you need to purchase a Pro membership first. +3. **Organization Account**: Organization accounts require separate authorization, contact the administrator to obtain authorization. #### Qwen Code OAuth Configuration -1. **First Authorization**: After starting the service, the system will automatically open the authorization page in the browser -2. **Credential Storage**: After successful authorization, `oauth_creds.json` file will be automatically generated and saved to `~/.qwen` directory -3. **Recommended Parameters**: Use official default parameters for best results +1. **First Authorization**: After configuring the Qwen service, the system will automatically open the authorization page in the browser +2. **Recommended Parameters**: Use official default parameters for best results ```json { "temperature": 0, @@ -248,48 +196,37 @@ Seamlessly supports the following latest large models, simply configure the corr ``` #### Kiro API Configuration -1. **Environment Preparation**: [Download and install Kiro client](https://aibook.ren/archives/kiro-install) +1. **Environment Preparation**: [Download and install Kiro client](https://kiro.dev/pricing/) 2. **Complete Authorization**: Log in to your account in the client to generate `kiro-auth-token.json` credential file 3. **Best Practice**: Recommended to use with **Claude Code** for optimal experience 4. **Important Notice**: Kiro service usage policy has been updated, please visit the official website for the latest usage restrictions and terms #### Account Pool Management Configuration 1. **Create Pool Configuration File**: Create a configuration file referencing [provider_pools.json.example](./provider_pools.json.example) -2. **Configure Pool Parameter**: Set `PROVIDER_POOLS_FILE_PATH` in config.json to point to the pool configuration file -3. **Startup Parameter Configuration**: Use `--provider-pools-file ` parameter to specify the pool configuration file path -4. **Health Check**: The system will automatically perform periodic health checks and remove unhealthy providers +2. **Configure Pool Parameters**: Set `PROVIDER_POOLS_FILE_PATH` in config.json to point to the pool configuration file +3. **Startup Parameter Configuration**: Use the `--provider-pools-file ` parameter to specify the pool configuration file path +4. **Health Check**: The system will automatically perform periodic health checks and avoid using unhealthy providers --- -### 🔄 Model Provider Switching +### 📁 Authorization File Storage Paths -This project provides two flexible model switching methods to meet different usage scenario requirements. +Default storage locations for authorization credential files of each service: -Achieve instant switching by specifying provider identifier in API request path: +| Service | Default Path | Description | +|------|---------|------| +| **Gemini** | `~/.gemini/oauth_creds.json` | OAuth authentication credentials | +| **Kiro** | `~/.aws/sso/cache/kiro-auth-token.json` | Kiro authentication token | +| **Qwen** | `~/.qwen/oauth_creds.json` | Qwen OAuth credentials | +| **Antigravity** | `~/.antigravity/oauth_creds.json` | Antigravity OAuth credentials (supports Claude 4.5 Opus) | +> **Note**: `~` represents the user home directory (Windows: `C:\Users\username`, Linux/macOS: `/home/username` or `/Users/username`) +> +> **Custom Path**: Can specify custom storage location via relevant parameters in configuration file or environment variables -| Route Path | Description | Use Case | -|---------|------|---------| -| `/claude-custom` | Use Claude API from config file | Official Claude API calls | -| `/claude-kiro-oauth` | Access Claude via Kiro OAuth | Free use of Claude Sonnet 4.5 | -| `/openai-custom` | Use OpenAI provider to handle requests | Standard OpenAI API calls | -| `/gemini-cli-oauth` | Access via Gemini CLI OAuth | Break through Gemini free limits | -| `/openai-qwen-oauth` | Access via Qwen OAuth | Use Qwen Code Plus | -| `/openaiResponses-custom` | OpenAI Responses API | Structured dialogue scenarios | -| `/ollama` | Ollama API protocol | Unified access to all supported models | - -**Usage Examples**: -```bash -# Configure in programming agents like Cline, Kilo -API_ENDPOINT=http://localhost:3000/claude-kiro-oauth - -# Direct API call -curl http://localhost:3000/gemini-cli-oauth/v1/chat/completions \ - -H "Content-Type: application/json" \ - -d '{"model":"gemini-2.0-flash-exp","messages":[...]}' -``` +--- -### Ollama Protocol Usage Examples +### 🦙 Ollama Protocol Usage Examples This project supports the Ollama protocol, allowing access to all supported models through a unified interface. The Ollama endpoint provides standard interfaces such as `/api/tags`, `/api/chat`, `/api/generate`, etc. @@ -319,184 +256,16 @@ curl http://localhost:3000/ollama/api/chat \ - `[OpenAI]` - Use official OpenAI API - `[Qwen CLI]` - Access via Qwen OAuth ---- - -### 📁 Authorization File Storage Paths - -Default storage locations for authorization credential files of each service: - -| Service | Default Path | Description | -|------|---------|------| -| **Gemini** | `~/.gemini/oauth_creds.json` | OAuth authentication credentials | -| **Kiro** | `~/.aws/sso/cache/kiro-auth-token.json` | Kiro authentication token | -| **Qwen** | `~/.qwen/oauth_creds.json` | Qwen OAuth credentials | -| **Antigravity** | `~/.antigravity/oauth_creds.json` | Antigravity OAuth credentials | - -> **Note**: `~` represents the user home directory (Windows: `C:\Users\username`, Linux/macOS: `/home/username` or `/Users/username`) -> -> **Custom Path**: Can specify custom storage location via relevant parameters in configuration file or environment variables - ---- - -## 🚀 Project Startup Parameters - -This project supports rich command-line parameter configuration, allowing flexible adjustment of service behavior as needed. The following is a detailed explanation of all startup parameters, displayed in functional groups: - -### 🔧 Server Configuration Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--host` | string | localhost | Server listening address | -| `--port` | number | 3000 | Server listening port | -| `--api-key` | string | 123456 | API key for authentication | - -### 🤖 Model Provider Configuration Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--model-provider` | string | gemini-cli-oauth | AI model provider, optional values: openai-custom, claude-custom, gemini-cli-oauth, claude-kiro-oauth, openai-qwen-oauth, openaiResponses-custom, gemini-antigravity | - -### 🧠 OpenAI Compatible Provider Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--openai-api-key` | string | null | OpenAI API key (required when `model-provider` is `openai-custom`) | -| `--openai-base-url` | string | null | OpenAI API base URL (required when `model-provider` is `openai-custom`) | - -### 🖥️ Claude Compatible Provider Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--claude-api-key` | string | null | Claude API key (required when `model-provider` is `claude-custom`) | -| `--claude-base-url` | string | null | Claude API base URL (required when `model-provider` is `claude-custom`) | - -### 🔐 Gemini OAuth Authentication Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--gemini-oauth-creds-base64` | string | null | Base64 string of Gemini OAuth credentials (optional when `model-provider` is `gemini-cli-oauth`, choose one with `--gemini-oauth-creds-file`) | -| `--gemini-oauth-creds-file` | string | null | Gemini OAuth credentials JSON file path (optional when `model-provider` is `gemini-cli-oauth`, choose one with `--gemini-oauth-creds-base64`) | -| `--project-id` | string | null | Google Cloud project ID (required when `model-provider` is `gemini-cli-oauth`) | - -### 🎮 Kiro OAuth Authentication Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--kiro-oauth-creds-base64` | string | null | Base64 string of Kiro OAuth credentials (optional when `model-provider` is `claude-kiro-oauth`, choose one with `--kiro-oauth-creds-file`) | -| `--kiro-oauth-creds-file` | string | null | Kiro OAuth credentials JSON file path (optional when `model-provider` is `claude-kiro-oauth`, choose one with `--kiro-oauth-creds-base64`) | - -### 🐼 Qwen OAuth Authentication Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--qwen-oauth-creds-file` | string | null | Qwen OAuth credentials JSON file path (required when `model-provider` is `openai-qwen-oauth`) | - -### 🌌 Antigravity OAuth Authentication Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--antigravity-oauth-creds-file` | string | null | Antigravity OAuth credentials JSON file path (optional when `model-provider` is `gemini-antigravity`) | - -### 🔄 OpenAI Responses API Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--model-provider` | string | openaiResponses-custom | Model provider, set to `openaiResponses-custom` when using OpenAI Responses API | -| `--openai-api-key` | string | null | OpenAI API key (required when `model-provider` is `openaiResponses-custom`) | -| `--openai-base-url` | string | null | OpenAI API base URL (required when `model-provider` is `openaiResponses-custom`) | - -### 📝 System Prompt Configuration Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--system-prompt-file` | string | input_system_prompt.txt | System prompt file path | -| `--system-prompt-mode` | string | overwrite | System prompt mode, optional values: overwrite (override), append (append) | - -### 📊 Log Configuration Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--log-prompts` | string | none | Prompt log mode, optional values: console (console), file (file), none (none) | -| `--prompt-log-base-name` | string | prompt_log | Prompt log file base name | - -### 🔄 Retry Mechanism Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--request-max-retries` | number | 3 | Maximum number of automatic retries when API requests fail | -| `--request-base-delay` | number | 1000 | Base delay time (milliseconds) between automatic retries, delay increases after each retry | - -### ⏰ Scheduled Task Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--cron-near-minutes` | number | 15 | Interval time (minutes) for OAuth token refresh task schedule | -| `--cron-refresh-token` | boolean | true | Whether to enable automatic OAuth token refresh task | - -### 🎯 Account Pool Configuration Parameters - -| Parameter | Type | Default Value | Description | -|------|------|--------|------| -| `--provider-pools-file` | string | null | Provider account pool configuration file path | - -### Usage Examples - -```bash -# Basic usage -node src/api-server.js - -# Specify port and API key -node src/api-server.js --port 8080 --api-key my-secret-key - -# Use OpenAI provider -node src/api-server.js --model-provider openai-custom --openai-api-key sk-xxx --openai-base-url https://api.openai.com/v1 - -# Use Claude provider -node src/api-server.js --model-provider claude-custom --claude-api-key sk-ant-xxx --claude-base-url https://api.anthropic.com - -# Use OpenAI Responses API provider -node src/api-server.js --model-provider openaiResponses-custom --openai-api-key sk-xxx --openai-base-url https://api.openai.com/v1 - -# Use Gemini provider (Base64 credentials) -node src/api-server.js --model-provider gemini-cli-oauth --gemini-oauth-creds-base64 eyJ0eXBlIjoi... --project-id your-project-id - -# Use Gemini provider (credentials file) -node src/api-server.js --model-provider gemini-cli-oauth --gemini-oauth-creds-file /path/to/credentials.json --project-id your-project-id - -# Configure system prompt -node src/api-server.js --system-prompt-file custom-prompt.txt --system-prompt-mode append - -# Configure logging -node src/api-server.js --log-prompts console -node src/api-server.js --log-prompts file --prompt-log-base-name my-logs - -# Configure Account Pool -node src/api-server.js --provider-pools-file ./provider_pools.json - -# Complete example -node src/api-server.js \ - --host 0.0.0.0 \ - --port 3000 \ - --api-key my-secret-key \ - --model-provider gemini-cli-oauth \ - --project-id my-gcp-project \ - --gemini-oauth-creds-file ./credentials.json \ - --system-prompt-file ./custom-system-prompt.txt \ - --system-prompt-mode overwrite \ - --log-prompts file \ - --prompt-log-base-name api-logs \ - --provider-pools-file ./provider_pools.json -``` - --- ## 📄 Open Source License -This project operates under the [**GNU General Public License v3 (GPLv3)**](https://www.gnu.org/licenses/gpl-3.0). For complete details, please refer to the `LICENSE` file located in the root directory. +This project follows the [**GNU General Public License v3 (GPLv3)**](https://www.gnu.org/licenses/gpl-3.0) license. For details, please check the `LICENSE` file in the root directory. ## 🙏 Acknowledgements -The development of this project was significantly inspired by the official Google Gemini CLI and incorporated some code implementations from Cline 3.18.0's `gemini-cli.ts`. We extend our sincere gratitude to the official Google team and the Cline development team for their exceptional work! +The development of this project was greatly inspired by the official Google Gemini CLI and referenced part of the code implementation of `gemini-cli.ts` in Cline 3.18.0. Sincere thanks to the Google official team and the Cline development team for their excellent work! + ### Contributor List Thanks to all the developers who contributed to the AIClient-2-API project: @@ -504,7 +273,8 @@ Thanks to all the developers who contributed to the AIClient-2-API project: [![Contributors](https://contrib.rocks/image?repo=justlovemaki/AIClient-2-API)](https://github.com/justlovemaki/AIClient-2-API/graphs/contributors) -## 🌟 Star History +### 🌟 Star History + [![Star History Chart](https://api.star-history.com/svg?repos=justlovemaki/AIClient-2-API&type=Timeline)](https://www.star-history.com/#justlovemaki/AIClient-2-API&Timeline) diff --git a/install-and-run.bat b/install-and-run.bat index 30fd4a2..5b07253 100644 --- a/install-and-run.bat +++ b/install-and-run.bat @@ -2,79 +2,80 @@ chcp 65001 >nul setlocal enabledelayedexpansion +:: 处理参数 +set FORCE_PULL=0 + +for %%a in (%*) do ( + if "%%a"=="--pull" set FORCE_PULL=1 +) + echo ======================================== echo AI Client 2 API 快速安装启动脚本 echo ======================================== echo. +:: 检查Git并尝试pull +if !FORCE_PULL! equ 1 ( + echo [更新] 正在从远程仓库拉取最新代码... + git --version >nul 2>&1 + if !errorlevel! equ 0 ( + git pull + if !errorlevel! neq 0 ( + echo [警告] Git pull 失败,请检查网络或手动处理冲突。 + ) else ( + echo [成功] 代码已更新。 + ) + ) else ( + echo [警告] 未检测到 Git,跳过代码拉取。 + ) +) + :: 检查Node.js是否已安装 echo [检查] 正在检查Node.js是否已安装... node --version >nul 2>&1 if %errorlevel% neq 0 ( - echo ❌ 错误:未检测到Node.js,请先安装Node.js - echo 📥 下载地址:https://nodejs.org/ - echo 💡 推荐安装LTS版本 + echo [错误] 未检测到Node.js,请先安装Node.js + echo 下载地址:https://nodejs.org/ + echo 提示:推荐安装LTS版本 pause exit /b 1 ) :: 获取Node.js版本 for /f "tokens=*" %%i in ('node --version') do set NODE_VERSION=%%i -echo ✅ Node.js已安装,版本: !NODE_VERSION! +echo [成功] Node.js已安装,版本: !NODE_VERSION! :: 检查package.json是否存在 if not exist "package.json" ( - echo ❌ 错误:未找到package.json文件 + echo [错误] 未找到package.json文件 echo 请确保在项目根目录下运行此脚本 pause exit /b 1 ) -echo ✅ 找到package.json文件 +echo [成功] 找到package.json文件 -:: 检查node_modules目录是否存在 -if not exist "node_modules" ( - echo [安装] node_modules目录不存在,正在安装依赖... - echo 这可能需要几分钟时间,请耐心等待... - echo 正在执行: npm install... - :: 使用npm install并设置超时机制 - npm install --timeout=300000 - if !errorlevel! neq 0 ( - echo ❌ 依赖安装失败 - echo 请检查网络连接或手动运行 'npm install' - pause - exit /b 1 - ) - echo ✅ 依赖安装完成 -) else ( - echo ✅ node_modules目录已存在 -) - -:: 检查package-lock.json是否存在 -if not exist "package-lock.json" ( - echo [更新] package-lock.json不存在,正在更新依赖... - echo 正在执行: npm install... - :: 使用npm install并设置超时机制 - npm install --timeout=300000 - if !errorlevel! neq 0 ( - echo ❌ 依赖更新失败 - echo 请检查网络连接或手动运行 'npm install' - pause - exit /b 1 - ) - echo ✅ 依赖更新完成 -) else ( - echo ✅ package-lock.json文件存在 +echo [安装] 正在安装/更新依赖... +echo 这可能需要几分钟时间,请耐心等待... +echo 正在执行: npm install... +:: 使用npm install并设置超时机制 +call npm install --timeout=300000 +if !errorlevel! neq 0 ( + echo [错误] 依赖安装失败 + echo 请检查网络连接或手动运行 'npm install' + pause + exit /b 1 ) +echo [成功] 依赖安装/更新完成 :: 检查src目录和api-server.js是否存在 if not exist "src\api-server.js" ( - echo ❌ 错误:未找到src\api-server.js文件 + echo [错误] 未找到src\api-server.js文件 pause exit /b 1 ) -echo ✅ 项目文件检查完成 +echo [成功] 项目文件检查完成 :: 启动应用程序 echo. @@ -82,9 +83,9 @@ echo ======================================== echo 启动AI Client 2 API服务器... echo ======================================== echo. -echo 🌐 服务器将在 http://localhost:3000 启动 -echo 📖 访问 http://localhost:3000 查看管理界面 -echo ⏹️ 按 Ctrl+C 停止服务器 +echo 服务器将在 http://localhost:3000 启动 +echo 访问 http://localhost:3000 查看管理界面 +echo 按 Ctrl+C 停止服务器 echo. :: 启动服务器 diff --git a/install-and-run.sh b/install-and-run.sh index fb9e2ed..d2acbeb 100644 --- a/install-and-run.sh +++ b/install-and-run.sh @@ -9,75 +9,79 @@ echo " AI Client 2 API 快速安装启动脚本" echo "========================================" echo +# 处理参数 +FORCE_PULL=0 + +for arg in "$@"; do + if [ "$arg" == "--pull" ]; then + FORCE_PULL=1 + fi +done + +# 检查Git并尝试pull +if [ $FORCE_PULL -eq 1 ]; then + echo "[更新] 正在从远程仓库拉取最新代码..." + if command -v git > /dev/null 2>&1; then + git pull + if [ $? -ne 0 ]; then + echo "[警告] Git pull 失败,请检查网络或手动处理冲突。" + else + echo "[成功] 代码已更新。" + fi + else + echo "[警告] 未检测到 Git,跳过代码拉取。" + fi +fi + # 检查Node.js是否已安装 echo "[检查] 正在检查Node.js是否已安装..." node --version > /dev/null 2>&1 if [ $? -ne 0 ]; then - echo "❌ 错误:未检测到Node.js,请先安装Node.js" - echo "📥 下载地址:https://nodejs.org/" - echo "💡 推荐安装LTS版本" + echo "[错误] 未检测到Node.js,请先安装Node.js" + echo "下载地址:https://nodejs.org/" + echo "提示:推荐安装LTS版本" exit 1 fi # 获取Node.js版本 NODE_VERSION=$(node --version 2>/dev/null) -echo "✅ Node.js已安装,版本: $NODE_VERSION" +echo "[成功] Node.js已安装,版本: $NODE_VERSION" # 检查npm是否可用 echo "[检查] 正在检查npm是否可用..." npm --version > /dev/null 2>&1 if [ $? -ne 0 ]; then - echo "❌ 错误:npm不可用,请重新安装Node.js" + echo "[错误] npm不可用,请重新安装Node.js" exit 1 fi # 检查package.json是否存在 if [ ! -f "package.json" ]; then - echo "❌ 错误:未找到package.json文件" + echo "[错误] 未找到package.json文件" echo "请确保在项目根目录下运行此脚本" exit 1 fi -echo "✅ 找到package.json文件" +echo "[成功] 找到package.json文件" -# 检查node_modules目录是否存在 -if [ ! -d "node_modules" ]; then - echo "[安装] node_modules目录不存在,正在安装依赖..." - echo "这可能需要几分钟时间,请耐心等待..." - echo "正在执行: npm install..." - npm install - if [ $? -ne 0 ]; then - echo "❌ 依赖安装失败" - echo "请检查网络连接或运行 'npm install' 手动安装" - exit 1 - fi - echo "✅ 依赖安装完成" -else - echo "✅ node_modules目录已存在" -fi - -# 检查package-lock.json是否存在 -if [ ! -f "package-lock.json" ]; then - echo "[更新] package-lock.json不存在,正在更新依赖..." - echo "正在执行: npm install..." - npm install - if [ $? -ne 0 ]; then - echo "❌ 依赖更新失败" - echo "请检查网络连接或运行 'npm install' 手动安装" - exit 1 - fi - echo "✅ 依赖更新完成" -else - echo "✅ package-lock.json文件存在" +echo "[安装] 正在安装/更新依赖..." +echo "这可能需要几分钟时间,请耐心等待..." +echo "正在执行: npm install..." +npm install +if [ $? -ne 0 ]; then + echo "[错误] 依赖安装失败" + echo "请检查网络连接或运行 'npm install' 手动安装" + exit 1 fi +echo "[成功] 依赖安装/更新完成" # 检查src目录和api-server.js是否存在 if [ ! -f "src/api-server.js" ]; then - echo "❌ 错误:未找到src/api-server.js文件" + echo "[错误] 未找到src/api-server.js文件" exit 1 fi -echo "✅ 项目文件检查完成" +echo "[成功] 项目文件检查完成" # 启动应用程序 echo @@ -85,9 +89,9 @@ echo "========================================" echo " 启动AI Client 2 API服务器..." echo "========================================" echo -echo "🌐 服务器将在 http://localhost:3000 启动" -echo "📖 访问 http://localhost:3000 查看管理界面" -echo "⏹️ 按 Ctrl+C 停止服务器" +echo "服务器将在 http://localhost:3000 启动" +echo "访问 http://localhost:3000 查看管理界面" +echo "按 Ctrl+C 停止服务器" echo # 启动服务器 diff --git a/src/claude/claude-kiro.js b/src/claude/claude-kiro.js index c539dca..ad1bd8e 100644 --- a/src/claude/claude-kiro.js +++ b/src/claude/claude-kiro.js @@ -53,28 +53,36 @@ const KIRO_AUTH_TOKEN_FILE = "kiro-auth-token.json"; * Provides OpenAI-compatible API for Claude Sonnet 4 via Kiro/CodeWhisperer */ -async function getMacAddressSha256() { - const networkInterfaces = os.networkInterfaces(); - let macAddress = ''; +/** + * 根据当前配置生成唯一的机器码(Machine ID) + * 确保每个配置对应一个唯一且不变的 ID + * @param {Object} credentials - 当前凭证信息 + * @returns {string} SHA256 格式的机器码 + */ +function generateMachineIdFromConfig(credentials) { + // 优先级:节点UUID > profileArn > clientId > fallback + const uniqueKey = credentials.uuid || credentials.profileArn || credentials.clientId || "KIRO_DEFAULT_MACHINE"; + return crypto.createHash('sha256').update(uniqueKey).digest('hex'); +} - for (const interfaceName in networkInterfaces) { - const networkInterface = networkInterfaces[interfaceName]; - for (const iface of networkInterface) { - if (!iface.internal && iface.mac && iface.mac !== '00:00:00:00:00:00') { - macAddress = iface.mac; - break; - } - } - if (macAddress) break; - } +/** + * 实时获取系统配置信息,用于生成 User-Agent + * @returns {Object} 包含 osName, nodeVersion 等信息 + */ +function getSystemRuntimeInfo() { + const osPlatform = os.platform(); + const osRelease = os.release(); + const nodeVersion = process.version.replace('v', ''); + + let osName = osPlatform; + if (osPlatform === 'win32') osName = `windows#${osRelease}`; + else if (osPlatform === 'darwin') osName = `macos#${osRelease}`; + else osName = `${osPlatform}#${osRelease}`; - if (!macAddress) { - console.warn("无法获取MAC地址,将使用默认值。"); - macAddress = '00:00:00:00:00:00'; // Fallback if no MAC address is found - } - - const sha256Hash = crypto.createHash('sha256').update(macAddress).digest('hex'); - return sha256Hash; + return { + osName, + nodeVersion + }; } // Helper functions for tool calls and JSON parsing @@ -271,6 +279,7 @@ export class KiroApiService { this.credPath = config.KIRO_OAUTH_CREDS_DIR_PATH || path.join(os.homedir(), ".aws", "sso", "cache"); this.credsBase64 = config.KIRO_OAUTH_CREDS_BASE64; this.useSystemProxy = config?.USE_SYSTEM_PROXY_KIRO ?? false; + this.uuid = config?.uuid; // 获取多节点配置的 uuid console.log(`[Kiro] System proxy ${this.useSystemProxy ? 'enabled' : 'disabled'}`); // this.accessToken = config.KIRO_ACCESS_TOKEN; // this.refreshToken = config.KIRO_REFRESH_TOKEN; @@ -305,8 +314,15 @@ export class KiroApiService { if (this.isInitialized) return; console.log('[Kiro] Initializing Kiro API Service...'); await this.initializeAuth(); - const macSha256 = await getMacAddressSha256(); + // 根据当前加载的凭证生成唯一的 Machine ID + const machineId = generateMachineIdFromConfig({ + uuid: this.uuid, + profileArn: this.profileArn, + clientId: this.clientId + }); const kiroVersion = KIRO_CONSTANTS.KIRO_VERSION; + const { osName, nodeVersion } = getSystemRuntimeInfo(); + // 配置 HTTP/HTTPS agent 限制连接池大小,避免资源泄漏 const httpAgent = new http.Agent({ keepAlive: true, @@ -330,8 +346,9 @@ export class KiroApiService { 'Accept': KIRO_CONSTANTS.ACCEPT_JSON, 'amz-sdk-request': 'attempt=1; max=1', 'x-amzn-kiro-agent-mode': 'vibe', - 'x-amz-user-agent': `aws-sdk-js/1.0.0 KiroIDE-${kiroVersion}-${macSha256}`, - 'user-agent': `aws-sdk-js/1.0.0 ua/2.1 os/win32#10.0.26100 lang/js md/nodejs#22.21.1 api/codewhispererruntime#1.0.0 m/N,E KiroIDE-${kiroVersion}-${macSha256}` + 'x-amz-user-agent': `aws-sdk-js/1.0.0 KiroIDE-${kiroVersion}-${machineId}`, + 'user-agent': `aws-sdk-js/1.0.0 ua/2.1 os/${osName} lang/js md/nodejs#${nodeVersion} api/codewhispererruntime#1.0.0 m/E KiroIDE-${kiroVersion}-${machineId}`, + 'Connection': 'close' }, }; @@ -1773,9 +1790,21 @@ async initializeAuth(forceRefresh = false) { const fullUrl = `${usageLimitsUrl}?${params.toString()}`; // 构建请求头 + const machineId = generateMachineIdFromConfig({ + uuid: this.uuid, + profileArn: this.profileArn, + clientId: this.clientId + }); + const kiroVersion = KIRO_CONSTANTS.KIRO_VERSION; + const { osName, nodeVersion } = getSystemRuntimeInfo(); + const headers = { - 'amz-sdk-invocation-id': uuidv4(), 'Authorization': `Bearer ${this.accessToken}`, + 'x-amz-user-agent': `aws-sdk-js/1.0.0 KiroIDE-${kiroVersion}-${machineId}`, + 'user-agent': `aws-sdk-js/1.0.0 ua/2.1 os/${osName} lang/js md/nodejs#${nodeVersion} api/codewhispererruntime#1.0.0 m/E KiroIDE-${kiroVersion}-${machineId}`, + 'amz-sdk-invocation-id': uuidv4(), + 'amz-sdk-request': 'attempt=1; max=1', + 'Connection': 'close' }; try { diff --git a/src/oauth-handlers.js b/src/oauth-handlers.js index e85603e..071229e 100644 --- a/src/oauth-handlers.js +++ b/src/oauth-handlers.js @@ -245,8 +245,7 @@ async function handleGoogleOAuth(providerKey, currentConfig, options = {}) { authInfo: { provider: providerKey, redirectUri: redirectUri, - port: config.port, - instructions: '请在浏览器中打开此链接进行授权,授权完成后会自动保存凭据文件' + port: config.port } }; } @@ -508,8 +507,7 @@ export async function handleQwenOAuth(currentConfig, options = {}) { verificationUriComplete: deviceAuth.verification_uri_complete, expiresIn: expiresIn, interval: interval, - codeVerifier: codeVerifier, - instructions: '请在浏览器中打开此链接并输入用户码进行授权。授权完成后,系统会自动轮询获取访问令牌。' + codeVerifier: codeVerifier } }; } catch (error) { diff --git a/src/openai/qwen-core.js b/src/openai/qwen-core.js index e2beea7..cfda2b0 100644 --- a/src/openai/qwen-core.js +++ b/src/openai/qwen-core.js @@ -877,6 +877,11 @@ class QwenOAuth2Client { constructor(config, useSystemProxy = false) { this.config = config; this.useSystemProxy = useSystemProxy; + + // Initialize OAuth endpoints + const oauthBaseUrl = config.QWEN_OAUTH_BASE_URL || DEFAULT_QWEN_OAUTH_BASE_URL; + this.oauthDeviceCodeEndpoint = `${oauthBaseUrl}/api/v1/oauth2/device/code`; + this.oauthTokenEndpoint = `${oauthBaseUrl}/api/v1/oauth2/token`; } setCredentials(credentials) { this.credentials = credentials; } diff --git a/src/service-manager.js b/src/service-manager.js index ea5508e..974b9a1 100644 --- a/src/service-manager.js +++ b/src/service-manager.js @@ -228,6 +228,7 @@ export async function getApiService(config, requestedModel = null, options = {}) console.warn(`[API Service] No healthy provider found in pool for ${config.MODEL_PROVIDER}${requestedModel ? ` supporting model: ${requestedModel}` : ''}. Falling back to main config.`); } } + // 号池不可用时降级,直接使用当前请求的 config 初始化服务适配器 return getServiceAdapter(serviceConfig); } diff --git a/static/app/modal.js b/static/app/modal.js index 905b9d6..a3d1d5f 100644 --- a/static/app/modal.js +++ b/static/app/modal.js @@ -1098,8 +1098,8 @@ function addDynamicConfigFields(form, providerType) { const field1 = filteredFields[i]; // 检查是否为密码类型字段 const isPassword1 = field1.type === 'password'; - // 检查是否为OAuth凭据文件路径字段 - const isOAuthFilePath1 = field1.id.includes('OauthCredsFilePath'); + // 检查是否为OAuth凭据文件路径字段(兼容两种命名方式) + const isOAuthFilePath1 = field1.id.includes('OAUTH_CREDS_FILE_PATH') || field1.id.includes('OauthCredsFilePath'); if (isPassword1) { fields += ` @@ -1141,8 +1141,8 @@ function addDynamicConfigFields(form, providerType) { if (field2) { // 检查是否为密码类型字段 const isPassword2 = field2.type === 'password'; - // 检查是否为OAuth凭据文件路径字段 - const isOAuthFilePath2 = field2.id.includes('OauthCredsFilePath'); + // 检查是否为OAuth凭据文件路径字段(兼容两种命名方式) + const isOAuthFilePath2 = field2.id.includes('OAUTH_CREDS_FILE_PATH') || field2.id.includes('OauthCredsFilePath'); if (isPassword2) { fields += ` diff --git a/static/app/provider-manager.js b/static/app/provider-manager.js index 4d344d2..8c0ad37 100644 --- a/static/app/provider-manager.js +++ b/static/app/provider-manager.js @@ -401,41 +401,22 @@ function showAuthModal(authUrl, authInfo) {

授权步骤:

  1. 点击下方按钮在浏览器中打开授权页面
  2. -
  3. 完成授权后,系统会自动获取访问令牌
  4. +
  5. 完成授权后,系统会自动获取凭据文件
  6. +
  7. 凭据文件可在上传配置管理中查看和管理
  8. 授权有效期: ${Math.floor(authInfo.expiresIn / 60)} 分钟
-

${authInfo.instructions}

-
- 授权文件路径: - ${authFilePath} - 注:~ 表示用户主目录(Windows: C:\\Users\\用户名,Linux/macOS: /home/用户名 或 /Users/用户名) -
`; } else { instructionsHtml = `
-
-
- ⚠️ 重要提醒:回调地址限制 -

OAuth回调地址的 host 必须是 localhost127.0.0.1,否则授权将无法完成!

-

当前回调地址: ${authInfo.redirectUri}

-

如果当前配置的 host 不是 localhost 或 127.0.0.1,请先修改配置后重新生成授权链接。

-
-

授权步骤:

    -
  1. 确认上方回调地址的 host 是 localhost 或 127.0.0.1
  2. 点击下方按钮在浏览器中打开授权页面
  3. 使用您的Google账号登录并授权
  4. 授权完成后,凭据文件会自动保存
  5. +
  6. 凭据文件可在上传配置管理中查看和管理
-

${authInfo.instructions}

-
- 授权文件路径: - ${authFilePath} - 注:~ 表示用户主目录(Windows: C:\\Users\\用户名,Linux/macOS: /home/用户名 或 /Users/用户名) -
`; } @@ -521,6 +502,7 @@ function showAuthModal(authUrl, authInfo) { // 添加手动输入回调 URL 的 UI const urlSection = modal.querySelector('.auth-url-section'); + if (urlSection && !modal.querySelector('.manual-callback-section')) { const manualInputHtml = `

自动监听受阻?

@@ -534,6 +516,7 @@ function showAuthModal(authUrl, authInfo) {
`; urlSection.insertAdjacentHTML('afterend', manualInputHtml); + } const manualInput = modal.querySelector('.manual-callback-input'); const applyBtn = modal.querySelector('.apply-callback-btn'); @@ -597,12 +580,6 @@ function showAuthModal(authUrl, authInfo) { } }); - // 点击遮罩层关闭 - modal.addEventListener('click', (e) => { - if (e.target === modal) { - modal.remove(); - } - }); } export {