@wavespeed/cli 0.4.1 → 0.4.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 +10 -0
- package/dist/commands/price.js +43 -2
- package/dist/lib/pricing-vars.js +75 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -152,6 +152,16 @@ wavespeed init Create a wavespeed.json with defaults +
|
|
|
152
152
|
wavespeed skill install Drop SKILL.md for coding agents
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
+
**Pricing is an estimate.** `wavespeed price` quotes from the model's pricing
|
|
156
|
+
formula, and many models bill from an input — audio/video duration, frame count,
|
|
157
|
+
text length. Those inputs are optional in the quote: ask for a price without
|
|
158
|
+
them and the formula collapses to the model's **base price**, which is the floor
|
|
159
|
+
of its range, not a typical run. `wavespeed price wavespeed-ai/infinitetalk`
|
|
160
|
+
says `$0.15`; a 60s audio actually bills `$1.80`. The command names the inputs it
|
|
161
|
+
was blind to (`unpriced_inputs` / `at_base_price` in `--json`) — supply them for
|
|
162
|
+
a real quote. Whatever it says, the amount actually charged for a run is
|
|
163
|
+
authoritative.
|
|
164
|
+
|
|
155
165
|
## Auth
|
|
156
166
|
|
|
157
167
|
| | Use when |
|
package/dist/commands/price.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import ora from 'ora';
|
|
3
|
-
import { fetchPricing } from '../lib/api.js';
|
|
3
|
+
import { fetchPricing, fetchModels } from '../lib/api.js';
|
|
4
|
+
import { missingPriceVars, isFloorQuote } from '../lib/pricing-vars.js';
|
|
4
5
|
import { parseInputs } from '../lib/inputs.js';
|
|
5
6
|
import { resolveModelToken } from '../lib/config.js';
|
|
6
7
|
import { collectLocalFiles, resolveLocalFiles } from '../lib/local-files.js';
|
|
@@ -73,9 +74,35 @@ export function registerPrice(program) {
|
|
|
73
74
|
const spinner = !opts.json ? ora('Calculating price…').start() : null;
|
|
74
75
|
try {
|
|
75
76
|
const data = await fetchPricing(resolved.model, inputs);
|
|
77
|
+
// /model/price evaluates the model's formula against whatever inputs we
|
|
78
|
+
// send and never complains about the ones we left out — a formula with
|
|
79
|
+
// every variable missing collapses to base_price. That is the floor of
|
|
80
|
+
// the model's range, not a representative charge, so name the inputs
|
|
81
|
+
// this quote could not see rather than presenting the floor as "the"
|
|
82
|
+
// price. Catalog is cached 1h; a lookup failure only costs the detail.
|
|
83
|
+
let unpriced = [];
|
|
84
|
+
let atFloor = false;
|
|
85
|
+
try {
|
|
86
|
+
const { models } = await fetchModels();
|
|
87
|
+
const meta = models.find((m) => m.model_id === resolved.model);
|
|
88
|
+
const props = meta?.api_schema?.api_schemas?.[0]?.request_schema?.properties;
|
|
89
|
+
unpriced = missingPriceVars(meta?.formula, inputs, props);
|
|
90
|
+
atFloor = isFloorQuote(meta?.formula, inputs);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
/* no catalog — fall back to the generic disclaimer below */
|
|
94
|
+
}
|
|
76
95
|
spinner?.stop();
|
|
96
|
+
const disclaimer = 'Estimate only, for reference — the amount actually charged for a run is authoritative.';
|
|
77
97
|
if (opts.json) {
|
|
78
|
-
process.stdout.write(JSON.stringify({
|
|
98
|
+
process.stdout.write(JSON.stringify({
|
|
99
|
+
...data,
|
|
100
|
+
estimate: true,
|
|
101
|
+
unpriced_inputs: unpriced,
|
|
102
|
+
at_base_price: atFloor,
|
|
103
|
+
disclaimer,
|
|
104
|
+
uploaded: uploadedUrls,
|
|
105
|
+
}, null, 2) + '\n');
|
|
79
106
|
return;
|
|
80
107
|
}
|
|
81
108
|
console.log();
|
|
@@ -86,6 +113,19 @@ export function registerPrice(program) {
|
|
|
86
113
|
(data.discounted_price > 0 && data.discounted_price !== data.price
|
|
87
114
|
? chalk.gray(` (list $${data.price})`)
|
|
88
115
|
: ''));
|
|
116
|
+
if (unpriced.length > 0) {
|
|
117
|
+
console.log(' ' +
|
|
118
|
+
chalk.yellow('note: ') +
|
|
119
|
+
chalk.yellow(`this model is priced from ${unpriced.join(', ')}, which ${unpriced.length === 1 ? 'was' : 'were'} not supplied.`));
|
|
120
|
+
console.log(' ' +
|
|
121
|
+
chalk.gray(atFloor
|
|
122
|
+
? 'The figure above is the base price — the floor of this model’s range, not a typical run.'
|
|
123
|
+
: 'The figure above prices the rest at their defaults and can move once these are set.'));
|
|
124
|
+
console.log(' ' +
|
|
125
|
+
chalk.gray('Pass ') +
|
|
126
|
+
chalk.cyan(unpriced.map((v) => `-i ${v}=…`).join(' ')) +
|
|
127
|
+
chalk.gray(' for a representative quote.'));
|
|
128
|
+
}
|
|
89
129
|
console.log();
|
|
90
130
|
for (const [file, url] of Object.entries(uploadedUrls)) {
|
|
91
131
|
console.log(' ' + chalk.gray('uploaded: ') + chalk.gray(file + ' → ') + chalk.cyan(url));
|
|
@@ -95,6 +135,7 @@ export function registerPrice(program) {
|
|
|
95
135
|
}
|
|
96
136
|
console.log();
|
|
97
137
|
console.log(chalk.gray('Run it: ') + chalk.cyan(`wavespeed run ${modelArg}` + (opts.prompt ? ` -p "${opts.prompt}"` : '')));
|
|
138
|
+
console.log(chalk.gray(disclaimer));
|
|
98
139
|
console.log();
|
|
99
140
|
}
|
|
100
141
|
catch (err) {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Pricing formulas are JSONata expressions returned by /api/v3/models, e.g.
|
|
2
|
+
// {"total_price": $max([5, $min([$ceil(get_duration_v3(audio)), 600])]) / 5 * base_price}
|
|
3
|
+
// {"total_price": base_price * duration / 5}
|
|
4
|
+
//
|
|
5
|
+
// The pricing endpoint evaluates them server-side and happily accepts a partial
|
|
6
|
+
// (or empty) `inputs` object — a formula whose variables are all missing
|
|
7
|
+
// collapses to `base_price`, which is the floor of the model's price range, not
|
|
8
|
+
// a typical charge. `wavespeed price wavespeed-ai/infinitetalk` with no inputs
|
|
9
|
+
// quotes $0.15 while a 60s audio actually costs $1.80. So we parse the formula
|
|
10
|
+
// to find which inputs move the price, and say which ones the quote is blind to.
|
|
11
|
+
const RESERVED = new Set(['base_price', 'total_price', 'true', 'false', 'null']);
|
|
12
|
+
/**
|
|
13
|
+
* Variable names a pricing formula reads from the model's inputs, in first-seen
|
|
14
|
+
* order. Excludes JSONata builtins (`$max`), helper calls (`get_duration_v3`),
|
|
15
|
+
* string literals, and `base_price`/`total_price`.
|
|
16
|
+
*
|
|
17
|
+
* Returns [] for a flat-priced model (`base_price * 1`) or an unparseable
|
|
18
|
+
* formula — callers should treat [] as "nothing input-dependent to warn about".
|
|
19
|
+
*/
|
|
20
|
+
export function extractPriceVars(formula) {
|
|
21
|
+
if (!formula)
|
|
22
|
+
return [];
|
|
23
|
+
// Drop string literals first so "720p" / "total_price" keys never register.
|
|
24
|
+
const stripped = formula.replace(/"(?:[^"\\]|\\.)*"/g, '""').replace(/'(?:[^'\\]|\\.)*'/g, "''");
|
|
25
|
+
const vars = [];
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
const re = /(\$?)([A-Za-z_][A-Za-z0-9_]*)\s*(\()?/g;
|
|
28
|
+
let m;
|
|
29
|
+
while ((m = re.exec(stripped)) !== null) {
|
|
30
|
+
const [, dollar, name, call] = m;
|
|
31
|
+
if (dollar)
|
|
32
|
+
continue; // $max, $ceil, $length — JSONata builtin
|
|
33
|
+
if (call)
|
|
34
|
+
continue; // get_duration_v3(...) — server-side helper
|
|
35
|
+
if (RESERVED.has(name))
|
|
36
|
+
continue;
|
|
37
|
+
if (seen.has(name))
|
|
38
|
+
continue;
|
|
39
|
+
seen.add(name);
|
|
40
|
+
vars.push(name);
|
|
41
|
+
}
|
|
42
|
+
return vars;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Price-driving variables the quote is genuinely blind to.
|
|
46
|
+
*
|
|
47
|
+
* A driver the caller omitted but that carries a schema default is NOT blind —
|
|
48
|
+
* the server priced it at that default, which is exactly what a run would use.
|
|
49
|
+
* Only drivers with no default (infinitetalk's `audio`, seedance's
|
|
50
|
+
* `reference_videos`) leave the quote uninformed, and those are the ones that
|
|
51
|
+
* silently collapse the formula toward base_price.
|
|
52
|
+
*/
|
|
53
|
+
export function missingPriceVars(formula, inputs, schemaProps) {
|
|
54
|
+
return extractPriceVars(formula).filter((v) => {
|
|
55
|
+
const val = inputs[v];
|
|
56
|
+
if (val !== undefined && val !== null && val !== '')
|
|
57
|
+
return false;
|
|
58
|
+
const prop = schemaProps?.[v];
|
|
59
|
+
return !(prop && 'default' in prop);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* True when every price driver is unsupplied — the case where the formula
|
|
64
|
+
* degenerates to `base_price` and the quote is the floor of the model's range
|
|
65
|
+
* rather than a representative charge.
|
|
66
|
+
*/
|
|
67
|
+
export function isFloorQuote(formula, inputs) {
|
|
68
|
+
const vars = extractPriceVars(formula);
|
|
69
|
+
if (vars.length === 0)
|
|
70
|
+
return false;
|
|
71
|
+
return vars.every((v) => {
|
|
72
|
+
const val = inputs[v];
|
|
73
|
+
return val === undefined || val === null || val === '';
|
|
74
|
+
});
|
|
75
|
+
}
|