craterview 0.1.5 → 0.3.12

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.
Files changed (3) hide show
  1. package/README.md +24 -5
  2. package/index.ts +28 -35
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -31,12 +31,30 @@ const blob = await job.blob();
31
31
  API's shape rather than an accident, but it is not something every caller should have to
32
32
  reimplement.
33
33
 
34
+ Build against `echo` first. It costs no credits, needs no GPU and returns a real result — a
35
+ plain upscale — so the request, the parameters and the response are the ones a paid model
36
+ gives, and your integration needs no change when you switch. When you are ready, swap the
37
+ model name for the one you want.
38
+
39
+ ```ts
40
+ const job = await cv.run(file, {
41
+ // echo is free, for building against. Swap in a paid model when you are ready —
42
+ // cv-enhance-v3 to enlarge, cv-restore-v1 to repair, cv-headshot-v1 for portraits.
43
+ model: "echo",
44
+ scale: 2, wait: 30,
45
+ });
46
+ const blob = await job.blob();
47
+ ```
48
+
49
+ A parameter one model publishes is not one another accepts — `cv.models()` says which — and
50
+ a value a model does not publish is refused at submit rather than ignored.
51
+
34
52
  ## An API key
35
53
 
36
54
  Keys begin with `cv_` and are issued from your dashboard.
37
55
 
38
56
  ```ts
39
- const cv = new CraterView({ apiKey: process.env.CRATERVIEW_API_KEY });
57
+ const cv = new CraterView({ apiKey: process.env.CV_API_KEY });
40
58
  ```
41
59
 
42
60
  A key carries your whole allowance and does not expire. **Do not ship one to a browser** —
