ollama-cloud-usage 1.0.0 → 1.0.2
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.
- package/README.md +11 -1
- package/dist/api.d.ts +14 -3
- package/dist/api.js +6 -2
- package/dist/cli.js +13 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,9 +70,19 @@ Snapshots are appended to `./ollama-usage.jsonl` (one JSON object per line), or
|
|
|
70
70
|
the path in `OLLAMA_USAGE_LOG`. Each line:
|
|
71
71
|
|
|
72
72
|
```json
|
|
73
|
-
{"timestamp":"...","session":{"used_percent":3.91,"remaining_percent":96.09,"resets_at":"2026-10-27T08:00:00Z"},"weekly":{"used_percent":16.67,"remaining_percent":83.33,"resets_at":"2026-11-02T00:00:00Z"},"purchased":{"balance_usd":0},"usage":{"range":"7d","totals":{"request_count":
|
|
73
|
+
{"timestamp":"...","session":{"used_percent":3.91,"remaining_percent":96.09,"resets_at":"2026-10-27T08:00:00Z"},"weekly":{"used_percent":16.67,"remaining_percent":83.33,"resets_at":"2026-11-02T00:00:00Z"},"purchased":{"balance_usd":0},"usage":{"range":"7d","totals":{"request_count":37796,"groups":[{"model":"deepseek-v4.1-flash:1017","request_count":32964},{"model":"glm-5.3-flash","request_count":4588}]},"partial":{"from":"2026-10-27T00:00:00Z","request_count":2084,"groups":[{"model":"deepseek-v4.1-flash:1017","request_count":1148},{"model":"glm-5.3-flash","request_count":911}]}}}
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
`usage.totals.groups` holds per-model request counts (`group_by=model`, top 10).
|
|
77
|
+
|
|
78
|
+
`usage.partial` is the current (still-growing) bucket. Because a bucket is a
|
|
79
|
+
fixed time slice, differencing two snapshots gives the new requests per model —
|
|
80
|
+
the input a cost estimator needs. `totals` is a sliding 7-day window and cannot
|
|
81
|
+
be differenced that way.
|
|
82
|
+
|
|
83
|
+
The monitor only logs these — it does not display or interpret them; cost
|
|
84
|
+
analysis can be done later from the log.
|
|
85
|
+
|
|
76
86
|
The log never contains the API key or per-request content.
|
|
77
87
|
|
|
78
88
|
## License
|
package/dist/api.d.ts
CHANGED
|
@@ -5,7 +5,14 @@ export interface UsageMetrics {
|
|
|
5
5
|
cached_input_tokens?: number;
|
|
6
6
|
output_tokens?: number;
|
|
7
7
|
}
|
|
8
|
-
export interface
|
|
8
|
+
export interface UsageGroup extends UsageMetrics {
|
|
9
|
+
model: string;
|
|
10
|
+
}
|
|
11
|
+
export interface UsageSummary extends UsageMetrics {
|
|
12
|
+
groups?: UsageGroup[];
|
|
13
|
+
remainder?: UsageMetrics;
|
|
14
|
+
}
|
|
15
|
+
export interface UsageBucket extends UsageSummary {
|
|
9
16
|
from: string;
|
|
10
17
|
until: string;
|
|
11
18
|
partial?: boolean;
|
|
@@ -14,9 +21,10 @@ export interface UsageReport {
|
|
|
14
21
|
range: "24h" | "7d" | "30d";
|
|
15
22
|
scope: "self" | "team";
|
|
16
23
|
granularity: "hour" | "day";
|
|
24
|
+
group_by?: "model";
|
|
17
25
|
from: string;
|
|
18
26
|
until: string;
|
|
19
|
-
totals:
|
|
27
|
+
totals: UsageSummary;
|
|
20
28
|
buckets: UsageBucket[];
|
|
21
29
|
}
|
|
22
30
|
export interface PlanLimit {
|
|
@@ -38,6 +46,9 @@ export interface Balance {
|
|
|
38
46
|
balance_usd: number;
|
|
39
47
|
};
|
|
40
48
|
}
|
|
41
|
-
export declare function fetchUsage(key: string,
|
|
49
|
+
export declare function fetchUsage(key: string, options?: {
|
|
50
|
+
range?: string;
|
|
51
|
+
groupBy?: "model";
|
|
52
|
+
}): Promise<UsageReport>;
|
|
42
53
|
export declare function fetchBalance(key: string): Promise<Balance>;
|
|
43
54
|
export declare function hasLimits(balance: Balance): boolean;
|
package/dist/api.js
CHANGED
|
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fetchUsage = fetchUsage;
|
|
4
4
|
exports.fetchBalance = fetchBalance;
|
|
5
5
|
exports.hasLimits = hasLimits;
|
|
6
|
-
async function fetchUsage(key,
|
|
7
|
-
let
|
|
6
|
+
async function fetchUsage(key, options = {}) {
|
|
7
|
+
let range = options.range || "7d";
|
|
8
|
+
let url = `https://ollama.com/api/usage?range=${range}`;
|
|
9
|
+
if (options.groupBy)
|
|
10
|
+
url += `&group_by=${options.groupBy}`;
|
|
11
|
+
let res = await fetch(url, {
|
|
8
12
|
headers: { Authorization: `Bearer ${key}` },
|
|
9
13
|
});
|
|
10
14
|
if (!res.ok)
|
package/dist/cli.js
CHANGED
|
@@ -44,9 +44,21 @@ function logQuota(options) {
|
|
|
44
44
|
if (options.balance.purchased)
|
|
45
45
|
row.purchased = options.balance.purchased;
|
|
46
46
|
if (options.usage) {
|
|
47
|
+
// The partial bucket is a fixed, growing slice, so differencing two polls
|
|
48
|
+
// gives the new requests per model — the input a cost estimator needs.
|
|
49
|
+
// `totals` is a sliding window and cannot be differenced that way.
|
|
50
|
+
let buckets = options.usage.buckets;
|
|
51
|
+
let last = buckets && buckets.length > 0 ? buckets[buckets.length - 1] : undefined;
|
|
47
52
|
row.usage = {
|
|
48
53
|
range: options.usage.range,
|
|
49
54
|
totals: options.usage.totals,
|
|
55
|
+
partial: last
|
|
56
|
+
? {
|
|
57
|
+
from: last.from,
|
|
58
|
+
request_count: last.request_count,
|
|
59
|
+
groups: last.groups || [],
|
|
60
|
+
}
|
|
61
|
+
: null,
|
|
50
62
|
};
|
|
51
63
|
}
|
|
52
64
|
fs_1.default.appendFileSync(logFile, JSON.stringify(row) + "\n");
|
|
@@ -64,7 +76,7 @@ async function main() {
|
|
|
64
76
|
while (true) {
|
|
65
77
|
let now = new Date();
|
|
66
78
|
let balance = await (0, api_1.fetchBalance)(key);
|
|
67
|
-
let usage = await (0, api_1.fetchUsage)(key, "7d");
|
|
79
|
+
let usage = await (0, api_1.fetchUsage)(key, { range: "7d", groupBy: "model" });
|
|
68
80
|
if ((0, api_1.hasLimits)(balance)) {
|
|
69
81
|
// Legacy plans: session/weekly remaining % plus exact reset times.
|
|
70
82
|
let session = balance.included.session;
|