check-balance 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. check_balance-0.1.0/.github/workflows/ci.yml +57 -0
  2. check_balance-0.1.0/.gitignore +37 -0
  3. check_balance-0.1.0/LICENSE +21 -0
  4. check_balance-0.1.0/PKG-INFO +202 -0
  5. check_balance-0.1.0/README.md +174 -0
  6. check_balance-0.1.0/README_zh.md +174 -0
  7. check_balance-0.1.0/check_balance/__init__.py +1 -0
  8. check_balance-0.1.0/check_balance/__main__.py +4 -0
  9. check_balance-0.1.0/check_balance/auto_detect.py +59 -0
  10. check_balance-0.1.0/check_balance/constants.py +176 -0
  11. check_balance-0.1.0/check_balance/main.py +39 -0
  12. check_balance-0.1.0/check_balance/mcp_server.py +21 -0
  13. check_balance-0.1.0/check_balance/output.py +48 -0
  14. check_balance-0.1.0/check_balance/providers/__init__.py +38 -0
  15. check_balance-0.1.0/check_balance/providers/anthropic.py +41 -0
  16. check_balance-0.1.0/check_balance/providers/baichuan.py +8 -0
  17. check_balance-0.1.0/check_balance/providers/base.py +63 -0
  18. check_balance-0.1.0/check_balance/providers/cohere.py +8 -0
  19. check_balance-0.1.0/check_balance/providers/dashscope.py +8 -0
  20. check_balance-0.1.0/check_balance/providers/deepseek.py +35 -0
  21. check_balance-0.1.0/check_balance/providers/groq.py +8 -0
  22. check_balance-0.1.0/check_balance/providers/minimax.py +25 -0
  23. check_balance-0.1.0/check_balance/providers/mistral.py +8 -0
  24. check_balance-0.1.0/check_balance/providers/moonshot.py +25 -0
  25. check_balance-0.1.0/check_balance/providers/openai.py +40 -0
  26. check_balance-0.1.0/check_balance/providers/stepfun.py +29 -0
  27. check_balance-0.1.0/check_balance/providers/together.py +32 -0
  28. check_balance-0.1.0/check_balance/providers/xai.py +26 -0
  29. check_balance-0.1.0/check_balance/providers/zhipu.py +49 -0
  30. check_balance-0.1.0/mcp.example.json +8 -0
  31. check_balance-0.1.0/pyproject.toml +50 -0
  32. check_balance-0.1.0/tests/__init__.py +0 -0
  33. check_balance-0.1.0/tests/test_auto_detect.py +99 -0
  34. check_balance-0.1.0/tests/test_output.py +78 -0
  35. check_balance-0.1.0/tests/test_providers.py +87 -0
