craterview 0.4.36 → 0.4.38
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 +8 -6
- package/index.ts +36 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -202,6 +202,7 @@ Every field the API publishes on a job is exposed here.
|
|
|
202
202
|
| `inputUrl` | The picture the model worked from — the region, where you named one |
|
|
203
203
|
| `contentType` | The result's media type |
|
|
204
204
|
| `outputBytes` | The result's size in bytes |
|
|
205
|
+
| `outputWidth`, `outputHeight` | The result's size in pixels |
|
|
205
206
|
| `blob()`, `arrayBuffer()` | Download the result |
|
|
206
207
|
|
|
207
208
|
`result` is the whole of what the job produced, and the rows above it that describe the
|
|
@@ -219,12 +220,12 @@ they are about to send and declare it; the API signs it into the presigned URL,
|
|
|
219
220
|
accepts exactly that length and nothing else. You do not pass it — it is read off the data
|
|
220
221
|
in hand, which is what makes it impossible to get wrong.
|
|
221
222
|
|
|
222
|
-
**Running out of credit does not stop you.** A job
|
|
223
|
-
|
|
224
|
-
queue
|
|
225
|
-
set, and `usage()` reports the same flag for your next job before you send it. There
|
|
226
|
-
payment error to handle:
|
|
227
|
-
|
|
223
|
+
**Running out of credit does not stop you.** A job at a balance of zero is accepted. Without a
|
|
224
|
+
subscription, or once a limited subscription's monthly allowance is spent, it runs free on the
|
|
225
|
+
community queue: same models, smaller size limits, longer waits at busy times. It comes back with
|
|
226
|
+
`community` set, and `usage()` reports the same flag for your next job before you send it. There
|
|
227
|
+
is no payment error to handle: credit or a subscription moves work onto paid compute that scales
|
|
228
|
+
with demand.
|
|
228
229
|
`etaSeconds` covers the whole wait, queue time included, so a community job simply reports
|
|
229
230
|
a longer one.
|
|
230
231
|
|
|
@@ -321,6 +322,7 @@ old one. You cannot revoke the key you are calling with.
|
|
|
321
322
|
await cv.models(); // models, what each takes and answers with, which queue you are on
|
|
322
323
|
await cv.job("job_..."); // one job by id
|
|
323
324
|
await cv.usage(); // credit balance, next job's queue, spend and job counts
|
|
325
|
+
await cv.quote("cv-enhance-v3", { scale: 2 }, { inputWidth: 1500, inputHeight: 1000 }); // a job's price and result size, run nothing
|
|
324
326
|
|
|
325
327
|
for await (const job of cv.jobs({ limit: 50, status: "succeeded" })) {
|
|
326
328
|
console.log(job.id, job.status); // newest first, paging transparently
|
package/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { imageSize } from "image-size";
|
|
|
18
18
|
// Mirrored from package.json, which is the number a release bumps. It cannot be imported
|
|
19
19
|
// from there — this ships as TypeScript, so the import would have to resolve in the
|
|
20
20
|
// consumer's toolchain — so test/version.test.ts asserts the two agree.
|
|
21
|
-
export const VERSION = "0.4.
|
|
21
|
+
export const VERSION = "0.4.38";
|
|
22
22
|
const DEFAULT_BASE_URL = "https://api.craterview.ai";
|
|
23
23
|
// The server rejects a longer wait outright, so asking for one costs a 422 rather than the
|
|
24
24
|
// wait you asked for. `run()` clamps to this rather than letting that happen.
|
|
@@ -475,12 +475,11 @@ export interface ModelInfo {
|
|
|
475
475
|
*/
|
|
476
476
|
result_schema: Record<string, unknown>;
|
|
477
477
|
/**
|
|
478
|
-
* Whether your
|
|
479
|
-
*
|
|
480
|
-
*
|
|
478
|
+
* Whether your next job runs free on the community queue: same models, smaller size limits,
|
|
479
|
+
* longer waits at busy times. True without credit or a subscription, or once a limited
|
|
480
|
+
* subscription's monthly allowance is spent. Otherwise it runs on paid compute.
|
|
481
481
|
*
|
|
482
|
-
*
|
|
483
|
-
* is answered on the job, once you have one — `Job.eta_seconds` — and nowhere else.
|
|
482
|
+
* How long a wait will be is answered on the job, once you have one: `Job.eta_seconds`.
|
|
484
483
|
*/
|
|
485
484
|
community: boolean;
|
|
486
485
|
/** Of `params_schema`, the ones that apply to still images only. */
|
|
@@ -609,7 +608,7 @@ export interface JobData {
|
|
|
609
608
|
* A submitted job. Mirrors the API's job representation field for field.
|
|
610
609
|
*
|
|
611
610
|
* `credits` is what you were billed, and it is the only figure about cost the API states.
|
|
612
|
-
*
|
|
611
|
+
* Nothing is owed for what the balance does not cover: it is written off when credit next
|
|
613
612
|
* arrives or a subscription renews.
|
|
614
613
|
* For how long a job took, `finishedAt` minus `createdAt` is the wait you actually had,
|
|
615
614
|
* queue included — both are here and both are on the webhook, which states the same fields
|
|
@@ -635,12 +634,9 @@ export interface JobData {
|
|
|
635
634
|
* run is done — an estimate that never reaches 1 before the job finishes, and null when none
|
|
636
635
|
* holds. Null while the job is queued and once it has settled.
|
|
637
636
|
*
|
|
638
|
-
* `community` says the job
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
* balance is never itself a reason to refuse a job — paying moves work onto paid compute that
|
|
642
|
-
* scales with demand, not the right to submit — but on some models the community queue takes
|
|
643
|
-
* smaller files.
|
|
637
|
+
* `community` says the job runs free on the community queue: same models, smaller size
|
|
638
|
+
* limits, longer waits at busy times. A job goes there without credit or a subscription, or
|
|
639
|
+
* once a limited subscription's monthly allowance is spent. A balance of zero never stops a job.
|
|
644
640
|
* `models()` lists each model's limits for your key, and a file over them is refused with
|
|
645
641
|
* the limit named.
|
|
646
642
|
*/
|
|
@@ -710,6 +706,10 @@ export class Job {
|
|
|
710
706
|
}
|
|
711
707
|
get contentType() { return (this.output["content_type"] as string) ?? null; }
|
|
712
708
|
get outputBytes() { return (this.output["bytes"] as number) ?? null; }
|
|
709
|
+
/** The result's width in pixels. */
|
|
710
|
+
get outputWidth() { return (this.output["width"] as number) ?? null; }
|
|
711
|
+
/** The result's height in pixels. */
|
|
712
|
+
get outputHeight() { return (this.output["height"] as number) ?? null; }
|
|
713
713
|
|
|
714
714
|
/** Null when absent or unparseable — never a bad Date, which compares false to itself. */
|
|
715
715
|
get createdAt(): Date | null { return this.moment(this.data.created_at); }
|
|
@@ -928,10 +928,8 @@ export class CraterView {
|
|
|
928
928
|
*
|
|
929
929
|
* Prices are published here, so the cost of a job is knowable before submitting it.
|
|
930
930
|
*
|
|
931
|
-
* `community` and the limits are
|
|
932
|
-
*
|
|
933
|
-
* in — so two keys asking at the same moment can get different answers, and paying —
|
|
934
|
-
* credit or a subscription — changes yours.
|
|
931
|
+
* `community` and the limits are for your key's next job, so two keys can get different
|
|
932
|
+
* answers, and credit or a subscription changes yours.
|
|
935
933
|
*
|
|
936
934
|
* A model that is available is not always listed — a model in trial, or being retired,
|
|
937
935
|
* stays usable by name while absent from this catalog.
|
|
@@ -1061,7 +1059,8 @@ export class CraterView {
|
|
|
1061
1059
|
* time, and `credits_granted` what it has been given. `credits_remaining` is always a
|
|
1062
1060
|
* number, floored at zero. A balance of zero never stops a
|
|
1063
1061
|
* submission: `community` says whether your next job runs on the community queue, which is
|
|
1064
|
-
* free and can wait longer at busy times, or on paid compute. `
|
|
1062
|
+
* free and can wait longer at busy times, or on paid compute. `subscription_allowance` is a
|
|
1063
|
+
* number on a limited subscription and null on an unlimited one. `jobs_in_flight` and
|
|
1065
1064
|
* `max_jobs_in_flight` are the state of the queue and are what a 429 on submit is about.
|
|
1066
1065
|
*
|
|
1067
1066
|
* Account-wide, so every key on an account reports the same figures.
|
|
@@ -1070,6 +1069,25 @@ export class CraterView {
|
|
|
1070
1069
|
return await this.request("GET", "/v1/usage");
|
|
1071
1070
|
}
|
|
1072
1071
|
|
|
1072
|
+
/**
|
|
1073
|
+
* What a job would cost and how large its result would be, without running it.
|
|
1074
|
+
*
|
|
1075
|
+
* Nothing is uploaded, queued or charged. `inputWidth` and `inputHeight` are the picture's size
|
|
1076
|
+
* the way up a person sees it. A size a job would be refused for is an error with status 422,
|
|
1077
|
+
* in the words the job would fail with.
|
|
1078
|
+
*
|
|
1079
|
+
* The answer has `credits`, or `credits_at_most` where the price is not known yet, `community`
|
|
1080
|
+
* for the queue that price is for, and `result_megapixels` where `scale` sizes the job.
|
|
1081
|
+
*/
|
|
1082
|
+
async quote(model: string, params: Record<string, unknown> = {},
|
|
1083
|
+
size: { inputWidth?: number; inputHeight?: number } = {}): Promise<unknown> {
|
|
1084
|
+
return await this.request("POST", "/v1/quotes", {
|
|
1085
|
+
model, params,
|
|
1086
|
+
...(size.inputWidth !== undefined ? { input_width: size.inputWidth } : {}),
|
|
1087
|
+
...(size.inputHeight !== undefined ? { input_height: size.inputHeight } : {}),
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1073
1091
|
/**
|
|
1074
1092
|
* The secret your callbacks are signed with, created the first time you ask or with your
|
|
1075
1093
|
* first delivery, whichever comes first.
|