@hedra/sdk 5.0.0 → 5.2.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 +196 -49
- package/dist/cjs/BaseClient.d.ts +2 -2
- package/dist/cjs/BaseClient.js +3 -3
- package/dist/cjs/api/resources/billing/client/Client.js +3 -3
- package/dist/cjs/api/resources/files/client/Client.js +1 -1
- package/dist/cjs/api/resources/jobs/client/Client.d.ts +73 -0
- package/dist/cjs/api/resources/jobs/client/Client.js +274 -97
- package/dist/cjs/api/resources/jobs/client/requests/SubmitBodyCreatifyAurora.d.ts +24 -0
- package/dist/cjs/api/resources/jobs/client/requests/SubmitBodyCreatifyAurora.js +3 -0
- package/dist/cjs/api/resources/jobs/client/requests/SubmitBodyHeygenPhotoAvatar4.d.ts +25 -0
- package/dist/cjs/api/resources/jobs/client/requests/SubmitBodyHeygenPhotoAvatar4.js +3 -0
- package/dist/cjs/api/resources/jobs/client/requests/index.d.ts +2 -0
- package/dist/cjs/api/resources/keys/client/Client.js +4 -4
- package/dist/cjs/api/resources/logDrains/client/Client.js +6 -6
- package/dist/cjs/api/resources/models/client/Client.js +7 -7
- package/dist/cjs/api/resources/tokens/client/Client.js +1 -1
- package/dist/cjs/api/resources/webhooks/client/Client.js +7 -7
- package/dist/cjs/api/types/InputCreatifyAurora.d.ts +24 -0
- package/dist/cjs/api/types/InputCreatifyAurora.js +12 -0
- package/dist/cjs/api/types/InputCreatifyAuroraAudio.d.ts +23 -0
- package/dist/cjs/api/types/InputCreatifyAuroraAudio.js +3 -0
- package/dist/cjs/api/types/InputCreatifyAuroraStartImage.d.ts +23 -0
- package/dist/cjs/api/types/InputCreatifyAuroraStartImage.js +3 -0
- package/dist/cjs/api/types/InputGptImage2.d.ts +1 -1
- package/dist/cjs/api/types/InputHeygenPhotoAvatar4.d.ts +39 -0
- package/dist/cjs/api/types/InputHeygenPhotoAvatar4.js +24 -0
- package/dist/cjs/api/types/InputHeygenPhotoAvatar4Audio.d.ts +23 -0
- package/dist/cjs/api/types/InputHeygenPhotoAvatar4Audio.js +3 -0
- package/dist/cjs/api/types/InputHeygenPhotoAvatar4StartImage.d.ts +23 -0
- package/dist/cjs/api/types/InputHeygenPhotoAvatar4StartImage.js +3 -0
- package/dist/cjs/api/types/index.d.ts +6 -0
- package/dist/cjs/api/types/index.js +6 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +2 -2
- package/dist/esm/BaseClient.mjs +3 -3
- package/dist/esm/api/resources/billing/client/Client.mjs +3 -3
- package/dist/esm/api/resources/files/client/Client.mjs +1 -1
- package/dist/esm/api/resources/jobs/client/Client.d.mts +73 -0
- package/dist/esm/api/resources/jobs/client/Client.mjs +274 -97
- package/dist/esm/api/resources/jobs/client/requests/SubmitBodyCreatifyAurora.d.mts +24 -0
- package/dist/esm/api/resources/jobs/client/requests/SubmitBodyCreatifyAurora.mjs +2 -0
- package/dist/esm/api/resources/jobs/client/requests/SubmitBodyHeygenPhotoAvatar4.d.mts +25 -0
- package/dist/esm/api/resources/jobs/client/requests/SubmitBodyHeygenPhotoAvatar4.mjs +2 -0
- package/dist/esm/api/resources/jobs/client/requests/index.d.mts +2 -0
- package/dist/esm/api/resources/keys/client/Client.mjs +4 -4
- package/dist/esm/api/resources/logDrains/client/Client.mjs +6 -6
- package/dist/esm/api/resources/models/client/Client.mjs +7 -7
- package/dist/esm/api/resources/tokens/client/Client.mjs +1 -1
- package/dist/esm/api/resources/webhooks/client/Client.mjs +7 -7
- package/dist/esm/api/types/InputCreatifyAurora.d.mts +24 -0
- package/dist/esm/api/types/InputCreatifyAurora.mjs +9 -0
- package/dist/esm/api/types/InputCreatifyAuroraAudio.d.mts +23 -0
- package/dist/esm/api/types/InputCreatifyAuroraAudio.mjs +2 -0
- package/dist/esm/api/types/InputCreatifyAuroraStartImage.d.mts +23 -0
- package/dist/esm/api/types/InputCreatifyAuroraStartImage.mjs +2 -0
- package/dist/esm/api/types/InputGptImage2.d.mts +1 -1
- package/dist/esm/api/types/InputHeygenPhotoAvatar4.d.mts +39 -0
- package/dist/esm/api/types/InputHeygenPhotoAvatar4.mjs +21 -0
- package/dist/esm/api/types/InputHeygenPhotoAvatar4Audio.d.mts +23 -0
- package/dist/esm/api/types/InputHeygenPhotoAvatar4Audio.mjs +2 -0
- package/dist/esm/api/types/InputHeygenPhotoAvatar4StartImage.d.mts +23 -0
- package/dist/esm/api/types/InputHeygenPhotoAvatar4StartImage.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +6 -0
- package/dist/esm/api/types/index.mjs +6 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +2 -2
- package/reference.md +155 -0
package/README.md
CHANGED
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=Hedra%2FTypeScript)
|
|
4
4
|
[](https://www.npmjs.com/package/@hedra/sdk)
|
|
5
5
|
|
|
6
|
-
The Hedra TypeScript library provides convenient access to the Hedra
|
|
6
|
+
The Hedra TypeScript library provides convenient access to the Hedra API v3 from TypeScript and
|
|
7
|
+
JavaScript.
|
|
7
8
|
|
|
8
9
|
## Table of Contents
|
|
9
10
|
|
|
10
11
|
- [Installation](#installation)
|
|
11
12
|
- [Reference](#reference)
|
|
12
13
|
- [Usage](#usage)
|
|
14
|
+
- [Authentication](#authentication)
|
|
13
15
|
- [Custom base URL](#custom-base-url)
|
|
16
|
+
- [Resources](#resources)
|
|
14
17
|
- [Request and Response Types](#request-and-response-types)
|
|
18
|
+
- [Streaming](#streaming)
|
|
15
19
|
- [Pagination](#pagination)
|
|
16
20
|
- [Exception Handling](#exception-handling)
|
|
17
21
|
- [File Uploads](#file-uploads)
|
|
@@ -22,6 +26,7 @@ The Hedra TypeScript library provides convenient access to the Hedra APIs from T
|
|
|
22
26
|
- [Timeouts](#timeouts)
|
|
23
27
|
- [Aborting Requests](#aborting-requests)
|
|
24
28
|
- [Access Raw Response Data](#access-raw-response-data)
|
|
29
|
+
- [Spec Version Header](#spec-version-header)
|
|
25
30
|
- [Logging](#logging)
|
|
26
31
|
- [Custom Fetch](#custom-fetch)
|
|
27
32
|
- [Runtime Compatibility](#runtime-compatibility)
|
|
@@ -46,12 +51,12 @@ import { HedraClient } from "@hedra/sdk";
|
|
|
46
51
|
|
|
47
52
|
const client = new HedraClient({ apiKey: "YOUR_API_KEY" });
|
|
48
53
|
|
|
49
|
-
const submitted = await client.jobs.
|
|
54
|
+
const submitted = await client.jobs.submitMinimaxH3({
|
|
50
55
|
input: {
|
|
51
56
|
prompt: "a fox sprinting across fresh snow",
|
|
52
57
|
aspect_ratio: "16:9",
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
resolution: "768p",
|
|
59
|
+
duration_ms: 6000,
|
|
55
60
|
},
|
|
56
61
|
});
|
|
57
62
|
|
|
@@ -63,24 +68,66 @@ while (status.status === "IN_QUEUE" || status.status === "IN_PROGRESS") {
|
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
const result = await client.jobs.get(submitted.job_id);
|
|
66
|
-
|
|
71
|
+
for (const output of result.outputs ?? []) {
|
|
72
|
+
console.log(output.url);
|
|
73
|
+
}
|
|
67
74
|
```
|
|
68
75
|
|
|
69
|
-
Every model has its own submit method — `submitKlingO3`, `submitVeo3`,
|
|
70
|
-
and so on — each taking the `input` that model actually accepts, checked at
|
|
71
|
-
The [reference](./reference.md) lists all of them.
|
|
76
|
+
Every model has its own submit method — `submitMinimaxH3`, `submitKlingO3`, `submitVeo3`,
|
|
77
|
+
`submitNanoBanana` and so on — each taking the `input` that model actually accepts, checked at
|
|
78
|
+
compile time. The [reference](./reference.md) lists all of them.
|
|
79
|
+
|
|
80
|
+
To run a model by its public id instead, with an untyped `input` that the API validates at submit
|
|
81
|
+
time, use `client.jobs.submit(model, { input })`. This is the call to reach for when the model is
|
|
82
|
+
not known ahead of time, or when a client generated before a model shipped needs to run it:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const submitted = await client.jobs.submit("minimax-h3", {
|
|
86
|
+
input: {
|
|
87
|
+
prompt: "a fox sprinting across fresh snow",
|
|
88
|
+
aspect_ratio: "16:9",
|
|
89
|
+
resolution: "768p",
|
|
90
|
+
duration_ms: 6000,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
```
|
|
72
94
|
|
|
73
|
-
|
|
74
|
-
`
|
|
95
|
+
Every submit body also accepts two optional fields: `webhook`, a URL that receives a signed
|
|
96
|
+
completion webhook, and `idempotency_key`, which replays the original acknowledgement for a
|
|
97
|
+
retried submit instead of enqueueing a duplicate job.
|
|
98
|
+
|
|
99
|
+
Instead of polling you can follow the job over server-sent events; see [Streaming](#streaming).
|
|
100
|
+
|
|
101
|
+
## Authentication
|
|
75
102
|
|
|
76
103
|
The client authenticates with `Authorization: Bearer <api key>`; an API key is the
|
|
77
|
-
`<key_id>:<secret>` credential from the Hedra console.
|
|
78
|
-
|
|
104
|
+
`<key_id>:<secret>` credential from the Hedra console. The API key can also be provided via the
|
|
105
|
+
`HEDRA_API_KEY` environment variable, in which case `apiKey` may be omitted:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { HedraClient } from "@hedra/sdk";
|
|
109
|
+
|
|
110
|
+
// Reads HEDRA_API_KEY from the environment
|
|
111
|
+
const client = new HedraClient();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Ephemeral tokens minted with `client.tokens.create(...)` are valid Bearer credentials until they
|
|
115
|
+
expire; pass the returned `token` as `apiKey` to authenticate with one.
|
|
116
|
+
To take over header construction entirely, pass `auth` — either `false` to send no credentials,
|
|
117
|
+
or a function returning the headers to attach:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { HedraClient } from "@hedra/sdk";
|
|
121
|
+
|
|
122
|
+
const client = new HedraClient({
|
|
123
|
+
auth: async () => ({ headers: { Authorization: `Bearer ${await fetchTokenSomehow()}` } }),
|
|
124
|
+
});
|
|
125
|
+
```
|
|
79
126
|
|
|
80
127
|
## Custom base URL
|
|
81
128
|
|
|
82
|
-
The client targets `https://api.hedra.com/v3
|
|
83
|
-
elsewhere (e.g. a mock server in tests):
|
|
129
|
+
The client targets `https://api.hedra.com/v3` (`HedraEnvironment.Production`). Pass a URL as
|
|
130
|
+
`environment` to point elsewhere (e.g. a mock server in tests):
|
|
84
131
|
|
|
85
132
|
```typescript
|
|
86
133
|
import { HedraClient } from "@hedra/sdk";
|
|
@@ -90,6 +137,32 @@ const client = new HedraClient({
|
|
|
90
137
|
});
|
|
91
138
|
```
|
|
92
139
|
|
|
140
|
+
## Resources
|
|
141
|
+
|
|
142
|
+
The client exposes one sub-client per API resource:
|
|
143
|
+
|
|
144
|
+
| Sub-client | What it covers |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| `client.jobs` | Submit generation jobs (typed per model, or by id), poll status, fetch results, tail logs, stream progress, list history. |
|
|
147
|
+
| `client.models` | Browse the model catalog and each model's input schema, list voices, estimate cost, fetch the OpenAPI document. |
|
|
148
|
+
| `client.files` | Upload media to reference from a submit. |
|
|
149
|
+
| `client.keys` | List, create, rotate and revoke API keys. |
|
|
150
|
+
| `client.tokens` | Mint ephemeral Bearer tokens that expire on a schedule, for clients that should not hold a long-lived key. |
|
|
151
|
+
| `client.billing` | Balance, usage and transaction history. |
|
|
152
|
+
| `client.webhooks` | Manage and test the account's default completion webhook, list and redeliver deliveries, fetch the signing public key. |
|
|
153
|
+
| `client.logDrains` | Manage log drains that batch-forward job logs to an endpoint you own. |
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const catalog = await client.models.list({ modality: "video" });
|
|
157
|
+
const detail = await client.models.get("minimax-h3");
|
|
158
|
+
const balance = await client.billing.getBalance();
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Each resource is also published as a package subpath — `@hedra/sdk/jobs`, `@hedra/sdk/models`,
|
|
162
|
+
`@hedra/sdk/files`, `@hedra/sdk/keys`, `@hedra/sdk/tokens`, `@hedra/sdk/billing`,
|
|
163
|
+
`@hedra/sdk/webhooks`, `@hedra/sdk/logDrains` — exporting that resource's client class and
|
|
164
|
+
request types on their own.
|
|
165
|
+
|
|
93
166
|
## Request and Response Types
|
|
94
167
|
|
|
95
168
|
The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
|
|
@@ -98,15 +171,57 @@ following namespace:
|
|
|
98
171
|
```typescript
|
|
99
172
|
import { Hedra } from "@hedra/sdk";
|
|
100
173
|
|
|
101
|
-
const
|
|
102
|
-
|
|
174
|
+
const input: Hedra.InputMinimaxH3 = {
|
|
175
|
+
prompt: "a fox sprinting across fresh snow",
|
|
176
|
+
aspect_ratio: "16:9",
|
|
177
|
+
resolution: "768p",
|
|
178
|
+
duration_ms: 6000,
|
|
103
179
|
};
|
|
180
|
+
|
|
181
|
+
const request: Hedra.SubmitBodyMinimaxH3 = { input };
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Enum-valued fields are exported as `as const` objects alongside their types, so
|
|
185
|
+
`Hedra.InputMinimaxH3.Resolution.SevenHundredSixtyEightP` and the literal `"768p"` are
|
|
186
|
+
interchangeable. Response envelopes are typed the same way: `Hedra.SubmitResponse`,
|
|
187
|
+
`Hedra.StatusResponse`, `Hedra.ResultResponse`, `Hedra.OutputItem`, and `Hedra.JobStatus`
|
|
188
|
+
(`"IN_QUEUE" | "IN_PROGRESS" | "COMPLETED" | "FAILED"`).
|
|
189
|
+
|
|
190
|
+
## Streaming
|
|
191
|
+
|
|
192
|
+
`client.jobs.stream(job_id)` follows a job over server-sent events instead of polling. It resolves
|
|
193
|
+
to an async iterable that yields a `StatusResponse` for every `status` frame and a `JobLogItem` for
|
|
194
|
+
every `log` frame, and ends once the job reaches a terminal state:
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
// submitted is the SubmitResponse returned by any submit call
|
|
198
|
+
const stream = await client.jobs.stream(submitted.job_id);
|
|
199
|
+
for await (const event of stream) {
|
|
200
|
+
if ("status" in event) {
|
|
201
|
+
console.log(event.status, event.progress);
|
|
202
|
+
} else {
|
|
203
|
+
console.log(event.level, event.message);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
A dropped connection is resumed automatically from the last event id. Tune that with the `stream`
|
|
209
|
+
option, on the client or per request:
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
const client = new HedraClient({
|
|
213
|
+
stream: { reconnectionEnabled: true, maxReconnectionAttempts: 5 },
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const stream = await client.jobs.stream(submitted.job_id, {}, {
|
|
217
|
+
stream: { reconnectionEnabled: false },
|
|
218
|
+
});
|
|
104
219
|
```
|
|
105
220
|
|
|
106
221
|
## Pagination
|
|
107
222
|
|
|
108
|
-
|
|
109
|
-
|
|
223
|
+
Paginated requests return a `Page` that can be iterated asynchronously; it fetches cursor pages
|
|
224
|
+
lazily as you iterate:
|
|
110
225
|
|
|
111
226
|
```typescript
|
|
112
227
|
const page = await client.jobs.list({ limit: 50 });
|
|
@@ -115,21 +230,43 @@ for await (const job of page) {
|
|
|
115
230
|
}
|
|
116
231
|
```
|
|
117
232
|
|
|
233
|
+
You can also iterate page by page and access the typed response for each one:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
let page = await client.jobs.list({ limit: 50 });
|
|
237
|
+
while (true) {
|
|
238
|
+
console.log(page.response); // the typed JobListResponse for this page
|
|
239
|
+
for (const job of page.data) {
|
|
240
|
+
console.log(job.job_id);
|
|
241
|
+
}
|
|
242
|
+
if (!page.hasNextPage()) break;
|
|
243
|
+
page = await page.getNextPage();
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
118
247
|
## Exception Handling
|
|
119
248
|
|
|
120
|
-
When the API returns a non-success status code (4xx or 5xx response), a subclass of
|
|
121
|
-
|
|
249
|
+
When the API returns a non-success status code (4xx or 5xx response), a subclass of `HedraError` is
|
|
250
|
+
thrown. Each documented status has its own class under the `Hedra` namespace — `BadRequestError`,
|
|
251
|
+
`UnauthorizedError`, `PaymentRequiredError`, `ForbiddenError`, `NotFoundError`,
|
|
252
|
+
`UnprocessableEntityError`, `TooManyRequestsError` and `InternalServerError` — with a typed
|
|
253
|
+
`body`. A request that exceeds its timeout throws `HedraTimeoutError`.
|
|
122
254
|
|
|
123
255
|
```typescript
|
|
124
|
-
import { HedraError } from "@hedra/sdk";
|
|
256
|
+
import { Hedra, HedraError, HedraTimeoutError } from "@hedra/sdk";
|
|
125
257
|
|
|
126
258
|
try {
|
|
127
|
-
await client.jobs.
|
|
259
|
+
await client.jobs.get("job_does_not_exist");
|
|
128
260
|
} catch (err) {
|
|
129
|
-
if (err instanceof
|
|
261
|
+
if (err instanceof Hedra.NotFoundError) {
|
|
262
|
+
console.log(err.body); // typed Hedra.ErrorResponse
|
|
263
|
+
} else if (err instanceof HedraTimeoutError) {
|
|
264
|
+
console.log("timed out", err.cause);
|
|
265
|
+
} else if (err instanceof HedraError) {
|
|
130
266
|
console.log(err.statusCode);
|
|
131
267
|
console.log(err.message);
|
|
132
268
|
console.log(err.body);
|
|
269
|
+
console.log(err.requestId); // the response's x-request-id, if any
|
|
133
270
|
console.log(err.rawResponse);
|
|
134
271
|
}
|
|
135
272
|
}
|
|
@@ -137,17 +274,33 @@ try {
|
|
|
137
274
|
|
|
138
275
|
## File Uploads
|
|
139
276
|
|
|
140
|
-
|
|
277
|
+
Media inputs (`start_image`, `end_image`, `images`, `audio`, `video`, …) take either a public URL or
|
|
278
|
+
a file you uploaded first. `client.files.upload` stores the bytes and returns a presigned URL that is
|
|
279
|
+
the file's handle for the next hour; pass it back verbatim as a `url` source:
|
|
141
280
|
|
|
142
281
|
```typescript
|
|
143
282
|
import * as fs from "fs";
|
|
144
283
|
import { HedraClient } from "@hedra/sdk";
|
|
145
284
|
|
|
146
285
|
const client = new HedraClient({ apiKey: "YOUR_API_KEY" });
|
|
147
|
-
|
|
148
|
-
|
|
286
|
+
|
|
287
|
+
const upload = await client.files.upload({
|
|
288
|
+
file: fs.createReadStream("frame.png"),
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
await client.jobs.submitMinimaxH3({
|
|
292
|
+
input: {
|
|
293
|
+
prompt: "the fox turns toward the camera",
|
|
294
|
+
resolution: "768p",
|
|
295
|
+
duration_ms: 6000,
|
|
296
|
+
start_image: { source: "url", url: upload.url },
|
|
297
|
+
},
|
|
149
298
|
});
|
|
150
299
|
```
|
|
300
|
+
|
|
301
|
+
A completed job's outputs carry an `asset_id`; pass `{ source: "asset", asset_id }` instead of a
|
|
302
|
+
URL to reuse an output as the input to a later job.
|
|
303
|
+
|
|
151
304
|
The client accepts a variety of types for file upload parameters:
|
|
152
305
|
* Stream types: `fs.ReadStream`, `stream.Readable`, and `ReadableStream`
|
|
153
306
|
* Buffered types: `Buffer`, `Blob`, `File`, `ArrayBuffer`, `ArrayBufferView`, and `Uint8Array`
|
|
@@ -199,7 +352,7 @@ const client = new HedraClient({
|
|
|
199
352
|
}
|
|
200
353
|
});
|
|
201
354
|
|
|
202
|
-
const response = await client.jobs.
|
|
355
|
+
const response = await client.jobs.submitMinimaxH3(..., {
|
|
203
356
|
headers: {
|
|
204
357
|
'X-Custom-Header': 'custom value'
|
|
205
358
|
}
|
|
@@ -211,7 +364,7 @@ const response = await client.jobs.submitKlingO3(..., {
|
|
|
211
364
|
If you would like to send additional query string parameters as part of the request, use the `queryParams` request option.
|
|
212
365
|
|
|
213
366
|
```typescript
|
|
214
|
-
const response = await client.jobs.
|
|
367
|
+
const response = await client.jobs.submitMinimaxH3(..., {
|
|
215
368
|
queryParams: {
|
|
216
369
|
'customQueryParamKey': 'custom query param value'
|
|
217
370
|
}
|
|
@@ -222,26 +375,17 @@ const response = await client.jobs.submitKlingO3(..., {
|
|
|
222
375
|
|
|
223
376
|
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
|
|
224
377
|
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
|
|
225
|
-
retry limit (default: 2).
|
|
226
|
-
|
|
227
|
-
Which status codes are retried depends on the `retryStatusCodes` generator configuration:
|
|
378
|
+
retry limit (default: 2). A response is retryable when its status is:
|
|
228
379
|
|
|
229
|
-
**`legacy`** (current default): retries on
|
|
230
380
|
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
231
381
|
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
232
382
|
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (All server errors, including 500)
|
|
233
383
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
237
|
-
- [502](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502) (Bad Gateway)
|
|
238
|
-
- [503](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) (Service Unavailable)
|
|
239
|
-
- [504](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504) (Gateway Timeout)
|
|
240
|
-
|
|
241
|
-
Use the `maxRetries` request option to configure this behavior.
|
|
384
|
+
A `Retry-After` header is honoured when the server sends one. Use the `maxRetries` option, on the
|
|
385
|
+
client or per request, to configure this behavior.
|
|
242
386
|
|
|
243
387
|
```typescript
|
|
244
|
-
const response = await client.jobs.
|
|
388
|
+
const response = await client.jobs.submitMinimaxH3(..., {
|
|
245
389
|
maxRetries: 0 // override maxRetries at the request level
|
|
246
390
|
});
|
|
247
391
|
```
|
|
@@ -251,7 +395,7 @@ const response = await client.jobs.submitKlingO3(..., {
|
|
|
251
395
|
The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
|
|
252
396
|
|
|
253
397
|
```typescript
|
|
254
|
-
const response = await client.jobs.
|
|
398
|
+
const response = await client.jobs.submitMinimaxH3(..., {
|
|
255
399
|
timeoutInSeconds: 30 // override timeout to 30s
|
|
256
400
|
});
|
|
257
401
|
```
|
|
@@ -262,7 +406,7 @@ The SDK allows users to abort requests at any point by passing in an abort signa
|
|
|
262
406
|
|
|
263
407
|
```typescript
|
|
264
408
|
const controller = new AbortController();
|
|
265
|
-
const response = await client.jobs.
|
|
409
|
+
const response = await client.jobs.submitMinimaxH3(..., {
|
|
266
410
|
abortSignal: controller.signal
|
|
267
411
|
});
|
|
268
412
|
controller.abort(); // aborts the request
|
|
@@ -274,12 +418,19 @@ The SDK provides access to raw response data, including headers, through the `.w
|
|
|
274
418
|
The `.withRawResponse()` method returns a promise that results to an object with a `data` and a `rawResponse` property.
|
|
275
419
|
|
|
276
420
|
```typescript
|
|
277
|
-
const { data, rawResponse } = await client.jobs.
|
|
421
|
+
const { data, rawResponse } = await client.jobs.submitMinimaxH3(...).withRawResponse();
|
|
278
422
|
|
|
279
423
|
console.log(data);
|
|
280
|
-
console.log(rawResponse.headers
|
|
424
|
+
console.log(rawResponse.headers.get("x-request-id"));
|
|
281
425
|
```
|
|
282
426
|
|
|
427
|
+
### Spec Version Header
|
|
428
|
+
|
|
429
|
+
Every request carries an `X-Hedra-Spec-Version` header naming the OpenAPI spec version this client
|
|
430
|
+
was generated from, so the server can tell which generation of the API a caller was built against.
|
|
431
|
+
It is sent automatically; the `specVersion` option that backs it is typed to the pinned version, so
|
|
432
|
+
there is nothing to configure.
|
|
433
|
+
|
|
283
434
|
### Logging
|
|
284
435
|
|
|
285
436
|
The SDK supports logging. You can configure the logger by passing in a `logging` object to the client options.
|
|
@@ -382,11 +533,8 @@ other than your configured base.
|
|
|
382
533
|
|
|
383
534
|
### Runtime Compatibility
|
|
384
535
|
|
|
385
|
-
|
|
386
536
|
The SDK works in the following runtimes:
|
|
387
537
|
|
|
388
|
-
|
|
389
|
-
|
|
390
538
|
- Node.js 18+
|
|
391
539
|
- Vercel
|
|
392
540
|
- Cloudflare Workers
|
|
@@ -394,7 +542,6 @@ The SDK works in the following runtimes:
|
|
|
394
542
|
- Bun 1.0+
|
|
395
543
|
- React Native
|
|
396
544
|
|
|
397
|
-
|
|
398
545
|
## Contributing
|
|
399
546
|
|
|
400
547
|
While we value open-source contributions to this SDK, this library is generated programmatically.
|
package/dist/cjs/BaseClient.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type BaseClientOptions = {
|
|
|
7
7
|
/** Specify a custom URL to connect the client to. */
|
|
8
8
|
baseUrl?: core.Supplier<string>;
|
|
9
9
|
/** Override the X-Hedra-Spec-Version header */
|
|
10
|
-
specVersion?: "3.16.
|
|
10
|
+
specVersion?: "3.16.2";
|
|
11
11
|
/** Additional headers to include in requests. */
|
|
12
12
|
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
13
13
|
/** The default maximum time to wait for a response in seconds. */
|
|
@@ -34,7 +34,7 @@ export interface BaseRequestOptions {
|
|
|
34
34
|
/** A hook to abort the request. */
|
|
35
35
|
abortSignal?: AbortSignal;
|
|
36
36
|
/** Override the X-Hedra-Spec-Version header */
|
|
37
|
-
specVersion?: "3.16.
|
|
37
|
+
specVersion?: "3.16.2";
|
|
38
38
|
/** Additional query string parameters to include in the request. */
|
|
39
39
|
queryParams?: Record<string, unknown>;
|
|
40
40
|
/** A dictionary containing additional parameters to spread into the request's body. */
|
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -44,11 +44,11 @@ function normalizeClientOptions(options) {
|
|
|
44
44
|
const headers = (0, headers_js_1.mergeHeaders)({
|
|
45
45
|
"X-Fern-Language": "JavaScript",
|
|
46
46
|
"X-Fern-SDK-Name": "@hedra/sdk",
|
|
47
|
-
"X-Fern-SDK-Version": "5.
|
|
48
|
-
"User-Agent": "hedra-node/5.
|
|
47
|
+
"X-Fern-SDK-Version": "5.2.0",
|
|
48
|
+
"User-Agent": "hedra-node/5.2.0",
|
|
49
49
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
50
50
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
51
|
-
"X-Hedra-Spec-Version": (_a = options === null || options === void 0 ? void 0 : options.specVersion) !== null && _a !== void 0 ? _a : "3.16.
|
|
51
|
+
"X-Hedra-Spec-Version": (_a = options === null || options === void 0 ? void 0 : options.specVersion) !== null && _a !== void 0 ? _a : "3.16.2",
|
|
52
52
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
|
53
53
|
return Object.assign(Object.assign({}, options), { logging: core.logging.createLogger(options === null || options === void 0 ? void 0 : options.logging), headers });
|
|
54
54
|
}
|
|
@@ -80,7 +80,7 @@ class BillingClient {
|
|
|
80
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
81
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
82
82
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
83
|
-
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "X-Hedra-Spec-Version": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.specVersion) !== null && _b !== void 0 ? _b : "3.16.
|
|
83
|
+
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "X-Hedra-Spec-Version": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.specVersion) !== null && _b !== void 0 ? _b : "3.16.2" }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
84
84
|
const _response = yield core.fetcher({
|
|
85
85
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.HedraEnvironment.Production, "balance"),
|
|
86
86
|
method: "GET",
|
|
@@ -149,7 +149,7 @@ class BillingClient {
|
|
|
149
149
|
group_by: groupBy != null ? groupBy : undefined,
|
|
150
150
|
};
|
|
151
151
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
152
|
-
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "X-Hedra-Spec-Version": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.specVersion) !== null && _b !== void 0 ? _b : "3.16.
|
|
152
|
+
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "X-Hedra-Spec-Version": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.specVersion) !== null && _b !== void 0 ? _b : "3.16.2" }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
153
153
|
const _response = yield core.fetcher({
|
|
154
154
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.HedraEnvironment.Production, "usage"),
|
|
155
155
|
method: "GET",
|
|
@@ -225,7 +225,7 @@ class BillingClient {
|
|
|
225
225
|
cursor,
|
|
226
226
|
};
|
|
227
227
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
228
|
-
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "X-Hedra-Spec-Version": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.specVersion) !== null && _b !== void 0 ? _b : "3.16.
|
|
228
|
+
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "X-Hedra-Spec-Version": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.specVersion) !== null && _b !== void 0 ? _b : "3.16.2" }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
229
229
|
const _response = yield core.fetcher({
|
|
230
230
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.HedraEnvironment.Production, "transactions"),
|
|
231
231
|
method: "GET",
|
|
@@ -90,7 +90,7 @@ class FilesClient {
|
|
|
90
90
|
yield _body.appendFile("file", request.file);
|
|
91
91
|
const _maybeEncodedRequest = yield _body.getRequest();
|
|
92
92
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
93
|
-
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)(Object.assign({ "X-Hedra-Spec-Version": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.specVersion) !== null && _b !== void 0 ? _b : "3.16.
|
|
93
|
+
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)(Object.assign({ "X-Hedra-Spec-Version": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.specVersion) !== null && _b !== void 0 ? _b : "3.16.2" }, _maybeEncodedRequest.headers)), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
94
94
|
const _response = yield core.fetcher({
|
|
95
95
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.HedraEnvironment.Production, "files"),
|
|
96
96
|
method: "POST",
|
|
@@ -88,6 +88,42 @@ export declare class JobsClient {
|
|
|
88
88
|
listJobLogs(job_id: string, request?: Hedra.JobsListJobLogsRequest, requestOptions?: JobsClient.RequestOptions): Promise<core.Page<Hedra.JobLogItem, Hedra.JobLogListResponse>>;
|
|
89
89
|
stream(job_id: string, request?: Hedra.JobsStreamRequest, requestOptions?: JobsClient.RequestOptions): core.HttpResponsePromise<core.Stream<Hedra.JobsStreamResponse>>;
|
|
90
90
|
private __stream;
|
|
91
|
+
/**
|
|
92
|
+
* Create high-fidelity speaking or singing avatar videos.
|
|
93
|
+
*
|
|
94
|
+
* Submits an asynchronous job and returns `202` with a job id. Fetch the result at `GET /v3/jobs/{job_id}` — each item in its `outputs[]` follows the `OutputItem` schema — or track progress via `GET /v3/jobs/{job_id}/status` / the SSE stream at `GET /v3/jobs/{job_id}/stream`.
|
|
95
|
+
*
|
|
96
|
+
* @param {Hedra.SubmitBodyCreatifyAurora} request
|
|
97
|
+
* @param {JobsClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
98
|
+
*
|
|
99
|
+
* @throws {@link Hedra.BadRequestError}
|
|
100
|
+
* @throws {@link Hedra.UnauthorizedError}
|
|
101
|
+
* @throws {@link Hedra.PaymentRequiredError}
|
|
102
|
+
* @throws {@link Hedra.ForbiddenError}
|
|
103
|
+
* @throws {@link Hedra.NotFoundError}
|
|
104
|
+
* @throws {@link Hedra.UnprocessableEntityError}
|
|
105
|
+
* @throws {@link Hedra.TooManyRequestsError}
|
|
106
|
+
* @throws {@link Hedra.InternalServerError}
|
|
107
|
+
* @throws {@link errors.HedraError}
|
|
108
|
+
* @throws {@link errors.HedraTimeoutError}
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* await client.jobs.submitCreatifyAurora({
|
|
112
|
+
* input: {
|
|
113
|
+
* resolution: "480p",
|
|
114
|
+
* start_image: {
|
|
115
|
+
* source: "url",
|
|
116
|
+
* url: "url"
|
|
117
|
+
* },
|
|
118
|
+
* audio: {
|
|
119
|
+
* source: "url",
|
|
120
|
+
* url: "url"
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
* })
|
|
124
|
+
*/
|
|
125
|
+
submitCreatifyAurora(request: Hedra.SubmitBodyCreatifyAurora, requestOptions?: JobsClient.RequestOptions): core.HttpResponsePromise<Hedra.SubmitResponse>;
|
|
126
|
+
private __submitCreatifyAurora;
|
|
91
127
|
/**
|
|
92
128
|
* Polished, print-ready stills when the brief is a finished image rather than a sketch.
|
|
93
129
|
*
|
|
@@ -991,6 +1027,43 @@ export declare class JobsClient {
|
|
|
991
1027
|
*/
|
|
992
1028
|
submitHedraCharacter3(request: Hedra.SubmitBodyHedraCharacter3, requestOptions?: JobsClient.RequestOptions): core.HttpResponsePromise<Hedra.SubmitResponse>;
|
|
993
1029
|
private __submitHedraCharacter3;
|
|
1030
|
+
/**
|
|
1031
|
+
* Turn a clear portrait and driving audio into a talking avatar.
|
|
1032
|
+
*
|
|
1033
|
+
* Submits an asynchronous job and returns `202` with a job id. Fetch the result at `GET /v3/jobs/{job_id}` — each item in its `outputs[]` follows the `OutputItem` schema — or track progress via `GET /v3/jobs/{job_id}/status` / the SSE stream at `GET /v3/jobs/{job_id}/stream`.
|
|
1034
|
+
*
|
|
1035
|
+
* @param {Hedra.SubmitBodyHeygenPhotoAvatar4} request
|
|
1036
|
+
* @param {JobsClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
1037
|
+
*
|
|
1038
|
+
* @throws {@link Hedra.BadRequestError}
|
|
1039
|
+
* @throws {@link Hedra.UnauthorizedError}
|
|
1040
|
+
* @throws {@link Hedra.PaymentRequiredError}
|
|
1041
|
+
* @throws {@link Hedra.ForbiddenError}
|
|
1042
|
+
* @throws {@link Hedra.NotFoundError}
|
|
1043
|
+
* @throws {@link Hedra.UnprocessableEntityError}
|
|
1044
|
+
* @throws {@link Hedra.TooManyRequestsError}
|
|
1045
|
+
* @throws {@link Hedra.InternalServerError}
|
|
1046
|
+
* @throws {@link errors.HedraError}
|
|
1047
|
+
* @throws {@link errors.HedraTimeoutError}
|
|
1048
|
+
*
|
|
1049
|
+
* @example
|
|
1050
|
+
* await client.jobs.submitHeygenPhotoAvatar4({
|
|
1051
|
+
* input: {
|
|
1052
|
+
* aspect_ratio: "16:9",
|
|
1053
|
+
* resolution: "360p",
|
|
1054
|
+
* start_image: {
|
|
1055
|
+
* source: "url",
|
|
1056
|
+
* url: "url"
|
|
1057
|
+
* },
|
|
1058
|
+
* audio: {
|
|
1059
|
+
* source: "url",
|
|
1060
|
+
* url: "url"
|
|
1061
|
+
* }
|
|
1062
|
+
* }
|
|
1063
|
+
* })
|
|
1064
|
+
*/
|
|
1065
|
+
submitHeygenPhotoAvatar4(request: Hedra.SubmitBodyHeygenPhotoAvatar4, requestOptions?: JobsClient.RequestOptions): core.HttpResponsePromise<Hedra.SubmitResponse>;
|
|
1066
|
+
private __submitHeygenPhotoAvatar4;
|
|
994
1067
|
/**
|
|
995
1068
|
* HiDream.ai's open-weights HiDream-O1-Image (8B): one pixel-native model that generates, edits, and personalizes without a VAE or a separate text encoder.
|
|
996
1069
|
*
|