@@ -102,7 +120,8 @@ for (let attempt = 0; attempt < 3; attempt++) {
102
120
  Generating a fresh key per attempt defeats the point entirely — the server has nothing to
103
121
  match against and every attempt starts its own job. Reusing a key with a *different* body
104
122
  is rejected with 409 rather than quietly handing back the earlier result. Claims are kept
105
- for 24 hours; past that the same key starts new work.
123
+ for as long as the job's record is, which is not deleted; the same key always returns
124
+ the same job.
106
125
 
107
126
  ## Errors
108
127
 
@@ -111,7 +130,7 @@ Everything thrown by this client extends `CraterViewError`, so one `catch` handl
111
130
 
112
131
  | Class | Meaning |
113
132
  |---|---|
114
- | `RateLimited` | 429. `.retryAfter` is seconds until the window rolls over. |
133
+ | `RateLimited` | 429. `.retryAfter` is seconds to wait: until the window rolls over for the request rate, or a short fixed interval to poll on for the in-flight cap. |
115
134
  | `JobFailed` | The job ran and did not succeed. `.message` says what you can do about it; `.errorCode` is the half to branch on. |
116
135
  | `CraterViewError` | Everything else, including 4xx and 5xx from the API. |
117
136
 
@@ -131,7 +150,7 @@ Every field the API publishes on a job is exposed here.
131
150
  | `error` | Set when the job failed. Safe to show a user |
132
151
  | `errorCode` | The same fact, as a stable identifier. Branch on this, show the other |
133
152
  | `credits` | **What you were billed** |
134
- | `etaSeconds` | The estimate made at submit. Absent once the job has settled |
153
+ | `etaSeconds` | Seconds until the job is expected to finish, recomputed on every read — it counts down while the job runs. Absent once the job has settled |
135
154
  | `community` | True when the job is on the community queue: served after priority work, always taking a share of it, so it never stalls behind paid work |
136
155
  | `outputUrl`, `downloadUrl` | The result, presigned. One to display, one to save |
137
156
  | `thumbUrl` | A small JPEG of the result, for listings. Null when none was drawn |
@@ -247,7 +266,7 @@ old one. You cannot revoke the key you are calling with.
247
266
  ## Everything else
248
267
 
249
268
  ```ts
250
- await cv.models(); // models, parameter schemas, queue depth
269
+ await cv.models(); // models, parameter schemas, which queue you are on
251
270
  await cv.job("job_..."); // one job by id
252
271
  await cv.usage(); // credit balance, spend and job counts
253
272
 
package/index.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  // Mirrored from package.json, which is the number a release bumps. It cannot be imported
15
15
  // from there — this ships as TypeScript, so the import would have to resolve in the
16
16
  // consumer's toolchain — so test/version.test.ts asserts the two agree.
17
- export const VERSION = "0.1.5";
17
+ export const VERSION = "0.3.12";
18
18
  const DEFAULT_BASE_URL = "https://api.craterview.ai";
19
19
  // The server rejects a longer wait outright, so asking for one costs a 422 rather than the
20
20
  // wait you asked for. `run()` clamps to this rather than letting that happen.
@@ -70,11 +70,11 @@ export class CraterViewError extends Error {
70
70
  * request rate, and the account's cap on jobs queued or running at the same time, which
71
71
  * exists so one caller cannot occupy the whole fleet.
72
72
  *
73
- * `retryAfter` is seconds to wait, and how good a number it is depends on which limit you
74
- * hit: exact for the rate limit, where it is when the window rolls over, and a hint for
75
- * the in-flight cap, where a slot frees when one of your own jobs finishes and the server
76
- * can only quote the model's typical duration. `usage()` reports the cap and what you
77
- * currently hold against it.
73
+ * `retryAfter` is seconds to wait, and what it means depends on which limit you hit: for
74
+ * the rate limit it is when the window rolls over; for the in-flight cap it is a fixed
75
+ * short interval to poll on, since a slot frees when one of your own jobs finishes and
76
+ * nothing here predicts that. `usage()` reports the cap and what you currently hold
77
+ * against it.
78
78
  */
79
79
  export class RateLimited extends CraterViewError {
80
80
  constructor(message: string, readonly retryAfter?: number) {
@@ -275,18 +275,13 @@ export interface ModelInfo {
275
275
  credits_per_video_second?: number | null;
276
276
  reference_fps: number;
277
277
  params_schema: Record<string, unknown>;
278
- /**
279
- * Work ahead of you **on the queue your key would use** — not a platform-wide total.
280
- * Read it with `community`, which says which queue that is.
281
- */
282
- queue_depth: number;
283
278
  /**
284
279
  * Whether your key's work goes to the community queue, which is served after priority
285
- * work and always takes a share of it, so it never stalls behind paid work. False once
286
- * the account holds credit.
280
+ * work and always takes a share of it, so it never stalls behind paid work. False while
281
+ * the account is paying — holding credit, or on a subscription.
287
282
  *
288
- * The same field, meaning the same thing, as `Job.community` — these are the two places
289
- * the API describes a wait, and they describe it the same way.
283
+ * The same field, meaning the same thing, as `Job.community`. How long a wait will be
284
+ * is answered on the job, once you have one — `Job.eta_seconds` — and nowhere else.
290
285
  */
291
286
  community: boolean;
292
287
  /** Of `params_schema`, the ones that apply to still images only. */
@@ -303,7 +298,11 @@ export interface KeyInfo {
303
298
  /** When it stopped working, or null while it still does. */
304
299
  revoked_at: string | null;
305
300
  rate_limit_per_minute: number;
306
- /** Whether this is the key you are calling with. It cannot be revoked while it is. */
301
+ /**
302
+ * Whether this is the key you are calling with. It cannot be revoked by id while it is;
303
+ * `endCurrentKey()` (`DELETE /v1/keys/current`) ends it on request, unless it is the
304
+ * account's only way back in.
305
+ */
307
306
  current: boolean;
308
307
  }
309
308
 
@@ -317,20 +316,14 @@ export interface NewKey {
317
316
  rate_limit_per_minute: number;
318
317
  }
319
318
 
320
- /** The body of a callback, once {@link verifyWebhook} has checked it came from us. */
321
- export interface WebhookEvent {
322
- id: string;
323
- custom_id: string | null;
324
- model: string | null;
325
- status: JobStatus;
326
- error: string | null;
327
- error_code: string | null;
328
- community: boolean;
329
- credits: number | null;
330
- created_at: string | null;
331
- finished_at: string | null;
332
- result: Record<string, unknown> | null;
333
- }
319
+ /**
320
+ * The body of a callback, once {@link verifyWebhook} has checked it came from us.
321
+ *
322
+ * A job, delivered rather than fetched: the same fields a read of the job states, under the
323
+ * same names, every one present and null where it does not apply — so a receiver parses one
324
+ * shape rather than branching on which keys arrived.
325
+ */
326
+ export interface WebhookEvent extends Required<JobData> {}
334
327
 
335
328
  export type JobStatus = "queued" | "running" | "succeeded" | "failed";
336
329
 
@@ -552,14 +545,14 @@ export class CraterView {
552
545
  }
553
546
 
554
547
  /**
555
- * Available models: parameter schemas, prices, limits, and your queue.
548
+ * Available models: parameter schemas, prices, limits, and which queue you are on.
556
549
  *
557
550
  * Prices are published here, so the cost of a job is knowable before submitting it.
558
551
  *
559
- * Needs a key, and not only because the figures are live: `queue_depth` and `community`
560
- * are answered **for the queue your key would use**. The API looks up the account's
561
- * balance and reports the queue a job from this key would land in — so two keys asking
562
- * at the same moment can get different numbers, and buying credit changes yours.
552
+ * `community` and the limits are answered **for the queue your key would use**. The API
553
+ * looks up the account's standing and reports the queue a job from this key would land
554
+ * in — so two keys asking at the same moment can get different answers, and paying —
555
+ * credit or a subscription — changes yours.
563
556
  *
564
557
  * A model that is available is not always listed — a model in trial, or being retired,
565
558
  * stays usable by name while absent from this catalog.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craterview",
3
- "version": "0.1.5",
3
+ "version": "0.3.12",
4
4
  "dependencies": {},
5
5
  "description": "TypeScript client for the CraterView image enhancement API",
6
6
  "type": "module",