craterview 0.4.35 → 0.4.37
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 +45 -19
- 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.37";
|
|
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. */
|
|
@@ -502,6 +501,12 @@ export interface KeyInfo {
|
|
|
502
501
|
* back in. This client has no method for that call.
|
|
503
502
|
*/
|
|
504
503
|
current: boolean;
|
|
504
|
+
/**
|
|
505
|
+
* Whether this key belongs to the CraterView.ai app on an iPhone or iPad: the key the
|
|
506
|
+
* person's devices share, or one device's own. It cannot be revoked by id; the app ends it
|
|
507
|
+
* when the person signs out in it.
|
|
508
|
+
*/
|
|
509
|
+
app: boolean;
|
|
505
510
|
}
|
|
506
511
|
|
|
507
512
|
/** A freshly minted key. The only response that carries a usable value. */
|
|
@@ -603,7 +608,7 @@ export interface JobData {
|
|
|
603
608
|
* A submitted job. Mirrors the API's job representation field for field.
|
|
604
609
|
*
|
|
605
610
|
* `credits` is what you were billed, and it is the only figure about cost the API states.
|
|
606
|
-
*
|
|
611
|
+
* Nothing is owed for what the balance does not cover: it is written off when credit next
|
|
607
612
|
* arrives or a subscription renews.
|
|
608
613
|
* For how long a job took, `finishedAt` minus `createdAt` is the wait you actually had,
|
|
609
614
|
* queue included — both are here and both are on the webhook, which states the same fields
|
|
@@ -629,12 +634,9 @@ export interface JobData {
|
|
|
629
634
|
* run is done — an estimate that never reaches 1 before the job finishes, and null when none
|
|
630
635
|
* holds. Null while the job is queued and once it has settled.
|
|
631
636
|
*
|
|
632
|
-
* `community` says the job
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
* balance is never itself a reason to refuse a job — paying moves work onto paid compute that
|
|
636
|
-
* scales with demand, not the right to submit — but on some models the community queue takes
|
|
637
|
-
* 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.
|
|
638
640
|
* `models()` lists each model's limits for your key, and a file over them is refused with
|
|
639
641
|
* the limit named.
|
|
640
642
|
*/
|
|
@@ -704,6 +706,10 @@ export class Job {
|
|
|
704
706
|
}
|
|
705
707
|
get contentType() { return (this.output["content_type"] as string) ?? null; }
|
|
706
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; }
|
|
707
713
|
|
|
708
714
|
/** Null when absent or unparseable — never a bad Date, which compares false to itself. */
|
|
709
715
|
get createdAt(): Date | null { return this.moment(this.data.created_at); }
|
|
@@ -922,10 +928,8 @@ export class CraterView {
|
|
|
922
928
|
*
|
|
923
929
|
* Prices are published here, so the cost of a job is knowable before submitting it.
|
|
924
930
|
*
|
|
925
|
-
* `community` and the limits are
|
|
926
|
-
*
|
|
927
|
-
* in — so two keys asking at the same moment can get different answers, and paying —
|
|
928
|
-
* 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.
|
|
929
933
|
*
|
|
930
934
|
* A model that is available is not always listed — a model in trial, or being retired,
|
|
931
935
|
* stays usable by name while absent from this catalog.
|
|
@@ -1055,7 +1059,8 @@ export class CraterView {
|
|
|
1055
1059
|
* time, and `credits_granted` what it has been given. `credits_remaining` is always a
|
|
1056
1060
|
* number, floored at zero. A balance of zero never stops a
|
|
1057
1061
|
* submission: `community` says whether your next job runs on the community queue, which is
|
|
1058
|
-
* 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
|
|
1059
1064
|
* `max_jobs_in_flight` are the state of the queue and are what a 429 on submit is about.
|
|
1060
1065
|
*
|
|
1061
1066
|
* Account-wide, so every key on an account reports the same figures.
|
|
@@ -1064,6 +1069,25 @@ export class CraterView {
|
|
|
1064
1069
|
return await this.request("GET", "/v1/usage");
|
|
1065
1070
|
}
|
|
1066
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
|
+
|
|
1067
1091
|
/**
|
|
1068
1092
|
* The secret your callbacks are signed with, created the first time you ask or with your
|
|
1069
1093
|
* first delivery, whichever comes first.
|
|
@@ -1133,7 +1157,9 @@ export class CraterView {
|
|
|
1133
1157
|
*
|
|
1134
1158
|
* You cannot revoke the key this client is authenticating with: it is refused with status
|
|
1135
1159
|
* 409, because it would leave you unable to make another. Create a replacement, move onto
|
|
1136
|
-
* it, then revoke this one.
|
|
1160
|
+
* it, then revoke this one. A key of the CraterView.ai app on an iPhone or iPad, which
|
|
1161
|
+
* `keys()` marks `app`, is refused with 409 too: those end when the person signs out in
|
|
1162
|
+
* the app.
|
|
1137
1163
|
*
|
|
1138
1164
|
* `keyId` is a key's `id` from `keys()` or `createKey()`, never its value or its prefix.
|
|
1139
1165
|
* Anything else throws a `CraterViewError` without a request being made.
|