segmind 0.2.4 → 0.4.0
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 +57 -4
- package/dist/index.cjs +243 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +284 -84
- package/dist/index.d.ts +284 -84
- package/dist/index.js +243 -50
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,11 +51,24 @@ const image = new Uint8Array(await response.arrayBuffer()); // or response.json(
|
|
|
51
51
|
const job = await segmind.submit('seedance-2.0', { prompt: 'A sunset timelapse' });
|
|
52
52
|
console.log(job.requestId);
|
|
53
53
|
|
|
54
|
-
const result = await job.wait({
|
|
54
|
+
const result = await job.wait({
|
|
55
|
+
timeout: 15 * 60_000,
|
|
56
|
+
interval: (elapsed) => (elapsed < 30_000 ? 2_000 : 5_000), // or a fixed number of ms
|
|
57
|
+
onStatus: (status) => console.log(status.status),
|
|
58
|
+
});
|
|
55
59
|
```
|
|
56
60
|
|
|
57
61
|
A submit carries an `X-Request-ID`. If the connection drops, the SDK sends it again with the same id, and the gateway returns the existing request instead of starting (and billing) a second one. Pass your own `requestId` to make a submit idempotent across restarts.
|
|
58
62
|
|
|
63
|
+
To pick a job up later, such as after a page reload, keep its id and rebuild it:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const job = segmind.job(savedRequestId);
|
|
67
|
+
const result = await job.wait();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The result is kept for about an hour, and only for the user who submitted the job. Anything else reads as a `SegmindError` with status 404.
|
|
71
|
+
|
|
59
72
|
## Chat with an LLM
|
|
60
73
|
|
|
61
74
|
```ts
|
|
@@ -109,16 +122,27 @@ logo.persistent; // true
|
|
|
109
122
|
|
|
110
123
|
Persistent uploads take images, video, audio, PDF and common document types, up to 2 GB each.
|
|
111
124
|
|
|
125
|
+
## Models
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const page = await segmind.models.list({ q: 'upscale', output: 'image', limit: 20 });
|
|
129
|
+
page.models; // slug, name, category, average_cost, latency_seconds, ...
|
|
130
|
+
const videoModels = await segmind.models.listAll({ output: 'video', sort: 'cheapest' });
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`list` returns one page (`has_more`, `offset`, `total`); `listAll` reads every page. `average_cost` is observed spend, not the list price.
|
|
134
|
+
|
|
112
135
|
## Generations
|
|
113
136
|
|
|
114
137
|
```ts
|
|
115
138
|
const page = await segmind.generations.list({ modelName: 'flux-schnell' });
|
|
116
139
|
const history = await segmind.generations.history({ status: 'FAILED', perPage: 50 }); // failures included
|
|
140
|
+
const fromKey = await segmind.generations.history({ keySuffix: 'a1b2c3', initiator: ['API', 'API_V2'] });
|
|
117
141
|
const one = await segmind.generations.get(requestId);
|
|
118
142
|
const latest = await segmind.generations.recent('flux-schnell');
|
|
119
143
|
```
|
|
120
144
|
|
|
121
|
-
`history` lists one row per output, each with the request's full cost: de-duplicate on `request_id` before summing `credits_deduction`.
|
|
145
|
+
`history` lists one row per output, each with the request's full cost: de-duplicate on `request_id` before summing `credits_deduction`. Each row carries its `initiator` and the `key_mask` of the key that made it. Filter by key with `keySuffix`, the last 6 characters of the key: the full key is never sent.
|
|
122
146
|
|
|
123
147
|
## Webhooks
|
|
124
148
|
|
|
@@ -126,12 +150,16 @@ const latest = await segmind.generations.recent('flux-schnell');
|
|
|
126
150
|
const hook = await segmind.webhooks.add('https://example.com/hooks/segmind', ['PIXELFLOW']);
|
|
127
151
|
const hooks = await segmind.webhooks.get(); // each with its signing_secret
|
|
128
152
|
await segmind.webhooks.update(hook.id, 'https://example.com/hooks/v2'); // URL only
|
|
129
|
-
await segmind.webhooks.
|
|
153
|
+
await segmind.webhooks.test(hook.id); // a WEBHOOK_TEST delivery
|
|
154
|
+
const deliveries = await segmind.webhooks.logs(hook.id);
|
|
155
|
+
await segmind.webhooks.resend(deliveries[0].id); // that payload again
|
|
130
156
|
await segmind.webhooks.delete(hook.id);
|
|
131
157
|
```
|
|
132
158
|
|
|
133
159
|
Event types are subscription types: `PIXELFLOW` for PixelFlow runs, plus `WORKFLOW`, `INFERENCE` and `FINETUNE`. `update` changes the URL only; to change the event types, `delete` the registration and `add` a new one. Before 0.2.4, `update` registered a second hook and `delete` deactivated nothing, so check `webhooks.get()` for registrations left behind.
|
|
134
160
|
|
|
161
|
+
`test` and `resend` each send a real delivery, in the background after they return: read `logs` to see how your endpoint answered. Neither is retried, since every attempt is another delivery.
|
|
162
|
+
|
|
135
163
|
## PixelFlow workflows
|
|
136
164
|
|
|
137
165
|
```ts
|
|
@@ -144,6 +172,14 @@ const done = await job.wait({ timeout: 20 * 60_000, interval: 5_000 });
|
|
|
144
172
|
|
|
145
173
|
The slug is the workflow's API slug from its API tab, and inputs are keyed by each input's keyname. Runs use the current workflow engine; pass `{ engine: 'v1' }` for the legacy one. A failed run throws `InferenceFailed` whose `detail` names the node that failed. A submit is never retried, because a run bills.
|
|
146
174
|
|
|
175
|
+
## Credits
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
const { credits, freeCredits } = await segmind.accounts.credits();
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`credits` is the stored balance of the account or team making the request. Credits held by requests still running are not taken off.
|
|
182
|
+
|
|
147
183
|
## Errors
|
|
148
184
|
|
|
149
185
|
| Error | When |
|
|
@@ -152,8 +188,10 @@ The slug is the workflow's API slug from its API tab, and inputs are keyed by ea
|
|
|
152
188
|
| `APIConnectionError` | No response: network failure or the client timeout |
|
|
153
189
|
| `InferenceFailed` | A queued request reached `FAILED`; `detail` holds the reason |
|
|
154
190
|
| `InferenceTimeout` | `wait()` passed its timeout. The request may still finish: call `job.wait()` again |
|
|
191
|
+
| `InsufficientCredits` | The account can't pay for the request, at submit or as a failed job. `detail` holds the reason |
|
|
192
|
+
| `RateLimited` | Too many requests, after any retries. `retryAfterMs` is set when the server sent `Retry-After` and the runtime could read it |
|
|
155
193
|
|
|
156
|
-
Reads and
|
|
194
|
+
Reads, polls and queued submits retry connection errors and `429`, `502`, `503` and `504`, honouring `Retry-After`; reads also retry `408`.
|
|
157
195
|
|
|
158
196
|
## Options
|
|
159
197
|
|
|
@@ -164,6 +202,8 @@ new Segmind({
|
|
|
164
202
|
timeout: 600_000, // ms per HTTP request
|
|
165
203
|
maxRetries: 2,
|
|
166
204
|
fetch: customFetch, // any fetch implementation
|
|
205
|
+
initiator: 'API', // how these requests are labelled in usage history; default SDK-JS
|
|
206
|
+
initiatorId: 'batch-42', // what they belong to, also settable per call
|
|
167
207
|
});
|
|
168
208
|
```
|
|
169
209
|
|
|
@@ -171,6 +211,19 @@ new Segmind({
|
|
|
171
211
|
|
|
172
212
|
The constructor refuses an API key in a browser or React Native app, because every user of the app could read it. Call Segmind from your backend. Pass `dangerouslyAllowBrowser: true` only for internal tools where that is acceptable.
|
|
173
213
|
|
|
214
|
+
### Signed-in Segmind users
|
|
215
|
+
|
|
216
|
+
An app where people sign in with their Segmind account can send the user's own session token instead of an API key. This works in a browser, because the token only reaches what that user could do anyway.
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
const segmind = new Segmind({
|
|
220
|
+
tokenProvider: () => auth.getToken(), // called before every request
|
|
221
|
+
onUnauthorized: () => auth.refresh(), // on a 401; a new token retries the request once
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Pass `apiKey` or `tokenProvider`, not both.
|
|
226
|
+
|
|
174
227
|
## License
|
|
175
228
|
|
|
176
229
|
Apache-2.0
|