@inferencesh/sdk 0.4.27 → 0.5.1
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 +62 -3
- package/dist/api/apps.d.ts +1 -11
- package/dist/types.d.ts +37 -65
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
# @inferencesh/sdk
|
|
1
|
+
# @inferencesh/sdk — ai inference api for javascript & typescript
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@inferencesh/sdk)
|
|
4
4
|
[](https://www.npmjs.com/package/@inferencesh/sdk)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
official javascript/typescript sdk for [inference.sh](https://inference.sh) — the ai agent runtime for serverless ai inference.
|
|
9
|
+
|
|
10
|
+
run ai models, build ai agents, and deploy generative ai applications with a simple api. access 150+ models including flux, stable diffusion, llms (claude, gpt, gemini), video generation (veo, seedance), and more.
|
|
9
11
|
|
|
10
12
|
## Installation
|
|
11
13
|
|
|
@@ -149,6 +151,53 @@ const task = await client.tasks.run(
|
|
|
149
151
|
await client.tasks.cancel(task.id);
|
|
150
152
|
```
|
|
151
153
|
|
|
154
|
+
### Sessions (Stateful Execution)
|
|
155
|
+
|
|
156
|
+
Sessions allow you to maintain state across multiple task invocations. The worker stays warm between calls, preserving loaded models and in-memory state.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Start a new session
|
|
160
|
+
const result = await client.tasks.run({
|
|
161
|
+
app: 'my-stateful-app',
|
|
162
|
+
input: { prompt: 'hello' },
|
|
163
|
+
session: 'new'
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const sessionId = result.session_id;
|
|
167
|
+
console.log('Session ID:', sessionId);
|
|
168
|
+
|
|
169
|
+
// Continue the session with another call
|
|
170
|
+
const result2 = await client.tasks.run({
|
|
171
|
+
app: 'my-stateful-app',
|
|
172
|
+
input: { prompt: 'remember what I said?' },
|
|
173
|
+
session: sessionId
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Custom Session Timeout
|
|
178
|
+
|
|
179
|
+
By default, sessions expire after 60 seconds of inactivity. You can customize this with `session_timeout` (1-3600 seconds):
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
// Create a session with 5-minute idle timeout
|
|
183
|
+
const result = await client.tasks.run({
|
|
184
|
+
app: 'my-stateful-app',
|
|
185
|
+
input: { prompt: 'hello' },
|
|
186
|
+
session: 'new',
|
|
187
|
+
session_timeout: 300 // 5 minutes
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Session stays alive for 5 minutes after each call
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**Notes:**
|
|
194
|
+
- `session_timeout` is only valid when `session: 'new'`
|
|
195
|
+
- Minimum timeout: 1 second
|
|
196
|
+
- Maximum timeout: 3600 seconds (1 hour)
|
|
197
|
+
- Each successful call resets the idle timer
|
|
198
|
+
|
|
199
|
+
For complete session documentation including error handling, best practices, and advanced patterns, see the [Sessions Developer Guide](https://inference.sh/docs/extend/sessions).
|
|
200
|
+
|
|
152
201
|
## Agent Chat
|
|
153
202
|
|
|
154
203
|
Chat with AI agents using `client.agents.create()`.
|
|
@@ -252,6 +301,8 @@ Runs a task on inference.sh.
|
|
|
252
301
|
| `params.setup` | `object` | No | Setup parameters (affects worker warmth/scheduling) |
|
|
253
302
|
| `params.infra` | `string` | No | Infrastructure: `'cloud'` or `'private'` |
|
|
254
303
|
| `params.variant` | `string` | No | App variant to use |
|
|
304
|
+
| `params.session` | `string` | No | Session ID or `'new'` to start a new session |
|
|
305
|
+
| `params.session_timeout` | `number` | No | Session timeout in seconds (1-3600, only with `session: 'new'`) |
|
|
255
306
|
|
|
256
307
|
**Options:**
|
|
257
308
|
|
|
@@ -331,6 +382,14 @@ import type { Task, ApiTaskRequest, RunOptions } from '@inferencesh/sdk';
|
|
|
331
382
|
- Node.js 18.0.0 or higher
|
|
332
383
|
- Modern browsers with `fetch` support
|
|
333
384
|
|
|
334
|
-
##
|
|
385
|
+
## resources
|
|
386
|
+
|
|
387
|
+
- [documentation](https://inference.sh/docs) — getting started guides and api reference
|
|
388
|
+
- [blog](https://inference.sh/blog) — tutorials on ai agents, image generation, and more
|
|
389
|
+
- [app store](https://app.inference.sh) — browse 150+ ai models
|
|
390
|
+
- [discord](https://discord.gg/RM77SWSbyT) — community support
|
|
391
|
+
- [github](https://github.com/inference-sh) — open source projects
|
|
392
|
+
|
|
393
|
+
## license
|
|
335
394
|
|
|
336
395
|
MIT © [inference.sh](https://inference.sh)
|
package/dist/api/apps.d.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { HttpClient } from '../http/client';
|
|
2
|
-
import { AppDTO as App, AppVersionDTO, CursorListRequest, CursorListResponse } from '../types';
|
|
3
|
-
interface LicenseRecord {
|
|
4
|
-
id: string;
|
|
5
|
-
created_at: string;
|
|
6
|
-
updated_at: string;
|
|
7
|
-
deleted_at?: string;
|
|
8
|
-
user_id: string;
|
|
9
|
-
app_id: string;
|
|
10
|
-
license: string;
|
|
11
|
-
}
|
|
2
|
+
import { AppDTO as App, AppVersionDTO, CursorListRequest, CursorListResponse, LicenseRecord } from '../types';
|
|
12
3
|
/**
|
|
13
4
|
* Apps API
|
|
14
5
|
*/
|
|
@@ -69,4 +60,3 @@ export declare class AppsAPI {
|
|
|
69
60
|
saveLicense(appId: string, license: string): Promise<LicenseRecord>;
|
|
70
61
|
}
|
|
71
62
|
export declare function createAppsAPI(http: HttpClient): AppsAPI;
|
|
72
|
-
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -192,9 +192,7 @@ export interface AgentImages {
|
|
|
192
192
|
thumbnail: string;
|
|
193
193
|
banner: string;
|
|
194
194
|
}
|
|
195
|
-
export interface Agent {
|
|
196
|
-
BaseModel: BaseModel;
|
|
197
|
-
PermissionModel: PermissionModel;
|
|
195
|
+
export interface Agent extends BaseModel, PermissionModel {
|
|
198
196
|
ProjectModel: ProjectModel;
|
|
199
197
|
/**
|
|
200
198
|
* Basic info
|
|
@@ -261,14 +259,8 @@ export interface AgentConfig {
|
|
|
261
259
|
*/
|
|
262
260
|
output_schema?: any;
|
|
263
261
|
}
|
|
264
|
-
export interface AgentVersion {
|
|
265
|
-
BaseModel: BaseModel;
|
|
266
|
-
PermissionModel: PermissionModel;
|
|
262
|
+
export interface AgentVersion extends BaseModel, PermissionModel {
|
|
267
263
|
agent_id: string;
|
|
268
|
-
/**
|
|
269
|
-
* Short ID for human-readable version references (e.g., "abc123")
|
|
270
|
-
*/
|
|
271
|
-
short_id: string;
|
|
272
264
|
/**
|
|
273
265
|
* ConfigHash for deduplication - SHA256 of config content
|
|
274
266
|
*/
|
|
@@ -360,6 +352,10 @@ export interface ApiAppRunRequest {
|
|
|
360
352
|
* When using sessions, the worker is leased and state persists across calls
|
|
361
353
|
*/
|
|
362
354
|
session?: string;
|
|
355
|
+
/**
|
|
356
|
+
* Session timeout in seconds (1-3600). Only valid when session="new"
|
|
357
|
+
*/
|
|
358
|
+
session_timeout?: number;
|
|
363
359
|
}
|
|
364
360
|
/**
|
|
365
361
|
* ApiAgentRunRequest is the request body for /agents/run endpoint.
|
|
@@ -710,9 +706,7 @@ export interface AppImages {
|
|
|
710
706
|
thumbnail: string;
|
|
711
707
|
banner: string;
|
|
712
708
|
}
|
|
713
|
-
export interface App {
|
|
714
|
-
BaseModel: BaseModel;
|
|
715
|
-
PermissionModel: PermissionModel;
|
|
709
|
+
export interface App extends BaseModel, PermissionModel {
|
|
716
710
|
/**
|
|
717
711
|
* Namespace is copied from team.username at creation time and is IMMUTABLE.
|
|
718
712
|
* This ensures stable references like "namespace/name" even if team username changes.
|
|
@@ -767,13 +761,7 @@ export interface AppFunction {
|
|
|
767
761
|
input_schema: any;
|
|
768
762
|
output_schema: any;
|
|
769
763
|
}
|
|
770
|
-
export interface AppVersion {
|
|
771
|
-
BaseModel: BaseModel;
|
|
772
|
-
/**
|
|
773
|
-
* ShortID is a human-friendly version identifier (e.g., "abc123")
|
|
774
|
-
* Unique within the app, used in references like "namespace/app@abc123"
|
|
775
|
-
*/
|
|
776
|
-
short_id: string;
|
|
764
|
+
export interface AppVersion extends BaseModel {
|
|
777
765
|
app_id: string;
|
|
778
766
|
metadata: {
|
|
779
767
|
[key: string]: any;
|
|
@@ -811,6 +799,11 @@ export interface AppVersion {
|
|
|
811
799
|
*/
|
|
812
800
|
checksum?: string;
|
|
813
801
|
}
|
|
802
|
+
export interface LicenseRecord extends BaseModel {
|
|
803
|
+
user_id: string;
|
|
804
|
+
app_id: string;
|
|
805
|
+
license: string;
|
|
806
|
+
}
|
|
814
807
|
export interface AppDTO extends BaseModel, PermissionModelDTO {
|
|
815
808
|
namespace: string;
|
|
816
809
|
name: string;
|
|
@@ -822,7 +815,6 @@ export interface AppDTO extends BaseModel, PermissionModelDTO {
|
|
|
822
815
|
version?: AppVersionDTO;
|
|
823
816
|
}
|
|
824
817
|
export interface AppVersionDTO extends BaseModel {
|
|
825
|
-
short_id: string;
|
|
826
818
|
metadata: {
|
|
827
819
|
[key: string]: any;
|
|
828
820
|
};
|
|
@@ -858,9 +850,7 @@ export type AppSessionStatus = string;
|
|
|
858
850
|
export declare const AppSessionStatusActive: AppSessionStatus;
|
|
859
851
|
export declare const AppSessionStatusEnded: AppSessionStatus;
|
|
860
852
|
export declare const AppSessionStatusExpired: AppSessionStatus;
|
|
861
|
-
export interface AppSession {
|
|
862
|
-
BaseModel: BaseModel;
|
|
863
|
-
PermissionModel: PermissionModel;
|
|
853
|
+
export interface AppSession extends BaseModel, PermissionModel {
|
|
864
854
|
/**
|
|
865
855
|
* Affinity binding
|
|
866
856
|
*/
|
|
@@ -882,6 +872,10 @@ export interface AppSession {
|
|
|
882
872
|
*/
|
|
883
873
|
call_count: number;
|
|
884
874
|
last_call_at?: string;
|
|
875
|
+
/**
|
|
876
|
+
* Custom idle timeout in seconds (nil = use default)
|
|
877
|
+
*/
|
|
878
|
+
idle_timeout?: number;
|
|
885
879
|
/**
|
|
886
880
|
* Relations
|
|
887
881
|
*/
|
|
@@ -890,6 +884,7 @@ export interface AppSession {
|
|
|
890
884
|
}
|
|
891
885
|
export interface BaseModel {
|
|
892
886
|
id: string;
|
|
887
|
+
short_id: string;
|
|
893
888
|
created_at: string;
|
|
894
889
|
updated_at: string;
|
|
895
890
|
deleted_at?: string;
|
|
@@ -1150,9 +1145,7 @@ export declare const EngineStatusRunning: EngineStatus;
|
|
|
1150
1145
|
export declare const EngineStatusPending: EngineStatus;
|
|
1151
1146
|
export declare const EngineStatusStopping: EngineStatus;
|
|
1152
1147
|
export declare const EngineStatusStopped: EngineStatus;
|
|
1153
|
-
export interface EngineState {
|
|
1154
|
-
BaseModel: BaseModel;
|
|
1155
|
-
PermissionModel: PermissionModel;
|
|
1148
|
+
export interface EngineState extends BaseModel, PermissionModel {
|
|
1156
1149
|
instance?: Instance;
|
|
1157
1150
|
transaction_id: string;
|
|
1158
1151
|
config: EngineConfig;
|
|
@@ -1182,9 +1175,7 @@ export interface EngineStateSummary extends BaseModel, PermissionModelDTO {
|
|
|
1182
1175
|
* Worker-related types
|
|
1183
1176
|
*/
|
|
1184
1177
|
export type WorkerStatus = string;
|
|
1185
|
-
export interface WorkerState {
|
|
1186
|
-
BaseModel: BaseModel;
|
|
1187
|
-
PermissionModel: PermissionModel;
|
|
1178
|
+
export interface WorkerState extends BaseModel, PermissionModel {
|
|
1188
1179
|
index: number;
|
|
1189
1180
|
status: WorkerStatus;
|
|
1190
1181
|
status_updated_at?: string;
|
|
@@ -1262,9 +1253,7 @@ export interface WorkerStateSummary {
|
|
|
1262
1253
|
cpus: WorkerCPU[];
|
|
1263
1254
|
rams: WorkerRAM[];
|
|
1264
1255
|
}
|
|
1265
|
-
export interface File {
|
|
1266
|
-
BaseModel: BaseModel;
|
|
1267
|
-
PermissionModel: PermissionModel;
|
|
1256
|
+
export interface File extends BaseModel, PermissionModel {
|
|
1268
1257
|
path: string;
|
|
1269
1258
|
remote_path: string;
|
|
1270
1259
|
upload_url: string;
|
|
@@ -1284,8 +1273,7 @@ export interface FileDTO extends BaseModel, PermissionModelDTO {
|
|
|
1284
1273
|
filename: string;
|
|
1285
1274
|
rating: ContentRating;
|
|
1286
1275
|
}
|
|
1287
|
-
export interface FlowVersion {
|
|
1288
|
-
BaseModel: BaseModel;
|
|
1276
|
+
export interface FlowVersion extends BaseModel {
|
|
1289
1277
|
/**
|
|
1290
1278
|
* Permission fields - nullable for migration from existing data
|
|
1291
1279
|
* After migration these will be populated from parent Flow
|
|
@@ -1295,10 +1283,6 @@ export interface FlowVersion {
|
|
|
1295
1283
|
team_id: string;
|
|
1296
1284
|
team?: Team;
|
|
1297
1285
|
flow_id: string;
|
|
1298
|
-
/**
|
|
1299
|
-
* Short ID for human-readable version references (e.g., "abc123")
|
|
1300
|
-
*/
|
|
1301
|
-
short_id: string;
|
|
1302
1286
|
/**
|
|
1303
1287
|
* ConfigHash for deduplication - SHA256 of config content
|
|
1304
1288
|
*/
|
|
@@ -1395,7 +1379,6 @@ export interface FlowDTO extends BaseModel, PermissionModelDTO {
|
|
|
1395
1379
|
viewport?: FlowViewport;
|
|
1396
1380
|
}
|
|
1397
1381
|
export interface FlowVersionDTO extends BaseModel {
|
|
1398
|
-
short_id: string;
|
|
1399
1382
|
input_schema: any;
|
|
1400
1383
|
input: FlowRunInputs;
|
|
1401
1384
|
output_schema: any;
|
|
@@ -1564,9 +1547,7 @@ export interface ProjectModelDTO {
|
|
|
1564
1547
|
/**
|
|
1565
1548
|
* Project represents a container for organizing related resources
|
|
1566
1549
|
*/
|
|
1567
|
-
export interface Project {
|
|
1568
|
-
BaseModel: BaseModel;
|
|
1569
|
-
PermissionModel: PermissionModel;
|
|
1550
|
+
export interface Project extends BaseModel, PermissionModel {
|
|
1570
1551
|
name: string;
|
|
1571
1552
|
description: string;
|
|
1572
1553
|
type: ProjectType;
|
|
@@ -1673,9 +1654,7 @@ export type InstanceStatus = string;
|
|
|
1673
1654
|
export declare const InstanceStatusPending: InstanceStatus;
|
|
1674
1655
|
export declare const InstanceStatusActive: InstanceStatus;
|
|
1675
1656
|
export declare const InstanceStatusDeleted: InstanceStatus;
|
|
1676
|
-
export interface Instance {
|
|
1677
|
-
BaseModel: BaseModel;
|
|
1678
|
-
PermissionModel: PermissionModel;
|
|
1657
|
+
export interface Instance extends BaseModel, PermissionModel {
|
|
1679
1658
|
cloud: InstanceCloudProvider;
|
|
1680
1659
|
name: string;
|
|
1681
1660
|
region: string;
|
|
@@ -1891,9 +1870,7 @@ export type Infra = string;
|
|
|
1891
1870
|
export declare const InfraPrivate: Infra;
|
|
1892
1871
|
export declare const InfraCloud: Infra;
|
|
1893
1872
|
export declare const InfraPrivateFirst: Infra;
|
|
1894
|
-
export interface Task {
|
|
1895
|
-
BaseModel: BaseModel;
|
|
1896
|
-
PermissionModel: PermissionModel;
|
|
1873
|
+
export interface Task extends BaseModel, PermissionModel {
|
|
1897
1874
|
is_featured: boolean;
|
|
1898
1875
|
status: TaskStatus;
|
|
1899
1876
|
/**
|
|
@@ -1953,6 +1930,10 @@ export interface Task {
|
|
|
1953
1930
|
*/
|
|
1954
1931
|
session_id?: string;
|
|
1955
1932
|
session?: AppSession;
|
|
1933
|
+
/**
|
|
1934
|
+
* Session timeout in seconds (only used when session="new")
|
|
1935
|
+
*/
|
|
1936
|
+
session_timeout?: number;
|
|
1956
1937
|
}
|
|
1957
1938
|
export interface TaskEvent {
|
|
1958
1939
|
id: string;
|
|
@@ -2012,6 +1993,7 @@ export interface TaskDTO extends BaseModel, PermissionModelDTO {
|
|
|
2012
1993
|
transaction_id?: string;
|
|
2013
1994
|
transaction?: Transaction;
|
|
2014
1995
|
session_id?: string;
|
|
1996
|
+
session_timeout?: number;
|
|
2015
1997
|
}
|
|
2016
1998
|
export interface TimescaleTask {
|
|
2017
1999
|
id: string;
|
|
@@ -2029,8 +2011,7 @@ export type TeamType = string;
|
|
|
2029
2011
|
export declare const TeamTypePersonal: TeamType;
|
|
2030
2012
|
export declare const TeamTypeTeam: TeamType;
|
|
2031
2013
|
export declare const TeamTypeSystem: TeamType;
|
|
2032
|
-
export interface Team {
|
|
2033
|
-
BaseModel: BaseModel;
|
|
2014
|
+
export interface Team extends BaseModel {
|
|
2034
2015
|
type: TeamType;
|
|
2035
2016
|
username: string;
|
|
2036
2017
|
email: string;
|
|
@@ -2137,8 +2118,7 @@ export declare const TransactionTypeDebit: TransactionType;
|
|
|
2137
2118
|
/**
|
|
2138
2119
|
* Transaction represents a single credit transaction
|
|
2139
2120
|
*/
|
|
2140
|
-
export interface Transaction {
|
|
2141
|
-
BaseModel: BaseModel;
|
|
2121
|
+
export interface Transaction extends BaseModel {
|
|
2142
2122
|
PermissionModel: PermissionModel;
|
|
2143
2123
|
type: TransactionType;
|
|
2144
2124
|
amount: number;
|
|
@@ -2168,9 +2148,7 @@ export declare const PaymentRecordTypeAutoRecharge: PaymentRecordType;
|
|
|
2168
2148
|
/**
|
|
2169
2149
|
* PaymentRecord stores Stripe payment details for both checkout sessions and direct charges
|
|
2170
2150
|
*/
|
|
2171
|
-
export interface PaymentRecord {
|
|
2172
|
-
BaseModel: BaseModel;
|
|
2173
|
-
PermissionModel: PermissionModel;
|
|
2151
|
+
export interface PaymentRecord extends BaseModel, PermissionModel {
|
|
2174
2152
|
type: PaymentRecordType;
|
|
2175
2153
|
status: PaymentRecordStatus;
|
|
2176
2154
|
amount: number;
|
|
@@ -2248,9 +2226,7 @@ export interface OutputMeta {
|
|
|
2248
2226
|
inputs: MetaItem[];
|
|
2249
2227
|
outputs: MetaItem[];
|
|
2250
2228
|
}
|
|
2251
|
-
export interface UsageEvent {
|
|
2252
|
-
BaseModel: BaseModel;
|
|
2253
|
-
PermissionModel: PermissionModel;
|
|
2229
|
+
export interface UsageEvent extends BaseModel, PermissionModel {
|
|
2254
2230
|
usage_billing_record_id: string;
|
|
2255
2231
|
reference_id: string;
|
|
2256
2232
|
resource_id: string;
|
|
@@ -2263,9 +2239,7 @@ export interface UsageEvent {
|
|
|
2263
2239
|
quantity: number;
|
|
2264
2240
|
unit: string;
|
|
2265
2241
|
}
|
|
2266
|
-
export interface UsageBillingRecord {
|
|
2267
|
-
BaseModel: BaseModel;
|
|
2268
|
-
PermissionModel: PermissionModel;
|
|
2242
|
+
export interface UsageBillingRecord extends BaseModel, PermissionModel {
|
|
2269
2243
|
/**
|
|
2270
2244
|
* Fee breakdown (all in microcents)
|
|
2271
2245
|
*/
|
|
@@ -2297,9 +2271,7 @@ export interface UsageBillingRecord {
|
|
|
2297
2271
|
partner_credit_transaction_id: string;
|
|
2298
2272
|
partner_credit_transaction?: Transaction;
|
|
2299
2273
|
}
|
|
2300
|
-
export interface UsageBillingRefund {
|
|
2301
|
-
BaseModel: BaseModel;
|
|
2302
|
-
PermissionModel: PermissionModel;
|
|
2274
|
+
export interface UsageBillingRefund extends BaseModel, PermissionModel {
|
|
2303
2275
|
usage_billing_record_id: string;
|
|
2304
2276
|
usage_billing_record?: UsageBillingRecord;
|
|
2305
2277
|
/**
|