cometapi-cli 0.2.0__tar.gz → 0.2.2__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 (74) hide show
  1. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/AGENTS.md +5 -5
  2. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/CHANGELOG.md +15 -0
  3. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/PKG-INFO +6 -10
  4. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/README.md +5 -9
  5. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/authentication.md +1 -1
  6. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/balance.md +6 -6
  7. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/models.md +1 -2
  8. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/pyproject.toml +1 -1
  9. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/skills/live-test/SKILL.md +3 -3
  10. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/__init__.py +1 -1
  11. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/balance.py +26 -4
  12. cometapi_cli-0.2.2/src/cometapi_cli/commands/models.py +95 -0
  13. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_balance.py +21 -4
  14. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_models.py +15 -4
  15. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/uv.lock +1 -1
  16. cometapi_cli-0.2.0/src/cometapi_cli/commands/models.py +0 -44
  17. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  18. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  19. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  20. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/.github/workflows/ci.yml +0 -0
  21. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/.github/workflows/publish.yml +0 -0
  22. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/.gitignore +0 -0
  23. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/CODE_OF_CONDUCT.md +0 -0
  24. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/CONTRIBUTING.md +0 -0
  25. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/LICENSE +0 -0
  26. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/SECURITY.md +0 -0
  27. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/SKILL.md +0 -0
  28. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/README.md +0 -0
  29. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/account.md +0 -0
  30. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/chat.md +0 -0
  31. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/config.md +0 -0
  32. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/doctor.md +0 -0
  33. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/init.md +0 -0
  34. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/logs.md +0 -0
  35. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/repl.md +0 -0
  36. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/stats.md +0 -0
  37. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/tasks.md +0 -0
  38. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/commands/tokens.md +0 -0
  39. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/configuration.md +0 -0
  40. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/errors.md +0 -0
  41. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/installation.md +0 -0
  42. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/docs/output-formats.md +0 -0
  43. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/app.py +0 -0
  44. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/client.py +0 -0
  45. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/__init__.py +0 -0
  46. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/account.py +0 -0
  47. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/chat.py +0 -0
  48. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/chat_repl.py +0 -0
  49. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/config_cmd.py +0 -0
  50. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/doctor.py +0 -0
  51. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/logs.py +0 -0
  52. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/repl.py +0 -0
  53. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/stats.py +0 -0
  54. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/tasks.py +0 -0
  55. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/commands/tokens.py +0 -0
  56. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/config.py +0 -0
  57. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/console.py +0 -0
  58. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/constants.py +0 -0
  59. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/errors.py +0 -0
  60. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/formatters.py +0 -0
  61. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/src/cometapi_cli/main.py +0 -0
  62. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/__init__.py +0 -0
  63. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/conftest.py +0 -0
  64. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_account.py +0 -0
  65. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_chat.py +0 -0
  66. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_config.py +0 -0
  67. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_doctor.py +0 -0
  68. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_errors.py +0 -0
  69. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_formatters.py +0 -0
  70. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_help.py +0 -0
  71. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_logs.py +0 -0
  72. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_stats.py +0 -0
  73. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_tasks.py +0 -0
  74. {cometapi_cli-0.2.0 → cometapi_cli-0.2.2}/tests/test_tokens.py +0 -0
@@ -189,9 +189,9 @@ These options apply to **every** command via the root Typer callback.
189
189
  | `--format` | `-f` | `OutputFormat` | inherits global | Per-command output format override |
190
190
  | `--json` | — | flag | `false` | Output as JSON |
191
191
 
192
- **Behavior:** Fetches all models via `client.models.list()`, sorts alphabetically by `id`, applies `--search` filter, then `--limit` truncation.
192
+ **Behavior:** Fetches all models via `client.models.list()`, applies `--search`, sorts model IDs in descending natural/version-aware order so newer variants surface first, then applies `--limit`.
193
193
 
194
- **Table columns:** `id` (cyan), `owned_by` (green).
194
+ **Table columns:** `id` (cyan).
195
195
 
196
196
  ---
197
197
 
@@ -201,13 +201,13 @@ These options apply to **every** command via the root Typer callback.
201
201
 
202
202
  | Parameter | Alias | Type | Default | Description |
203
203
  |-----------|-------|------|---------|-------------|
