@fuserstudio/sdk 0.0.2 → 0.0.3
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 +113 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
# @fuserstudio/sdk
|
|
2
2
|
|
|
3
|
-
The TypeScript SDK for the [Fuser](https://fuser.studio) API.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
The official TypeScript SDK for the [Fuser](https://fuser.studio) API.
|
|
4
|
+
|
|
5
|
+
Fuser is a node canvas for AI image, video, audio and 3D work. With this SDK
|
|
6
|
+
you build canvases, run them, and collect the results from code: the same
|
|
7
|
+
things the Fuser app and the Fuser MCP server do. Every API tool is a method
|
|
8
|
+
named after it (`canvas_edit` is `fuser.canvas.edit()`), with the same
|
|
9
|
+
arguments and results as the REST API, fully typed.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
6
12
|
|
|
7
13
|
```bash
|
|
8
14
|
npm install @fuserstudio/sdk
|
|
9
15
|
```
|
|
10
16
|
|
|
17
|
+
Works on Node 20.3+, Bun, Deno and Cloudflare Workers. It has no dependencies.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
11
21
|
```ts
|
|
12
22
|
import { Fuser } from '@fuserstudio/sdk';
|
|
13
23
|
|
|
@@ -34,7 +44,104 @@ const run = await fuser.run
|
|
|
34
44
|
console.log(run.nodes[0]?.outputs);
|
|
35
45
|
```
|
|
36
46
|
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
## What's in it
|
|
48
|
+
|
|
49
|
+
| Group | Methods | For |
|
|
50
|
+
| --------------- | ------------------------------------ | --------------------------------------------- |
|
|
51
|
+
| `fuser.account` | `get` | Credits, plan and workspaces |
|
|
52
|
+
| `fuser.canvas` | `list`, `get`, `edit`, `arrange` | Reading, changing and laying out canvases |
|
|
53
|
+
| `fuser.catalog` | `search` | Finding node types, their inputs and prices |
|
|
54
|
+
| `fuser.run` | `start`, `get`, `cancel`, `wait` | Pricing and running nodes |
|
|
55
|
+
| `fuser.media` | `search`, `view`, `import`, `export` | Your images and videos, and ZIP downloads |
|
|
56
|
+
| `fuser.upload` | `files`, `start`, `finish` | Sending local files to a canvas |
|
|
57
|
+
| `fuser.tool` | `search`, `build` | Tool nodes that crop, join, convert and so on |
|
|
58
|
+
|
|
59
|
+
## Authentication
|
|
60
|
+
|
|
61
|
+
Create an API key in Fuser and set it as `FUSER_API_KEY`, or pass it in:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const fuser = new Fuser({ apiKey: process.env.MY_FUSER_KEY });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
A key acts as you, so keep it on a server. The SDK refuses to run in a browser
|
|
68
|
+
unless you pass `dangerouslyAllowBrowser: true`.
|
|
69
|
+
|
|
70
|
+
## Waiting for runs and builds
|
|
71
|
+
|
|
72
|
+
`run.start()` and `tool.build()` answer straight away. Await them for that
|
|
73
|
+
first answer, or add `.wait()` to get the finished result:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const quote = await fuser.run.start({ canvasId, dryRun: true }); // price only
|
|
77
|
+
|
|
78
|
+
const run = await fuser.run.start({ canvasId, maxCredits: 200 }).wait();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`.wait()` gives up after 30 minutes for a run and 10 for a tool build; pass
|
|
82
|
+
`timeoutMs` or an `AbortSignal` to change that.
|
|
83
|
+
|
|
84
|
+
## Lists
|
|
85
|
+
|
|
86
|
+
List methods return one page when awaited and every item when iterated:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const firstPage = await fuser.canvas.list();
|
|
90
|
+
|
|
91
|
+
for await (const canvas of fuser.canvas.list()) {
|
|
92
|
+
console.log(canvas.title);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Uploading files
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { readFile } from 'node:fs/promises';
|
|
100
|
+
|
|
101
|
+
const [photo] = await fuser.upload.files(canvasId, [
|
|
102
|
+
{
|
|
103
|
+
fileName: 'bag.jpg',
|
|
104
|
+
data: await readFile('bag.jpg'),
|
|
105
|
+
contentType: 'image/jpeg',
|
|
106
|
+
},
|
|
107
|
+
]);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Errors
|
|
111
|
+
|
|
112
|
+
Every failure is a `FuserError` with the `tool` that failed, the HTTP `status`,
|
|
113
|
+
the API's `code` and a `requestId`. Subclasses say what went wrong:
|
|
114
|
+
`BadRequestError`, `AuthenticationError`, `PermissionDeniedError`,
|
|
115
|
+
`NotFoundError`, `ConflictError`, `RateLimitError`, `InternalServerError`,
|
|
116
|
+
`ConnectionError`, `TimeoutError` and `RunRefusedError`.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { ConflictError } from '@fuserstudio/sdk';
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
await fuser.canvas.edit({ canvasId, expectedRevision, diff });
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (error instanceof ConflictError && error.reason === 'stale_revision') {
|
|
125
|
+
// someone else changed the canvas: read it again and retry
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Retries and timeouts
|
|
132
|
+
|
|
133
|
+
Requests time out after 60 seconds and are retried twice. Change both on the
|
|
134
|
+
client or for one call:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
const fuser = new Fuser({ timeoutMs: 20_000, maxRetries: 0 });
|
|
138
|
+
|
|
139
|
+
await fuser.canvas.get({ canvasId }, { timeoutMs: 5_000 });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`beforeSend` and `afterSend` let you log or change each request, and `fetch`
|
|
143
|
+
swaps the HTTP client.
|
|
144
|
+
|
|
145
|
+
## Documentation
|
|
39
146
|
|
|
40
|
-
Full guide: https://docs.fuser.studio/docs/api/sdk
|
|
147
|
+
Full guide and API reference: https://docs.fuser.studio/docs/api/sdk
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuserstudio/sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "TypeScript SDK for the Fuser API.",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Official TypeScript SDK for the Fuser API: build and run AI image, video, audio and 3D canvases from code.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|