@@ -0,0 +1,57 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ tags: ['v*']
7
+ pull_request:
8
+ branches: [main]
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ${{ matrix.os }}
13
+ strategy:
14
+ matrix:
15
+ os: [ubuntu-latest, macos-latest, windows-latest]
16
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
17
+
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - name: Set up Python ${{ matrix.python-version }}
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+
26
+ - name: Install dependencies
27
+ run: |
28
+ python -m pip install --upgrade pip
29
+ pip install -e ".[dev]"
30
+
31
+ - name: Run tests
32
+ run: pytest -v
33
+
34
+ publish:
35
+ needs: test
36
+ runs-on: ubuntu-latest
37
+ if: startsWith(github.ref, 'refs/tags/v')
38
+
39
+ steps:
40
+ - uses: actions/checkout@v4
41
+
42
+ - name: Set up Python
43
+ uses: actions/setup-python@v5
44
+ with:
45
+ python-version: "3.12"
46
+
47
+ - name: Install build tools
48
+ run: pip install build
49
+
50
+ - name: Build package
51
+ run: python -m build
52
+
53
+ - name: Publish to PyPI
54
+ uses: pypa/gh-action-pypi-publish@release/v1
55
+ with:
56
+ password: ${{ secrets.PYPI_API_TOKEN }}
57
+ continue-on-error: true
@@ -0,0 +1,37 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Distribution / packaging
7
+ build/
8
+ dist/
9
+ *.egg-info/
10
+ *.egg
11
+
12
+ # Virtual environments
13
+ .venv/
14
+ venv/
15
+ env/
16
+
17
+ # IDE
18
+ .vscode/
19
+ .idea/
20
+ *.swp
21
+ *.swo
22
+
23
+ # Testing
24
+ .pytest_cache/
25
+ .coverage
26
+ htmlcov/
27
+
28
+ # OS
29
+ .DS_Store
30
+ Thumbs.db
31
+
32
+ # Environment variables
33
+ .env
34
+ .env.*
35
+
36
+ # Local config
37
+ opencode.json
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Han_new_new
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: check-balance
3
+ Version: 0.1.0
4
+ Summary: 一键查询当前 AI 服务的账户余额,支持 14 个主流 AI 提供商
5
+ Project-URL: Homepage, https://github.com/hanmumuHL/check_balance
6
+ Project-URL: Repository, https://github.com/hanmumuHL/check_balance
7
+ Project-URL: Issues, https://github.com/hanmumuHL/check_balance/issues
8
+ Author-email: Han_new_new <hanmumuHL@users.noreply.github.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai,api,balance,claude,deepseek,mcp,openai,opencode
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Classifier: Topic :: Utilities
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: mcp>=1.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
26
+ Requires-Dist: pytest>=7.0; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # check-balance
30
+
31
+ [中文文档](README_zh.md)
32
+
33
+ One-click balance checker for your AI API services. Supports 14 mainstream AI providers with automatic detection. Works as an MCP server or standalone CLI.
34
+
35
+ ## Features
36
+
37
+ - **MCP Server** — Integrates with opencode, Claude Code, Cursor, Claude Desktop
38
+ - **CLI Tool** — Run `check-balance` in any terminal
39
+ - **Auto-detection** — Reads opencode config and environment variables
40
+ - **14 Providers** — China (¥) and International ($) regions
41
+ - **Cross-platform** — Linux, macOS, Windows (WSL supported)
42
+ - **Zero config** — Just set your API keys and go
43
+
44
+ ## Supported Providers
45
+
46
+ ### China Region (¥)
47
+
48
+ | Provider | API Key Env | Balance API | Status |
49
+ |----------|-------------|-------------|--------|
50
+ | DeepSeek | `DEEPSEEK_API_KEY` | `GET /user/balance` | ✅ Direct query |
51
+ | Moonshot / Kimi | `MOONSHOT_API_KEY` | `GET /v1/users/me/balance` | ✅ Direct query |
52
+ | MiniMax | `MINIMAX_API_KEY` | `GET /v1/token_plan/remains` | ✅ Direct query |
53
+ | StepFun | `STEP_API_KEY` | `GET /v1/accounts` | ✅ Direct query |
54
+ | Zhipu / GLM | `ZHIPU_API_KEY` | Quota API | ~ Quota info |
55
+ | DashScope / Qwen | `DASHSCOPE_API_KEY` | — | ⚠️ Console only |
56
+ | Baichuan | `BAICHUAN_API_KEY` | — | ⚠️ Console only |
57
+
58
+ ### International Region ($)
59
+
60
+ | Provider | API Key Env | Balance API | Status |
61
+ |----------|-------------|-------------|--------|
62
+ | OpenAI | `OPENAI_API_KEY` | Usage/Cost API | ~ Usage + cost |
63
+ | Anthropic / Claude | `ANTHROPIC_API_KEY` | Admin Key Cost API | ~ Usage + cost |
64
+ | xAI / Grok | `XAI_API_KEY` | Balance API | ✅ Direct query |
65
+ | Together AI | `TOGETHER_API_KEY` | Usage API | ~ Usage + cost |
66
+ | Mistral | `MISTRAL_API_KEY` | — | ⚠️ Console only |
67
+ | Groq | `GROQ_API_KEY` | — | ⚠️ Console only |
68
+ | Cohere | `COHERE_API_KEY` | — | ⚠️ Console only |
69
+
70
+ > **Note:** Cursor subscription balance is not supported as Cursor uses its own proxy and does not expose API keys.
71
+
72
+ ## Installation
73
+
74
+ ```bash
75
+ pip install check-balance
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ ### As CLI
81
+
82
+ ```bash
83
+ check-balance
84
+ # or
85
+ python -m check_balance
86
+ ```
87
+
88
+ ### As MCP Server
89
+
90
+ #### opencode
91
+
92
+ Add to your `opencode.json`:
93
+
94
+ ```json
95
+ {
96
+ "mcp": {
97
+ "check-balance": {
98
+ "type": "local",
99
+ "command": ["python", "-m", "check_balance.mcp_server"],
100
+ "enabled": true
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+ Then type `/balance` in opencode or ask "check my AI balance".
107
+
108
+ #### Claude Code
109
+
110
+ Create `.mcp.json` in your project root:
111
+
112
+ ```json
113
+ {
114
+ "mcpServers": {
115
+ "check-balance": {
116
+ "command": "python",
117
+ "args": ["-m", "check_balance.mcp_server"]
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ Or add to `~/.claude/mcp.json` for global access.
124
+
125
+ #### Cursor
126
+
127
+ Create `.cursor/mcp.json` in your project root:
128
+
129
+ ```json
130
+ {
131
+ "mcpServers": {
132
+ "check-balance": {
133
+ "command": "python",
134
+ "args": ["-m", "check_balance.mcp_server"]
135
+ }
136
+ }
137
+ }
138
+ ```
139
+
140
+ Or add to `~/.cursor/mcp.json` for global access.
141
+
142
+ #### Claude Desktop
143
+
144
+ Edit `claude_desktop_config.json`:
145
+
146
+ | OS | Path |
147
+ |----|------|
148
+ | macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
149
+ | Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
150
+ | Linux | `~/.config/Claude/claude_desktop_config.json` |
151
+
152
+ ```json
153
+ {
154
+ "mcpServers": {
155
+ "check-balance": {
156
+ "command": "python",
157
+ "args": ["-m", "check_balance.mcp_server"]
158
+ }
159
+ }
160
+ }
161
+ ```
162
+
163
+ ## How It Works
164
+
165
+ 1. **Auto-detection** — Reads `opencode.json` to identify your current model/provider, then scans environment variables for all configured API keys
166
+ 2. **Balance query** — Calls each provider's balance/usage API
167
+ 3. **Formatted output** — Shows results with ¥ (China) or $ (International) currency
168
+
169
+ ## Output Example
170
+
171
+ ```
172
+ AI 服务余额查询
173
+ ==================================================
174
+ * DeepSeek (中国)
175
+ 余额: ¥ 142.50
176
+
177
+ Moonshot (中国)
178
+ 余额: ¥ 3.00
179
+
180
+ OpenAI (海外)
181
+ OpenAI 未开放余额查询 API,近 30 天用量: $ 18.32
182
+ 控制台: https://platform.openai.com/usage
183
+
184
+ Mistral (海外)
185
+ 未开放余额查询 API
186
+ 控制台: https://console.mistral.ai/usage
187
+
188
+ * 标记为当前使用的服务
189
+ ```
190
+
191
+ ## Development
192
+
193
+ ```bash
194
+ git clone https://github.com/hanmumuHL/check_balance.git
195
+ cd check_balance
196
+ pip install -e ".[dev]"
197
+ pytest
198
+ ```
199
+
200
+ ## License
201
+
202
+ MIT
@@ -0,0 +1,174 @@
1
+ # check-balance
2
+
3
+ [中文文档](README_zh.md)
4
+
5
+ One-click balance checker for your AI API services. Supports 14 mainstream AI providers with automatic detection. Works as an MCP server or standalone CLI.
6
+
7
+ ## Features
8
+
9
+ - **MCP Server** — Integrates with opencode, Claude Code, Cursor, Claude Desktop
10
+ - **CLI Tool** — Run `check-balance` in any terminal
11
+ - **Auto-detection** — Reads opencode config and environment variables
12
+ - **14 Providers** — China (¥) and International ($) regions
13
+ - **Cross-platform** — Linux, macOS, Windows (WSL supported)
14
+ - **Zero config** — Just set your API keys and go
15
+
16
+ ## Supported Providers
17
+
18
+ ### China Region (¥)
19
+
20
+ | Provider | API Key Env | Balance API | Status |
21
+ |----------|-------------|-------------|--------|
22
+ | DeepSeek | `DEEPSEEK_API_KEY` | `GET /user/balance` | ✅ Direct query |
23
+ | Moonshot / Kimi | `MOONSHOT_API_KEY` | `GET /v1/users/me/balance` | ✅ Direct query |
24
+ | MiniMax | `MINIMAX_API_KEY` | `GET /v1/token_plan/remains` | ✅ Direct query |
25
+ | StepFun | `STEP_API_KEY` | `GET /v1/accounts` | ✅ Direct query |
26
+ | Zhipu / GLM | `ZHIPU_API_KEY` | Quota API | ~ Quota info |
27
+ | DashScope / Qwen | `DASHSCOPE_API_KEY` | — | ⚠️ Console only |
28
+ | Baichuan | `BAICHUAN_API_KEY` | — | ⚠️ Console only |
29
+
30
+ ### International Region ($)
31
+
32
+ | Provider | API Key Env | Balance API | Status |
33
+ |----------|-------------|-------------|--------|
34
+ | OpenAI | `OPENAI_API_KEY` | Usage/Cost API | ~ Usage + cost |
35
+ | Anthropic / Claude | `ANTHROPIC_API_KEY` | Admin Key Cost API | ~ Usage + cost |
36
+ | xAI / Grok | `XAI_API_KEY` | Balance API | ✅ Direct query |
37
+ | Together AI | `TOGETHER_API_KEY` | Usage API | ~ Usage + cost |
38
+ | Mistral | `MISTRAL_API_KEY` | — | ⚠️ Console only |
39
+ | Groq | `GROQ_API_KEY` | — | ⚠️ Console only |
40
+ | Cohere | `COHERE_API_KEY` | — | ⚠️ Console only |
41
+
42
+ > **Note:** Cursor subscription balance is not supported as Cursor uses its own proxy and does not expose API keys.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install check-balance
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ### As CLI
53
+
54
+ ```bash
55
+ check-balance
56
+ # or
57
+ python -m check_balance
58
+ ```
59
+
60
+ ### As MCP Server
61
+
62
+ #### opencode
63
+
64
+ Add to your `opencode.json`:
65
+
66
+ ```json
67
+ {
68
+ "mcp": {
69
+ "check-balance": {
70
+ "type": "local",
71
+ "command": ["python", "-m", "check_balance.mcp_server"],
72
+ "enabled": true
73
+ }
74
+ }
75
+ }
76
+ ```
77
+
78
+ Then type `/balance` in opencode or ask "check my AI balance".
79
+
80
+ #### Claude Code
81
+
82
+ Create `.mcp.json` in your project root:
83
+
84
+ ```json
85
+ {
86
+ "mcpServers": {
87
+ "check-balance": {
88
+ "command": "python",
89
+ "args": ["-m", "check_balance.mcp_server"]
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ Or add to `~/.claude/mcp.json` for global access.
96
+
97
+ #### Cursor
98
+
99
+ Create `.cursor/mcp.json` in your project root:
100
+
101
+ ```json
102
+ {
103
+ "mcpServers": {
104
+ "check-balance": {
105
+ "command": "python",
106
+ "args": ["-m", "check_balance.mcp_server"]
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+ Or add to `~/.cursor/mcp.json` for global access.
113
+
114
+ #### Claude Desktop
115
+
116
+ Edit `claude_desktop_config.json`:
117
+
118
+ | OS | Path |
119
+ |----|------|
120
+ | macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
121
+ | Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
122
+ | Linux | `~/.config/Claude/claude_desktop_config.json` |
123
+
124
+ ```json
125
+ {
126
+ "mcpServers": {
127
+ "check-balance": {
128
+ "command": "python",
129
+ "args": ["-m", "check_balance.mcp_server"]
130
+ }
131
+ }
132
+ }
133
+ ```
134
+
135
+ ## How It Works
136
+
137
+ 1. **Auto-detection** — Reads `opencode.json` to identify your current model/provider, then scans environment variables for all configured API keys
138
+ 2. **Balance query** — Calls each provider's balance/usage API
139
+ 3. **Formatted output** — Shows results with ¥ (China) or $ (International) currency
140
+
141
+ ## Output Example
142
+
143
+ ```
144
+ AI 服务余额查询
145
+ ==================================================
146
+ * DeepSeek (中国)
147
+ 余额: ¥ 142.50
148
+
149
+ Moonshot (中国)
150
+ 余额: ¥ 3.00
151
+
152
+ OpenAI (海外)
153
+ OpenAI 未开放余额查询 API,近 30 天用量: $ 18.32
154
+ 控制台: https://platform.openai.com/usage
155
+
156
+ Mistral (海外)
157
+ 未开放余额查询 API
158
+ 控制台: https://console.mistral.ai/usage
159
+
160
+ * 标记为当前使用的服务
161
+ ```
162
+
163
+ ## Development
164
+
165
+ ```bash
166
+ git clone https://github.com/hanmumuHL/check_balance.git
167
+ cd check_balance
168
+ pip install -e ".[dev]"
169
+ pytest
170
+ ```
171
+
172
+ ## License
173
+
174
+ MIT
@@ -0,0 +1,174 @@
1
+ # check-balance
2
+
3
+ [English](README.md)
4
+
5
+ 一键查询当前 AI 服务的账户余额。支持 14 个主流 AI 提供商,自动检测,可作为 MCP Server 或独立 CLI 使用。
6
+
7
+ ## 特性
8
+
9
+ - **MCP Server** — 集成 opencode、Claude Code、Cursor、Claude Desktop
10
+ - **CLI 工具** — 终端直接运行 `check-balance`
11
+ - **自动检测** — 读取 opencode 配置和环境变量
12
+ - **14 个提供商** — 中国区(¥)和海外区($)
13
+ - **跨平台** — Linux、macOS、Windows(含 WSL)
14
+ - **零配置** — 设置 API Key 即可使用
15
+
16
+ ## 支持的提供商
17
+
18
+ ### 中国区(¥)
19
+
20
+ | 提供商 | 环境变量 | 余额 API | 状态 |
21
+ |--------|---------|---------|------|
22
+ | DeepSeek | `DEEPSEEK_API_KEY` | `GET /user/balance` | ✅ 直接查询 |
23
+ | Moonshot / Kimi | `MOONSHOT_API_KEY` | `GET /v1/users/me/balance` | ✅ 直接查询 |
24
+ | MiniMax | `MINIMAX_API_KEY` | `GET /v1/token_plan/remains` | ✅ 直接查询 |
25
+ | StepFun / 阶跃星辰 | `STEP_API_KEY` | `GET /v1/accounts` | ✅ 直接查询 |
26
+ | 智谱 / GLM | `ZHIPU_API_KEY` | 配额 API | ~ 配额信息 |
27
+ | 通义千问 / DashScope | `DASHSCOPE_API_KEY` | — | ⚠️ 仅控制台 |
28
+ | 百川 | `BAICHUAN_API_KEY` | — | ⚠️ 仅控制台 |
29
+
30
+ ### 海外区($)
31
+
32
+ | 提供商 | 环境变量 | 余额 API | 状态 |
33
+ |--------|---------|---------|------|
34
+ | OpenAI | `OPENAI_API_KEY` | 用量/费用 API | ~ 用量+费用 |
35
+ | Anthropic / Claude | `ANTHROPIC_API_KEY` | Admin Key 用量 API | ~ 用量+费用 |
36
+ | xAI / Grok | `XAI_API_KEY` | 余额 API | ✅ 直接查询 |
37
+ | Together AI | `TOGETHER_API_KEY` | 用量 API | ~ 用量+费用 |
38
+ | Mistral | `MISTRAL_API_KEY` | — | ⚠️ 仅控制台 |
39
+ | Groq | `GROQ_API_KEY` | — | ⚠️ 仅控制台 |
40
+ | Cohere | `COHERE_API_KEY` | — | ⚠️ 仅控制台 |
41
+
42
+ > **注意:** Cursor 订阅余额不支持查询,因为 Cursor 使用自己的代理,不暴露 API Key。
43
+
44
+ ## 安装
45
+
46
+ ```bash
47
+ pip install check-balance
48
+ ```
49
+
50
+ ## 使用方法
51
+
52
+ ### CLI 模式
53
+
54
+ ```bash
55
+ check-balance
56
+ # 或
57
+ python -m check_balance
58
+ ```
59
+
60
+ ### MCP Server 模式
61
+
62
+ #### opencode
63
+
64
+ 在 `opencode.json` 中添加:
65
+
66
+ ```json
67
+ {
68
+ "mcp": {
69
+ "check-balance": {
70
+ "type": "local",
71
+ "command": ["python", "-m", "check_balance.mcp_server"],
72
+ "enabled": true
73
+ }
74
+ }
75
+ }
76
+ ```
77
+
78
+ 然后在 opencode 中输入 `/balance` 或说 "查一下余额"。
79
+
80
+ #### Claude Code
81
+
82
+ 在项目根目录创建 `.mcp.json`:
83
+
84
+ ```json
85
+ {
86
+ "mcpServers": {
87
+ "check-balance": {
88
+ "command": "python",
89
+ "args": ["-m", "check_balance.mcp_server"]
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ 或添加到 `~/.claude/mcp.json` 全局使用。
96
+
97
+ #### Cursor
98
+
99
+ 在项目根目录创建 `.cursor/mcp.json`:
100
+
101
+ ```json
102
+ {
103
+ "mcpServers": {
104
+ "check-balance": {
105
+ "command": "python",
106
+ "args": ["-m", "check_balance.mcp_server"]
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+ 或添加到 `~/.cursor/mcp.json` 全局使用。
113
+
114
+ #### Claude Desktop
115
+
116
+ 编辑 `claude_desktop_config.json`:
117
+
118
+ | 系统 | 路径 |
119
+ |------|------|
120
+ | macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
121
+ | Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
122
+ | Linux | `~/.config/Claude/claude_desktop_config.json` |
123
+
124
+ ```json
125
+ {
126
+ "mcpServers": {
127
+ "check-balance": {
128
+ "command": "python",
129
+ "args": ["-m", "check_balance.mcp_server"]
130
+ }
131
+ }
132
+ }
133
+ ```
134
+
135
+ ## 工作原理
136
+
137
+ 1. **自动检测** — 读取 `opencode.json` 识别当前使用的模型/提供商,扫描环境变量获取所有已配置的 API Key
138
+ 2. **余额查询** — 调用各提供商的余额/用量 API
139
+ 3. **格式化输出** — 中国区显示 ¥,海外区显示 $
140
+
141
+ ## 输出示例
142
+
143
+ ```
144
+ AI 服务余额查询
145
+ ==================================================
146
+ * DeepSeek (中国)
147
+ 余额: ¥ 142.50
148
+
149
+ Moonshot (中国)
150
+ 余额: ¥ 3.00
151
+
152
+ OpenAI (海外)
153
+ OpenAI 未开放余额查询 API,近 30 天用量: $ 18.32
154
+ 控制台: https://platform.openai.com/usage
155
+
156
+ Mistral (海外)
157
+ 未开放余额查询 API
158
+ 控制台: https://console.mistral.ai/usage
159
+
160
+ * 标记为当前使用的服务
161
+ ```
162
+
163
+ ## 开发
164
+
165
+ ```bash
166
+ git clone https://github.com/hanmumuHL/check_balance.git
167
+ cd check_balance
168
+ pip install -e ".[dev]"
169
+ pytest
170
+ ```
171
+
172
+ ## 许可
173
+
174
+ MIT
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ from check_balance.main import main
2
+
3
+ if __name__ == "__main__":
4
+ main()