204
- | `--source` | `-s` | `str` (`account` or `token`) | `None` (auto-detect) | Force data source: `account` = full account balance via `/api/user/self`; `token` = per-API-key billing via `/v1/dashboard/billing/*` |
204
+ | `--source` | `-s` | `str` (`account` or `key`) | `None` (auto-detect) | Force data source: `account` = full account balance via `/api/user/self`; `key` = per-API-key billing via `/v1/dashboard/billing/*` |
205
205
  | `--format` | `-f` | `OutputFormat` | inherits global | Per-command output format override |
206
206
  | `--json` | — | flag | `false` | Output raw balance dict as JSON |
207
207
 
208
208
  **Auto-detection logic** (when `--source` is omitted):
209
209
  1. If `COMETAPI_ACCESS_TOKEN` is available → uses `account` source.
210
- 2. Otherwise → falls back to `token` (per-key billing) source.
210
+ 2. Otherwise → falls back to `key` (per-key billing) source.
211
211
 
212
212
  **Display — `account` source:**
213
213
  | Field | Description |
@@ -216,7 +216,7 @@ These options apply to **every** command via the root Typer callback.
216
216
  | Used | Total amount consumed (USD) |
217
217
  | Total Topped Up | Lifetime top-up amount (USD) |
218
218
 
219
- **Display — `token` (billing) source:**
219
+ **Display — `key` (billing) source:**
220
220
  | Field | Description |
221
221
  |-------|-------------|
222
222
  | Limit | Spending cap (`Unlimited` if no cap set) |
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.2] — 2026-04-14
9
+
10
+ ### Changed
11
+
12
+ - `balance --source` now uses `key` for the API-key billing view so the CLI terminology matches `api_key` and `access_token`.
13
+ - `balance --source token` is still accepted as a compatibility alias and is normalized to the same API-key billing behavior.
14
+
15
+ ## [0.2.1] — 2026-04-14
16
+
17
+ ### Changed
18
+
19
+ - `models` now sorts model IDs in descending natural/version-aware order so newer GPT variants appear first in filtered output.
20
+ - `models` output now only includes the model `id`; the unrelated `owned_by` field is no longer shown in table, JSON, YAML, CSV, or Markdown output.
21
+ - README links were cleaned up for the next PyPI publish: duplicate License heading removed, homepage link kept on `www`, and tracked credential links use UTM parameters.
22
+
8
23
  ## [0.2.0] — 2026-04-13
9
24
 
10
25
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cometapi-cli
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: CometAPI CLI — official command-line interface for the CometAPI AI gateway
5
5
  Project-URL: Homepage, https://github.com/cometapi-dev/cometapi-cli
6
6
  Project-URL: Repository, https://github.com/cometapi-dev/cometapi-cli
