cometapi-cli 0.3.0__tar.gz → 0.3.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.
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/AGENTS.md +3 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/CHANGELOG.md +26 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/PKG-INFO +17 -1
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/README.md +15 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/logs.md +86 -14
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/pyproject.toml +2 -1
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/__init__.py +1 -1
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/client.py +15 -1
- cometapi_cli-0.3.2/src/cometapi_cli/commands/logs.py +436 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/constants.py +7 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/conftest.py +9 -2
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_help.py +36 -11
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_logs.py +88 -8
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/uv.lock +3 -1
- cometapi_cli-0.3.0/src/cometapi_cli/commands/logs.py +0 -300
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/.github/workflows/ci.yml +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/.github/workflows/publish.yml +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/.gitignore +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/CODE_OF_CONDUCT.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/CONTRIBUTING.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/LICENSE +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/SECURITY.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/SKILL.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/README.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/authentication.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/account.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/balance.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/chat.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/config.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/doctor.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/init.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/model.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/models.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/repl.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/run.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/stats.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/tasks.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/commands/tokens.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/configuration.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/errors.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/installation.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/docs/output-formats.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/skills/live-test/SKILL.md +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/app.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/catalog.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/__init__.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/account.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/balance.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/chat.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/chat_repl.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/config_cmd.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/doctor.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/model.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/models.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/repl.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/run.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/stats.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/tasks.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/commands/tokens.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/config.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/console.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/errors.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/formatters.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/main.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/src/cometapi_cli/urls.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/__init__.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_account.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_balance.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_catalog.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_chat.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_config.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_doctor.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_errors.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_formatters.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_model_info.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_models.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_run.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_stats.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_tasks.py +0 -0
- {cometapi_cli-0.3.0 → cometapi_cli-0.3.2}/tests/test_tokens.py +0 -0
|
@@ -353,6 +353,8 @@ These options apply to **every** command via the root Typer callback.
|
|
|
353
353
|
| `--start` | — | `str` | `None` | Start date (`YYYY-MM-DD`, ISO 8601, or Unix timestamp) |
|
|
354
354
|
| `--end` | — | `str` | `None` | End date (`YYYY-MM-DD`, ISO 8601, or Unix timestamp) |
|
|
355
355
|
| `--group` | `-g` | `str` | `None` | Filter by API key group |
|
|
356
|
+
| `--request-id` | — | `str` | `None` | Look up one request by `X-Cometapi-Request-Id` |
|
|
357
|
+
| `--request-id-max-pages` | — | `int` | `10` | Fallback pages to scan when direct request-ID lookup is unavailable |
|
|
356
358
|
| `--page` | `-p` | `int` | `1` | Page number |
|
|
357
359
|
| `--limit` | `-l` | `int` | `20` | Results per page |
|
|
358
360
|
| `--export` | — | flag | `false` | Export logs as server-side CSV to stdout |
|
|
@@ -375,6 +377,7 @@ Invalid `--type` values produce an error message with valid options and exit cod
|
|
|
375
377
|
|
|
376
378
|
**Behavior:**
|
|
377
379
|
- Without `--search` or `--export`: calls `client.list_logs(page=, page_size=, log_type=, model_name=, token_name=, start_timestamp=, end_timestamp=, group=)` — paginated, `data.items`.
|
|
380
|
+
- With `--request-id`: first calls `client.list_logs(..., request_id=)` and verifies an exact match. If the backend ignores `request_id`, falls back to scanning up to `--request-id-max-pages` pages; timestamp-shaped CometAPI request IDs are narrowed to the inferred local request day unless `--start`/`--end` were provided.
|
|
378
381
|
- With `--search`: calls `client.search_logs(keyword=)` — flat `data` list, ignores other filter flags.
|
|
379
382
|
- With `--export`: calls `client.export_logs(...)` — writes server-side CSV bytes to stdout. Honors `--model`, `--token-name`, `--type`, `--start`, `--end`, `--group`. Pipe-friendly (no Rich formatting).
|
|
380
383
|
|
|
@@ -5,6 +5,32 @@ 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.3.2] — 2026-06-17
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- `logs --request-id` now tries a direct request-ID lookup before falling back to paginated scanning. This avoids treating a precise lookup as an unbounded recent-log scan when the backend supports `request_id` filtering.
|
|
13
|
+
- `logs --request-id` fallback now narrows timestamp-shaped CometAPI request IDs to their inferred local request day, reducing slow scans on large log histories.
|
|
14
|
+
- Account-management requests now use bounded timeouts, so slow log pages fail promptly instead of appearing to hang for several minutes.
|
|
15
|
+
- Missing request-ID messages now explain the direct lookup and bounded fallback scan instead of implying only that the entry is older than the search window.
|
|
16
|
+
- Packaged installs now declare the CLI's direct `click` dependency instead of relying on Typer's transitive dependency metadata.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- `logs --request-id-max-pages` controls how many fallback pages are scanned when direct request-ID lookup is unavailable.
|
|
21
|
+
|
|
22
|
+
## [0.3.1] — 2026-05-29
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- `logs` now emits a consistent field set across all output formats. Previously `--json` dumped the raw API response (no computed `cost`, `other` left as a stringified blob, internal junk fields), while `table`/`yaml`/`markdown` showed a curated card.
|
|
27
|
+
- `logs --request-id` detail duration now reflects true end-to-end latency (`other.total_ms`) instead of the coarse `use_time` seconds value.
|
|
28
|
+
- `logs --request-id` cost now shows 6 decimal places (e.g. `$0.000384`) so sub-cent calls are no longer rounded to `$0.0004`.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- `logs` JSON/YAML output is now a canonical, typed record (raw numbers, booleans, ISO 8601 time, computed `cost_usd`, exploded `other` fields, normalized `model_price`) with a stable schema; `table`/`markdown` render the same fields as formatted strings.
|
|
33
|
+
|
|
8
34
|
## [0.3.0] — 2026-05-26
|
|
9
35
|
|
|
10
36
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cometapi-cli
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: CometAPI CLI — official command-line interface for the CometAPI AI gateway
|
|
5
5
|
Project-URL: Homepage, https://pypi.org/project/cometapi-cli/
|
|
6
6
|
Project-URL: Documentation, https://apidoc.cometapi.com/libraries/cli/overview
|
|
@@ -21,6 +21,7 @@ Classifier: Topic :: Internet
|
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries
|
|
22
22
|
Classifier: Typing :: Typed
|
|
23
23
|
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: click>=8.0
|
|
24
25
|
Requires-Dist: openai>=1.0.0
|
|
25
26
|
Requires-Dist: prompt-toolkit>=3.0
|
|
26
27
|
Requires-Dist: pyyaml>=6.0
|
|
@@ -144,6 +145,21 @@ cometapi run -h
|
|
|
144
145
|
| `repl` | Start an interactive command shell | Depends on command used |
|
|
145
146
|
| `config` | Show, set, unset, or locate local configuration | None |
|
|
146
147
|
|
|
148
|
+
## Logs
|
|
149
|
+
|
|
150
|
+
Use `cometapi logs` to inspect recent usage, export CSV, or look up one request by the
|
|
151
|
+
`X-Cometapi-Request-Id` response header.
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
cometapi logs --limit 20
|
|
155
|
+
cometapi logs --type consume --start 2026-06-01 --json
|
|
156
|
+
cometapi logs --request-id 20260617165550885561292gJBlzjtp
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`logs --request-id` first asks the backend for that exact request ID. If the installed
|
|
160
|
+
backend does not support direct request-ID filtering yet, the CLI falls back to scanning
|
|
161
|
+
a bounded number of log pages. Use `--request-id-max-pages` to widen that fallback scan.
|
|
162
|
+
|
|
147
163
|
## Models
|
|
148
164
|
|
|
149
165
|
`cometapi models` uses the public model catalog by default and displays richer metadata than `/v1/models`.
|
|
@@ -109,6 +109,21 @@ cometapi run -h
|
|
|
109
109
|
| `repl` | Start an interactive command shell | Depends on command used |
|
|
110
110
|
| `config` | Show, set, unset, or locate local configuration | None |
|
|
111
111
|
|
|
112
|
+
## Logs
|
|
113
|
+
|
|
114
|
+
Use `cometapi logs` to inspect recent usage, export CSV, or look up one request by the
|
|
115
|
+
`X-Cometapi-Request-Id` response header.
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
cometapi logs --limit 20
|
|
119
|
+
cometapi logs --type consume --start 2026-06-01 --json
|
|
120
|
+
cometapi logs --request-id 20260617165550885561292gJBlzjtp
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`logs --request-id` first asks the backend for that exact request ID. If the installed
|
|
124
|
+
backend does not support direct request-ID filtering yet, the CLI falls back to scanning
|
|
125
|
+
a bounded number of log pages. Use `--request-id-max-pages` to widen that fallback scan.
|
|
126
|
+
|
|
112
127
|
## Models
|
|
113
128
|
|
|
114
129
|
`cometapi models` uses the public model catalog by default and displays richer metadata than `/v1/models`.
|
|
@@ -18,6 +18,7 @@ cometapi logs [OPTIONS]
|
|
|
18
18
|
| `--end` | — | string | — | End date (see [Date Formats](#date-formats)) |
|
|
19
19
|
| `--group` | `-g` | string | — | Filter by API key group |
|
|
20
20
|
| `--request-id` | — | string | — | Look up cost by request ID (from `X-Cometapi-Request-Id` header) |
|
|
21
|
+
| `--request-id-max-pages` | — | int | `10` | Fallback pages to scan when direct request-ID lookup is unavailable |
|
|
21
22
|
| `--detail` | — | flag | `false` | Show extended columns (request ID, pricing ratios) |
|
|
22
23
|
| `--page` | `-p` | int | `1` | Page number |
|
|
23
24
|
| `--limit` | `-l` | int | `20` | Results per page |
|
|
@@ -102,7 +103,10 @@ Internal quota values are converted to USD:
|
|
|
102
103
|
$1.00 USD = 500,000 quota units
|
|
103
104
|
```
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
In the logs list, cost is displayed with 4 decimal places (e.g., `$0.0014`). The
|
|
107
|
+
per-request detail view (`--request-id`) uses 6 decimal places (e.g., `$0.000384`)
|
|
108
|
+
so sub-cent calls are not rounded away, and machine formats expose the raw
|
|
109
|
+
`cost_usd` float.
|
|
106
110
|
|
|
107
111
|
## CSV Export
|
|
108
112
|
|
|
@@ -160,27 +164,95 @@ cometapi logs --request-id req-abc-123
|
|
|
160
164
|
cometapi logs --request-id req-abc-123 --json
|
|
161
165
|
```
|
|
162
166
|
|
|
163
|
-
|
|
167
|
+
Lookup behavior:
|
|
164
168
|
|
|
169
|
+
1. The CLI first asks the backend for `request_id=req-abc-123` and accepts only an exact
|
|
170
|
+
`request_id` match.
|
|
171
|
+
2. If the backend does not return an exact match, the CLI falls back to scanning recent
|
|
172
|
+
log pages. Timestamp-shaped CometAPI request IDs are narrowed to the inferred local
|
|
173
|
+
request day unless you provide `--start` or `--end`.
|
|
174
|
+
3. The fallback scan is bounded by `--request-id-max-pages` (default: `10`) so a slow log
|
|
175
|
+
endpoint does not appear to hang indefinitely.
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Widen fallback scanning when direct lookup is unavailable
|
|
179
|
+
cometapi logs --request-id req-abc-123 --request-id-max-pages 25
|
|
165
180
|
```
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
├──────────────┼──────────────────────────┤
|
|
170
|
-
│ Request Id │ req-abc-123 │
|
|
171
|
-
│ Cost │ $0.0034 │
|
|
172
|
-
│ Quota (raw) │ 1,700 │
|
|
173
|
-
│ RPM │ 1 │
|
|
174
|
-
│ TPM │ 165 │
|
|
175
|
-
└──────────────┴──────────────────────────┘
|
|
181
|
+
|
|
182
|
+
Output shows a request detail card:
|
|
183
|
+
|
|
176
184
|
```
|
|
185
|
+
Request Detail
|
|
186
|
+
┌───────────────────┬──────────────────────────────────────────┐
|
|
187
|
+
│ Field │ Value │
|
|
188
|
+
├───────────────────┼──────────────────────────────────────────┤
|
|
189
|
+
│ Request ID │ req-abc-123 │
|
|
190
|
+
│ Response ID │ chatcmpl-xyz-789 │
|
|
191
|
+
│ Time │ 2026-05-29 06:00:21 │
|
|
192
|
+
│ Model │ gpt-5.4 │
|
|
193
|
+
│ Token Name │ Production Key │
|
|
194
|
+
│ Type │ consume │
|
|
195
|
+
│ Stream │ No │
|
|
196
|
+
│ Prompt Tokens │ 18 │
|
|
197
|
+
│ Completion Tokens │ 13 │
|
|
198
|
+
│ Cost (USD) │ $0.000384 │
|
|
199
|
+
│ Quota (raw) │ 192 │
|
|
200
|
+
│ Model Ratio │ 2.5 │
|
|
201
|
+
│ Completion Ratio │ 6x │
|
|
202
|
+
│ Group Ratio │ 0.8 │
|
|
203
|
+
│ Model Price │ default │
|
|
204
|
+
│ Duration │ 3,128 ms │
|
|
205
|
+
│ Endpoint │ /v1/chat/completions │
|
|
206
|
+
└───────────────────┴──────────────────────────────────────────┘
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Unified output schema
|
|
210
|
+
|
|
211
|
+
All formats expose the **same field set** — the difference is only presentation:
|
|
177
212
|
|
|
178
|
-
|
|
213
|
+
- `table` / `markdown` — human-friendly labels and formatted strings (`$0.000384`, `Yes`/`No`, `6x`, `3,128 ms`); optional fields are omitted when absent.
|
|
214
|
+
- `json` / `yaml` / `csv` — the canonical record with **raw typed values** (numbers, booleans, ISO 8601 time) and a stable schema (`null` when a value is absent), suitable for scripting.
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
cometapi logs --request-id req-abc-123 -f json
|
|
218
|
+
```
|
|
179
219
|
|
|
180
220
|
```json
|
|
181
|
-
{
|
|
221
|
+
{
|
|
222
|
+
"request_id": "req-abc-123",
|
|
223
|
+
"response_id": "chatcmpl-xyz-789",
|
|
224
|
+
"time": "2026-05-29T06:00:21+00:00",
|
|
225
|
+
"type": "consume",
|
|
226
|
+
"model": "gpt-5.4",
|
|
227
|
+
"token_name": "Production Key",
|
|
228
|
+
"username": "google_9550",
|
|
229
|
+
"user_id": 9550,
|
|
230
|
+
"ip": "203.0.113.7",
|
|
231
|
+
"stream": false,
|
|
232
|
+
"prompt_tokens": 18,
|
|
233
|
+
"completion_tokens": 13,
|
|
234
|
+
"cache_tokens": 0,
|
|
235
|
+
"cost_usd": 0.000384,
|
|
236
|
+
"quota": 192,
|
|
237
|
+
"model_ratio": 2.5,
|
|
238
|
+
"completion_ratio": 6,
|
|
239
|
+
"group_ratio": 0.8,
|
|
240
|
+
"model_price": null,
|
|
241
|
+
"cache_ratio": 0.1,
|
|
242
|
+
"duration_ms": 3128,
|
|
243
|
+
"first_token_ms": null,
|
|
244
|
+
"endpoint": "/v1/chat/completions"
|
|
245
|
+
}
|
|
182
246
|
```
|
|
183
247
|
|
|
248
|
+
Notes:
|
|
249
|
+
|
|
250
|
+
- `cost_usd` is `quota / 500000`, rounded to 6 decimals (matches the backend). In the `table`/`markdown` card it is shown as `$0.000384` so sub-cent calls are not rounded away.
|
|
251
|
+
- `duration_ms` uses the request's true end-to-end latency (`other.total_ms`); it falls back to the coarse `use_time` value only when `total_ms` is unavailable.
|
|
252
|
+
- `model_price` is `null` when the backend uses ratio-based pricing (the `-1` sentinel); the `table`/`markdown` card renders this as `default`.
|
|
253
|
+
- `time` is ISO 8601 UTC in machine formats; the card renders `YYYY-MM-DD HH:MM:SS`.
|
|
254
|
+
- `ip` is the client IP recorded by the backend — treat it as sensitive when sharing logs.
|
|
255
|
+
|
|
184
256
|
You can combine `--request-id` with filter options like `--type` and `--model` for additional precision. `--request-id` cannot be used with `--export`.
|
|
185
257
|
|
|
186
258
|
> **Note:** The upstream provider's response ID (e.g., `chatcmpl-DSfol...` from OpenAI) is NOT stored
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "cometapi-cli"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.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" }
|
|
@@ -24,6 +24,7 @@ classifiers = [
|
|
|
24
24
|
"Typing :: Typed",
|
|
25
25
|
]
|
|
26
26
|
dependencies = [
|
|
27
|
+
"click>=8.0",
|
|
27
28
|
"openai>=1.0.0",
|
|
28
29
|
"typer>=0.12",
|
|
29
30
|
"rich>=13.0",
|
|
@@ -9,6 +9,8 @@ import openai
|
|
|
9
9
|
|
|
10
10
|
COMETAPI_BASE_URL = "https://api.cometapi.com/v1"
|
|
11
11
|
COMETAPI_DASHBOARD_BASE = "https://api.cometapi.com"
|
|
12
|
+
ACCOUNT_REQUEST_TIMEOUT = 30.0
|
|
13
|
+
ACCOUNT_EXPORT_TIMEOUT = 120.0
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
class CometClient(openai.OpenAI):
|
|
@@ -44,7 +46,14 @@ class CometClient(openai.OpenAI):
|
|
|
44
46
|
|
|
45
47
|
# -- Account management (access-token auth) --------------------------------
|
|
46
48
|
|
|
47
|
-
def _account_request(
|
|
49
|
+
def _account_request(
|
|
50
|
+
self,
|
|
51
|
+
method: str,
|
|
52
|
+
path: str,
|
|
53
|
+
*,
|
|
54
|
+
params: dict | None = None,
|
|
55
|
+
timeout: float = ACCOUNT_REQUEST_TIMEOUT,
|
|
56
|
+
) -> dict:
|
|
48
57
|
"""Make an authenticated request to a CometAPI account endpoint."""
|
|
49
58
|
if not self._access_token:
|
|
50
59
|
raise openai.OpenAIError(
|
|
@@ -56,6 +65,7 @@ class CometClient(openai.OpenAI):
|
|
|
56
65
|
f"{COMETAPI_DASHBOARD_BASE}{path}",
|
|
57
66
|
headers={"Authorization": f"Bearer {self._access_token}"},
|
|
58
67
|
params=params,
|
|
68
|
+
timeout=timeout,
|
|
59
69
|
)
|
|
60
70
|
response.raise_for_status()
|
|
61
71
|
return response.json()
|
|
@@ -151,6 +161,7 @@ class CometClient(openai.OpenAI):
|
|
|
151
161
|
start_timestamp: int | None = None,
|
|
152
162
|
end_timestamp: int | None = None,
|
|
153
163
|
group: str | None = None,
|
|
164
|
+
request_id: str | None = None,
|
|
154
165
|
) -> dict:
|
|
155
166
|
"""List the user's usage logs (requires access token)."""
|
|
156
167
|
params: dict[str, Any] = {"p": page, "page_size": page_size}
|
|
@@ -166,6 +177,8 @@ class CometClient(openai.OpenAI):
|
|
|
166
177
|
params["end_timestamp"] = end_timestamp
|
|
167
178
|
if group:
|
|
168
179
|
params["group"] = group
|
|
180
|
+
if request_id:
|
|
181
|
+
params["request_id"] = request_id
|
|
169
182
|
return self._account_request("GET", "/api/log/self", params=params)
|
|
170
183
|
|
|
171
184
|
def search_logs(self, keyword: str) -> dict:
|
|
@@ -235,6 +248,7 @@ class CometClient(openai.OpenAI):
|
|
|
235
248
|
f"{COMETAPI_DASHBOARD_BASE}/api/log/self/export",
|
|
236
249
|
headers={"Authorization": f"Bearer {self._access_token}"},
|
|
237
250
|
params=params,
|
|
251
|
+
timeout=ACCOUNT_EXPORT_TIMEOUT,
|
|
238
252
|
)
|
|
239
253
|
response.raise_for_status()
|
|
240
254
|
return response.content
|