@@ -42,7 +42,7 @@ Description-Content-Type: text/markdown
42
42
  [![Python](https://img.shields.io/pypi/pyversions/cometapi-cli)](https://pypi.org/project/cometapi-cli/)
43
43
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
44
44
 
45
- > **Official command-line interface for [CometAPI](https://cometapi.com)** — 500+ AI Model API, All In One API.
45
+ > **Official command-line interface for [CometAPI](https://www.cometapi.com/?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=homepage)** — 500+ AI Model API, All In One API.
46
46
 
47
47
  Access 500+ AI models at low cost, directly from the terminal. Chat, search models, check usage, and manage your account — all through a single API key.
48
48
 
@@ -59,7 +59,7 @@ pipx install cometapi-cli # isolated environment
59
59
  uv tool install cometapi-cli # uv
60
60
  ```
61
61
 
62
- **Prerequisites**: Python 3.10+ · [Get your API key](https://www.cometapi.com/console/token)
62
+ **Prerequisites**: Python 3.10+ · [CometAPI Key](https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=prerequisites)
63
63
 
64
64
  ## Quick Start
65
65
 
@@ -77,8 +77,8 @@ cometapi models --search gpt --limit 10
77
77
  Or configure manually:
78
78
 
79
79
  ```bash
80
- export COMETAPI_KEY="your-api-key" # https://www.cometapi.com/console/token
81
- export COMETAPI_ACCESS_TOKEN="your-access-token" # https://www.cometapi.com/console/personal (optional)
80
+ export COMETAPI_KEY="your-api-key" # https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=env-api-key
81
+ export COMETAPI_ACCESS_TOKEN="your-access-token" # https://www.cometapi.com/console/personal?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=env-access-token (optional)
82
82
  ```
83
83
 
84
84
  ## Commands
@@ -226,7 +226,7 @@ pytest -v
226
226
  - API keys and access tokens are **never** logged or displayed in full — only the last 4 characters are shown
227
227
  - Config files are stored with restrictive permissions (`0600`)
228
228
  - Credentials should **never** be committed to version control
229
- - Create credentials at: [API Key](https://www.cometapi.com/console/token) · [Access Token](https://www.cometapi.com/console/personal)
229
+ - Create credentials at: [API Key](https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=security-api-key) · [Access Token](https://www.cometapi.com/console/personal?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=security-access-token)
230
230
  - **Disclaimer**: You are responsible for all usage and charges incurred with your API keys
231
231
 
232
232
  ## Troubleshooting
@@ -244,7 +244,3 @@ Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines
244
244
  ## License
245
245
 
246
246
  This project is licensed under the [MIT License](LICENSE).
247
-
248
- ## License
249
-
250
- MIT
@@ -4,7 +4,7 @@
4
4
  [![Python](https://img.shields.io/pypi/pyversions/cometapi-cli)](https://pypi.org/project/cometapi-cli/)
5
5
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
6
 
7
- > **Official command-line interface for [CometAPI](https://cometapi.com)** — 500+ AI Model API, All In One API.
7
+ > **Official command-line interface for [CometAPI](https://www.cometapi.com/?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=homepage)** — 500+ AI Model API, All In One API.
8
8
 
9
9
  Access 500+ AI models at low cost, directly from the terminal. Chat, search models, check usage, and manage your account — all through a single API key.
10
10
 
@@ -21,7 +21,7 @@ pipx install cometapi-cli # isolated environment
21
21
  uv tool install cometapi-cli # uv
22
22
  ```
23
23
 
24
- **Prerequisites**: Python 3.10+ · [Get your API key](https://www.cometapi.com/console/token)
24
+ **Prerequisites**: Python 3.10+ · [CometAPI Key](https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=prerequisites)
25
25
 
26
26
  ## Quick Start
27
27
 
@@ -39,8 +39,8 @@ cometapi models --search gpt --limit 10
39
39
  Or configure manually:
40
40
 
41
41
  ```bash
42
- export COMETAPI_KEY="your-api-key" # https://www.cometapi.com/console/token
43
- export COMETAPI_ACCESS_TOKEN="your-access-token" # https://www.cometapi.com/console/personal (optional)
42
+ export COMETAPI_KEY="your-api-key" # https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=env-api-key
43
+ export COMETAPI_ACCESS_TOKEN="your-access-token" # https://www.cometapi.com/console/personal?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=env-access-token (optional)
44
44
  ```
45
45
 
46
46
  ## Commands
@@ -188,7 +188,7 @@ pytest -v
188
188
  - API keys and access tokens are **never** logged or displayed in full — only the last 4 characters are shown
189
189
  - Config files are stored with restrictive permissions (`0600`)
190
190
  - Credentials should **never** be committed to version control
191
- - Create credentials at: [API Key](https://www.cometapi.com/console/token) · [Access Token](https://www.cometapi.com/console/personal)
191
+ - Create credentials at: [API Key](https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=security-api-key) · [Access Token](https://www.cometapi.com/console/personal?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=security-access-token)
192
192
  - **Disclaimer**: You are responsible for all usage and charges incurred with your API keys
193
193
 
194
194
  ## Troubleshooting
@@ -206,7 +206,3 @@ Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines
206
206
  ## License
207
207
 
208
208
  This project is licensed under the [MIT License](LICENSE).
209
-
210
- ## License
211
-
212
- MIT
@@ -9,7 +9,7 @@ Used for **AI relay endpoints** — the core API functionality:
9
9
  - `chat` — chat completions
10
10
  - `models` — list available models
11
11
  - `doctor` — connectivity check
12
- - `balance` — per-token billing stats (fallback mode)
12
+ - `balance` — per-key billing stats (fallback mode)
13
13
 
14
14
  **How to get one**: [https://www.cometapi.com/console/token](https://www.cometapi.com/console/token)
15
15
 
@@ -10,7 +10,7 @@ cometapi balance [OPTIONS]
10
10
 
11
11
  | Option | Alias | Type | Default | Description |
12
12
  |--------|-------|------|---------|-------------|
13
- | `--source` | `-s` | string | — | Data source: `account` (full account) or `token` (current API key) |
13
+ | `--source` | `-s` | string | — | Data source: `account` (full account) or `key` (current API key) |
14
14
  | `--format` | `-f` | choice | `table` | Output format: `table`, `json`, `yaml`, `csv`, `markdown` |
15
15
  | `--json` | — | flag | `false` | Output as JSON |
16
16
  | `--help` | `-h` | flag | — | Show help |
@@ -21,7 +21,7 @@ Requires `COMETAPI_KEY`. Access token is optional but provides richer data.
21
21
 
22
22
  ## Behavior
23
23
 
24
- By default, the command shows account-level balance if an access token is available, falling back to per-token billing stats from the API key. Use `--source` to force a specific view.
24
+ By default, the command shows account-level balance if an access token is available, falling back to per-key billing stats from the API key. Use `--source` to force a specific view.
25
25
 
26
26
  ### Source: `account` (access token required)
27
27
 
@@ -33,9 +33,9 @@ Shows full account balance:
33
33
  | `used` | Total amount consumed in USD |
34
34
  | `total_topped_up` | Total amount added to the account in USD |
35
35
 
36
- ### Source: `token` (API key only)
36
+ ### Source: `key` (API key only)
37
37
 
38
- Shows per-token billing stats:
38
+ Shows per-key billing stats:
39
39
 
40
40
  | Field | Description |
41
41
  |-------|-------------|
@@ -59,8 +59,8 @@ cometapi balance
59
59
  # Force account-level balance
60
60
  cometapi balance --source account
61
61
 
62
- # Force per-token billing stats
63
- cometapi balance --source token
62
+ # Force per-key billing stats
63
+ cometapi balance --source key
64
64
 
65
65
  # JSON output for scripting
66
66
  cometapi balance --json
@@ -22,7 +22,7 @@ Requires `COMETAPI_KEY`. Access token is not needed.
22
22
 
23
23
  ## Behavior
24
24
 
25
- - Results are sorted alphabetically by model ID.
25
+ - Results are sorted in descending natural/version-aware order so newer model IDs surface first.
26
26
  - `--search` performs a case-insensitive substring match on the model `id` field.
27
27
  - `--limit` is applied after filtering and sorting.
28
28
 
@@ -31,7 +31,6 @@ Requires `COMETAPI_KEY`. Access token is not needed.
31
31
  | Column | Description |
32
32
  |--------|-------------|
33
33
  | `id` | Model identifier (e.g., `gpt-5.4`, `claude-sonnet-4-6`) |
34
- | `owned_by` | Model provider (e.g., `openai`, `anthropic`) |
35
34
 
36
35
  ## Examples
37
36
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cometapi-cli"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "CometAPI CLI — official command-line interface for the CometAPI AI gateway"
5
5
  readme = "README.md"
6
6
  license = { text = "MIT" }
@@ -134,14 +134,14 @@ uv run cometapi models --format yaml --limit 3
134
134
 
135
135
  ```bash
136
136
  uv run cometapi balance
137
- uv run cometapi balance --source token
137
+ uv run cometapi balance --source key
138
138
  uv run cometapi balance --source account
139
139
  uv run cometapi balance --json
140
140
  ```
141
141
 
142
142
  **Verify:**
143
143
  - Default: shows "Available Balance", "Used", "Total Topped Up" (account source, if access token available).
144
- - `--source token`: shows "Limit" (may be "Unlimited") and "Used".
144
+ - `--source key`: shows "Limit" (may be "Unlimited") and "Used".
145
145
  - `--source account`: same as default account view.
146
146
  - `--json`: outputs valid JSON with `balance`, `used`, `total_topped_up`, `source` fields.
147
147
 
@@ -330,7 +330,7 @@ uv run cometapi --version
330
330
  uv run cometapi -h
331
331
  uv run cometapi models --limit 3 --json
332
332
  uv run cometapi balance
333
- uv run cometapi balance --source token
333
+ uv run cometapi balance --source key
334
334
  uv run cometapi chat "ping" --json
335
335
  uv run cometapi account --json
336
336
  uv run cometapi tokens --limit 3 --json
@@ -1,3 +1,3 @@
1
1
  """CometAPI CLI — professional terminal interface for CometAPI."""
2
2
 
3
- __version__ = "0.2.0"
3
+ __version__ = "0.2.2"
@@ -7,28 +7,50 @@ from typing import Annotated
7
7
  import typer
8
8
 
9
9
  from ..config import get_client
10
+ from ..console import err_console
10
11
  from ..errors import handle_errors
11
12
  from ..formatters import OutputFormat, output, resolve_format
12
13
 
14
+ BALANCE_SOURCE_ALIASES = {
15
+ "account": "account",
16
+ "key": "key",
17
+ "token": "key",
18
+ }
19
+
20
+
21
+ def _normalize_balance_source(source: str | None) -> str | None:
22
+ if source is None:
23
+ return None
24
+
25
+ normalized = BALANCE_SOURCE_ALIASES.get(source.lower())
26
+ if normalized is not None:
27
+ return normalized
28
+
29
+ err_console.print(f"[red]Invalid source:[/] {source}. Valid sources: account, key")
30
+ raise typer.Exit(code=2)
31
+
13
32
 
14
33
  @handle_errors
15
34
  def balance(
16
35
  ctx: typer.Context,
17
36
  source: Annotated[
18
37
  str | None,
19
- typer.Option("--source", "-s", help="Data source: 'account' (full account) or 'token' (current API key)."),
38
+ typer.Option("--source", "-s", help="Data source: 'account' (full account) or 'key' (current API key)."),
39
+ ] = None,
40
+ output_format: Annotated[
41
+ OutputFormat | None,
42
+ typer.Option("--format", "-f", help="Output format (table, json, yaml, csv, markdown)."),
20
43
  ] = None,
21
- output_format: Annotated[OutputFormat | None, typer.Option("--format", "-f", help="Output format (table, json, yaml, csv, markdown).")] = None,
22
44
  json_output: Annotated[bool, typer.Option("--json", help="Output as JSON.")] = False,
23
45
  ) -> None:
24
46
  """Show your CometAPI account balance.
25
47
 
26
48
  By default shows account-level balance (requires access token), falling back
27
- to per-token billing stats. Use --source to force a specific view.
49
+ to per-key billing stats. Use --source to force a specific view.
28
50
  """
29
51
  fmt = resolve_format(ctx, json_output, output_format)
30
52
  client = get_client()
31
- raw = client.get_balance(source=source)
53
+ raw = client.get_balance(source=_normalize_balance_source(source))
32
54
 
33
55
  # For JSON output, pass raw data for maximum information
34
56
  if fmt == OutputFormat.JSON:
@@ -0,0 +1,95 @@
1
+ """Models command."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from functools import cmp_to_key
7
+ from typing import Annotated
8
+
9
+ import typer
10
+
11
+ from ..config import get_client
12
+ from ..errors import handle_errors
13
+ from ..formatters import OutputFormat, output, resolve_format
14
+
15
+ _MODEL_TOKEN_RE = re.compile(r"[a-z]+|\d+")
16
+
17
+
18
+ def _tokenize_model_id(model_id: str) -> list[str | int]:
19
+ tokens: list[str | int] = []
20
+ for segment in re.split(r"[-.]+", model_id.lower()):
21
+ if not segment:
22
+ continue
23
+ for part in _MODEL_TOKEN_RE.findall(segment):
24
+ tokens.append(int(part) if part.isdigit() else part)
25
+ return tokens
26
+
27
+
28
+ def _compare_model_ids(left: str, right: str) -> int:
29
+ left_tokens = _tokenize_model_id(left)
30
+ right_tokens = _tokenize_model_id(right)
31
+
32
+ for left_token, right_token in zip(left_tokens, right_tokens):
33
+ if left_token == right_token:
34
+ continue
35
+
36
+ if isinstance(left_token, int) and isinstance(right_token, int):
37
+ return -1 if left_token > right_token else 1
38
+
39
+ if isinstance(left_token, int):
40
+ return -1
41
+ if isinstance(right_token, int):
42
+ return 1
43
+
44
+ return -1 if left_token > right_token else 1
45
+
46
+ if len(left_tokens) == len(right_tokens):
47
+ if left.lower() == right.lower():
48
+ return 0
49
+ return -1 if left.lower() > right.lower() else 1
50
+
51
+ if len(left_tokens) < len(right_tokens):
52
+ next_token = right_tokens[len(left_tokens)]
53
+ return 1 if isinstance(next_token, int) else -1
54
+
55
+ next_token = left_tokens[len(right_tokens)]
56
+ return -1 if isinstance(next_token, int) else 1
57
+
58
+
59
+ def _compare_model_rows(left: dict[str, str], right: dict[str, str]) -> int:
60
+ return _compare_model_ids(left["id"], right["id"])
61
+
62
+
63
+ @handle_errors
64
+ def models(
65
+ ctx: typer.Context,
66
+ search: Annotated[str | None, typer.Option("--search", "-s", help="Filter models by name.")] = None,
67
+ limit: Annotated[int | None, typer.Option("--limit", "-l", help="Max number of models to show.")] = None,
68
+ output_format: Annotated[
69
+ OutputFormat | None,
70
+ typer.Option("--format", "-f", help="Output format (table, json, yaml, csv, markdown)."),
71
+ ] = None,
72
+ json_output: Annotated[bool, typer.Option("--json", help="Output as JSON.")] = False,
73
+ ) -> None:
74
+ """List available models."""
75
+ fmt = resolve_format(ctx, json_output, output_format)
76
+ client = get_client()
77
+ result = client.models.list()
78
+
79
+ rows = [{"id": m.id} for m in result]
80
+
81
+ if search:
82
+ term = search.lower()
83
+ rows = [r for r in rows if term in r["id"].lower()]
84
+
85
+ rows = sorted(rows, key=cmp_to_key(_compare_model_rows))
86
+
87
+ if limit and limit > 0:
88
+ rows = rows[:limit]
89
+
90
+ output(
91
+ rows,
92
+ fmt,
93
+ title=f"Available Models ({len(rows)})",
94
+ columns={"id": "cyan"},
95
+ )
@@ -22,8 +22,8 @@ def test_balance_table(cli_runner, patched_client):
22
22
  assert "$3,305.90" in result.output
23
23
 
24
24
 
25
- def test_balance_source_token(cli_runner, patched_client):
26
- """Test --source token shows billing view."""
25
+ def test_balance_source_key(cli_runner, patched_client):
26
+ """Test --source key shows billing view."""
27
27
  patched_client.get_balance.return_value = {
28
28
  "balance": -1,
29
29
  "used": 280.05,
@@ -31,11 +31,18 @@ def test_balance_source_token(cli_runner, patched_client):
31
31
  "currency": "USD",
32
32
  "source": "billing",
33
33
  }
34
- result = cli_runner("balance", "--source", "token")
34
+ result = cli_runner("balance", "--source", "key")
35
35
  assert result.exit_code == 0
36
36
  assert "Unlimited" in result.output
37
37
  assert "$280.05" in result.output
38
- patched_client.get_balance.assert_called_with(source="token")
38
+ patched_client.get_balance.assert_called_with(source="key")
39
+
40
+
41
+ def test_balance_source_token_alias(cli_runner, patched_client):
42
+ """Test deprecated --source token still maps to API-key billing view."""
43
+ result = cli_runner("balance", "--source", "token")
44
+ assert result.exit_code == 0
45
+ patched_client.get_balance.assert_called_with(source="key")
39
46
 
40
47
 
41
48
  def test_balance_source_account(cli_runner, patched_client):
@@ -50,4 +57,14 @@ def test_balance_help(cli_runner):
50
57
  result = cli_runner("balance", "-h")
51
58
  assert result.exit_code == 0
52
59
  assert "--source" in result.output
60
+ assert "Data source:" in result.output
61
+ assert "'key'" in result.output
62
+ assert "API key" in result.output
63
+ assert "'token'" not in result.output
53
64
  assert "--json" in result.output
65
+
66
+
67
+ def test_balance_source_invalid(cli_runner):
68
+ result = cli_runner("balance", "--source", "billing")
69
+ assert result.exit_code == 2
70
+ assert "Valid sources: account, key" in result.output
@@ -4,20 +4,21 @@ from __future__ import annotations
4
4
 
5
5
  import json
6
6
 
7
+ from tests.conftest import _make_models_response
8
+
7
9
 
8
10
  def test_models_json(cli_runner, patched_client):
9
11
  result = cli_runner("models", "--json")
10
12
  assert result.exit_code == 0
11
13
  data = json.loads(result.output)
12
- assert isinstance(data, list)
13
- assert len(data) == 3
14
- assert data[0]["id"] == "claude-sonnet-4-6" # sorted alphabetically
14
+ assert data == [{"id": "gpt-5.4"}, {"id": "gpt-5.4-mini"}, {"id": "claude-sonnet-4-6"}]
15
15
 
16
16
 
17
17
  def test_models_table(cli_runner, patched_client):
18
18
  result = cli_runner("models")
19
19
  assert result.exit_code == 0
20
20
  assert "gpt-5.4" in result.output
21
+ assert "Owned By" not in result.output
21
22
 
22
23
 
23
24
  def test_models_search(cli_runner, patched_client):
@@ -27,6 +28,16 @@ def test_models_search(cli_runner, patched_client):
27
28
  assert all("gpt" in m["id"] for m in data)
28
29
 
29
30
 
31
+ def test_models_search_prioritizes_newest_versions(cli_runner, patched_client):
32
+ patched_client.models.list.return_value = _make_models_response(
33
+ ["gpt-3.5-turbo", "gpt-5-mini", "gpt-5", "gpt-5.4-mini", "gpt-4.1", "gpt-5.4"]
34
+ )
35
+ result = cli_runner("models", "--search", "gpt", "--limit", "5", "--json")
36
+ assert result.exit_code == 0
37
+ data = json.loads(result.output)
38
+ assert [model["id"] for model in data] == ["gpt-5.4", "gpt-5.4-mini", "gpt-5", "gpt-5-mini", "gpt-4.1"]
39
+
40
+
30
41
  def test_models_limit(cli_runner, patched_client):
31
42
  result = cli_runner("models", "--limit", "1", "--json")
32
43
  assert result.exit_code == 0
@@ -43,4 +54,4 @@ def test_models_yaml(cli_runner, patched_client):
43
54
  def test_models_csv(cli_runner, patched_client):
44
55
  result = cli_runner("--format", "csv", "models")
45
56
  assert result.exit_code == 0
46
- assert "id,owned_by" in result.output
57
+ assert result.output.splitlines()[0] == "id"
@@ -66,7 +66,7 @@ wheels = [
66
66
 
67
67
  [[package]]
68
68
  name = "cometapi-cli"
69
- version = "0.1.0"
69
+ version = "0.2.2"
70
70
  source = { editable = "." }
71
71
  dependencies = [
72
72
  { name = "openai" },
@@ -1,44 +0,0 @@
1
- """Models command."""
2
-
3
- from __future__ import annotations
4
-
5
- from typing import Annotated
6
-
7
- import typer
8
-
9
- from ..config import get_client
10
- from ..errors import handle_errors
11
- from ..formatters import OutputFormat, output, resolve_format
12
-
13
-
14
- @handle_errors
15
- def models(
16
- ctx: typer.Context,
17
- search: Annotated[str | None, typer.Option("--search", "-s", help="Filter models by name.")] = None,
18
- limit: Annotated[int | None, typer.Option("--limit", "-l", help="Max number of models to show.")] = None,
19
- output_format: Annotated[OutputFormat | None, typer.Option("--format", "-f", help="Output format (table, json, yaml, csv, markdown).")] = None,
20
- json_output: Annotated[bool, typer.Option("--json", help="Output as JSON.")] = False,
21
- ) -> None:
22
- """List available models."""
23
- fmt = resolve_format(ctx, json_output, output_format)
24
- client = get_client()
25
- result = client.models.list()
26
-
27
- rows = sorted(
28
- [{"id": m.id, "owned_by": m.owned_by} for m in result],
29
- key=lambda r: r["id"],
30
- )
31
-
32
- if search:
33
- term = search.lower()
34
- rows = [r for r in rows if term in r["id"].lower()]
35
-
36
- if limit and limit > 0:
37
- rows = rows[:limit]
38
-
39
- output(
40
- rows,
41
- fmt,
42
- title=f"Available Models ({len(rows)})",
43
- columns={"id": "cyan", "owned_by": "green"},
44
- )
File without changes
File without changes
File without changes
File without changes