@latens/sdk 0.0.0-stage → 1.3.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/LICENSE +21 -0
- package/README.md +108 -2
- package/dist/calculator.d.ts +2 -0
- package/dist/calculator.js +30 -0
- package/dist/client.d.ts +78 -0
- package/dist/client.js +151 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/normalizer.d.ts +2 -0
- package/dist/normalizer.js +40 -0
- package/dist/sizing.d.ts +13 -0
- package/dist/sizing.js +248 -0
- package/dist/standing.d.ts +20 -0
- package/dist/standing.js +99 -0
- package/dist/types.d.ts +230 -0
- package/dist/types.js +1 -0
- package/openapi/openapi.v3.1.json +410 -0
- package/package.json +49 -4
- package/src/calculator.ts +43 -0
- package/src/client.ts +272 -0
- package/src/index.ts +6 -0
- package/src/normalizer.ts +43 -0
- package/src/sizing.ts +335 -0
- package/src/standing.ts +126 -0
- package/src/types.ts +278 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.1.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "LATENS Autonomous Agent Read-Only API",
|
|
5
|
+
"version": "1.3.0",
|
|
6
|
+
"description": "Read-only GPU discovery, paginated normalized provider offer search, real 15-minute GPU price history, deterministic compute cost calculation, and synchronization telemetry for autonomous AI agents. Agents supplying X-Latens-Wallet with verified on-chain $LTNS holdings on Robinhood Chain (4663) unlock up to 600 req/min read and 900 req/min calculation throughput."
|
|
7
|
+
},
|
|
8
|
+
"servers": [
|
|
9
|
+
{
|
|
10
|
+
"url": "https://latens.trade",
|
|
11
|
+
"description": "LATENS API Origin"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"paths": {
|
|
15
|
+
"/api/v1/agent/models": {
|
|
16
|
+
"get": {
|
|
17
|
+
"operationId": "discoverGpuModels",
|
|
18
|
+
"summary": "Discover available normalized GPU models and price floors",
|
|
19
|
+
"responses": {
|
|
20
|
+
"200": {
|
|
21
|
+
"description": "Normalized GPU model catalog"
|
|
22
|
+
},
|
|
23
|
+
"429": {
|
|
24
|
+
"description": "Rate limit exceeded"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"/api/v1/agent/models/history": {
|
|
30
|
+
"get": {
|
|
31
|
+
"operationId": "getGpuPriceHistory",
|
|
32
|
+
"summary": "Retrieve genuine 15-minute or rolled-up hourly/daily GPU price history with no backfill or interpolation",
|
|
33
|
+
"description": "Returns recorded historical min, median, and max USD/GPU/hr prices aggregated from live non-stale normalized offers. 15-minute buckets are retained for 35 days; hourly rollups are retained indefinitely. Missing intervals remain gaps.",
|
|
34
|
+
"parameters": [
|
|
35
|
+
{
|
|
36
|
+
"name": "model",
|
|
37
|
+
"in": "query",
|
|
38
|
+
"required": true,
|
|
39
|
+
"description": "Canonical GPU model name or family prefix (e.g. H100, H100 SXM, A100 SXM, RTX 4090).",
|
|
40
|
+
"schema": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"minLength": 1,
|
|
43
|
+
"maxLength": 80
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "window",
|
|
48
|
+
"in": "query",
|
|
49
|
+
"required": false,
|
|
50
|
+
"description": "Lookback window relative to current UTC time.",
|
|
51
|
+
"schema": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"enum": [
|
|
54
|
+
"24h",
|
|
55
|
+
"7d",
|
|
56
|
+
"30d"
|
|
57
|
+
],
|
|
58
|
+
"default": "24h"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "interval",
|
|
63
|
+
"in": "query",
|
|
64
|
+
"required": false,
|
|
65
|
+
"description": "Time bucket aggregation interval.",
|
|
66
|
+
"schema": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"enum": [
|
|
69
|
+
"15m",
|
|
70
|
+
"1h",
|
|
71
|
+
"1d"
|
|
72
|
+
],
|
|
73
|
+
"default": "15m"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "category",
|
|
78
|
+
"in": "query",
|
|
79
|
+
"required": false,
|
|
80
|
+
"description": "Optional product category filter. Defaults to 'all' across all product categories.",
|
|
81
|
+
"schema": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"enum": [
|
|
84
|
+
"all",
|
|
85
|
+
"dedicated_instance",
|
|
86
|
+
"secure_pod",
|
|
87
|
+
"community_pod",
|
|
88
|
+
"cloud_vm",
|
|
89
|
+
"bare_metal",
|
|
90
|
+
"decentralized_lease",
|
|
91
|
+
"interruptible_spot"
|
|
92
|
+
],
|
|
93
|
+
"default": "all"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
"responses": {
|
|
98
|
+
"200": {
|
|
99
|
+
"description": "Recorded GPU price history series",
|
|
100
|
+
"content": {
|
|
101
|
+
"application/json": {
|
|
102
|
+
"schema": {
|
|
103
|
+
"type": "object",
|
|
104
|
+
"properties": {
|
|
105
|
+
"object": {
|
|
106
|
+
"type": "string",
|
|
107
|
+
"const": "gpu_price_history"
|
|
108
|
+
},
|
|
109
|
+
"read_only": {
|
|
110
|
+
"type": "boolean",
|
|
111
|
+
"const": true
|
|
112
|
+
},
|
|
113
|
+
"model": {
|
|
114
|
+
"type": "string"
|
|
115
|
+
},
|
|
116
|
+
"matched_models": {
|
|
117
|
+
"type": "array",
|
|
118
|
+
"items": {
|
|
119
|
+
"type": "string"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"window": {
|
|
123
|
+
"type": "string",
|
|
124
|
+
"enum": [
|
|
125
|
+
"24h",
|
|
126
|
+
"7d",
|
|
127
|
+
"30d"
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"interval": {
|
|
131
|
+
"type": "string",
|
|
132
|
+
"enum": [
|
|
133
|
+
"15m",
|
|
134
|
+
"1h",
|
|
135
|
+
"1d"
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
"category": {
|
|
139
|
+
"type": "string"
|
|
140
|
+
},
|
|
141
|
+
"first_recorded_at": {
|
|
142
|
+
"type": [
|
|
143
|
+
"string",
|
|
144
|
+
"null"
|
|
145
|
+
],
|
|
146
|
+
"format": "date-time"
|
|
147
|
+
},
|
|
148
|
+
"coverage_hours": {
|
|
149
|
+
"type": "number"
|
|
150
|
+
},
|
|
151
|
+
"points": {
|
|
152
|
+
"type": "array",
|
|
153
|
+
"items": {
|
|
154
|
+
"type": "object",
|
|
155
|
+
"properties": {
|
|
156
|
+
"t": {
|
|
157
|
+
"type": "string",
|
|
158
|
+
"format": "date-time"
|
|
159
|
+
},
|
|
160
|
+
"min": {
|
|
161
|
+
"type": "number"
|
|
162
|
+
},
|
|
163
|
+
"median": {
|
|
164
|
+
"type": "number"
|
|
165
|
+
},
|
|
166
|
+
"max": {
|
|
167
|
+
"type": "number"
|
|
168
|
+
},
|
|
169
|
+
"offers": {
|
|
170
|
+
"type": "integer"
|
|
171
|
+
},
|
|
172
|
+
"providers": {
|
|
173
|
+
"type": "integer"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
"400": {
|
|
184
|
+
"description": "Missing model or invalid/unknown query parameter (returns allowed parameters and hints)"
|
|
185
|
+
},
|
|
186
|
+
"429": {
|
|
187
|
+
"description": "Rate limit exceeded"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
"/api/v1/agent/offers": {
|
|
193
|
+
"get": {
|
|
194
|
+
"operationId": "searchGpuOffers",
|
|
195
|
+
"summary": "Search and paginate normalized GPU rental offers across 8 live providers",
|
|
196
|
+
"description": "Returns paginated normalized GPU offers sorted by price_asc (lowest price_per_gpu_usd first, tie-broken deterministically by offer id) by default. Unknown query parameters are rejected with HTTP 400 and parameter hints. Paginating through all pages with default filters (available_only=true) returns exactly status.summary.filteredOffers offers.",
|
|
197
|
+
"parameters": [
|
|
198
|
+
{
|
|
199
|
+
"name": "model",
|
|
200
|
+
"in": "query",
|
|
201
|
+
"schema": {
|
|
202
|
+
"type": "string"
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"name": "min_vram_gb",
|
|
207
|
+
"in": "query",
|
|
208
|
+
"schema": {
|
|
209
|
+
"type": "number"
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"name": "max_price_per_gpu_usd",
|
|
214
|
+
"in": "query",
|
|
215
|
+
"schema": {
|
|
216
|
+
"type": "number"
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"name": "provider",
|
|
221
|
+
"in": "query",
|
|
222
|
+
"schema": {
|
|
223
|
+
"type": "string",
|
|
224
|
+
"enum": [
|
|
225
|
+
"all",
|
|
226
|
+
"vast",
|
|
227
|
+
"runpod",
|
|
228
|
+
"cudo",
|
|
229
|
+
"vultr",
|
|
230
|
+
"akash",
|
|
231
|
+
"lambda",
|
|
232
|
+
"crusoe",
|
|
233
|
+
"scaleway"
|
|
234
|
+
]
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"name": "region",
|
|
239
|
+
"in": "query",
|
|
240
|
+
"schema": {
|
|
241
|
+
"type": "string"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"name": "gpu_count",
|
|
246
|
+
"in": "query",
|
|
247
|
+
"schema": {
|
|
248
|
+
"type": "integer"
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"name": "category",
|
|
253
|
+
"in": "query",
|
|
254
|
+
"schema": {
|
|
255
|
+
"type": "string",
|
|
256
|
+
"enum": [
|
|
257
|
+
"all",
|
|
258
|
+
"all_dedicated",
|
|
259
|
+
"dedicated_instance",
|
|
260
|
+
"secure_pod",
|
|
261
|
+
"community_pod",
|
|
262
|
+
"cloud_vm",
|
|
263
|
+
"bare_metal",
|
|
264
|
+
"decentralized_lease",
|
|
265
|
+
"interruptible_spot"
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"name": "available_only",
|
|
271
|
+
"in": "query",
|
|
272
|
+
"description": "When 'true' (default), excludes unavailable offers so total matches status.summary.filteredOffers. Set 'false' to include unavailable catalog entries (matching status.summary.totalOffers).",
|
|
273
|
+
"schema": {
|
|
274
|
+
"type": "string",
|
|
275
|
+
"enum": [
|
|
276
|
+
"true",
|
|
277
|
+
"false"
|
|
278
|
+
],
|
|
279
|
+
"default": "true"
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"name": "sort",
|
|
284
|
+
"in": "query",
|
|
285
|
+
"description": "Deterministic sort order. Default is price_asc (ascending price_per_gpu_usd).",
|
|
286
|
+
"schema": {
|
|
287
|
+
"type": "string",
|
|
288
|
+
"enum": [
|
|
289
|
+
"price_asc",
|
|
290
|
+
"price_desc",
|
|
291
|
+
"vram_desc"
|
|
292
|
+
],
|
|
293
|
+
"default": "price_asc"
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
"name": "offset",
|
|
298
|
+
"in": "query",
|
|
299
|
+
"description": "Zero-based pagination offset into the sorted matching offers list.",
|
|
300
|
+
"schema": {
|
|
301
|
+
"type": "integer",
|
|
302
|
+
"minimum": 0,
|
|
303
|
+
"default": 0
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"name": "limit",
|
|
308
|
+
"in": "query",
|
|
309
|
+
"description": "Maximum offers returned per page (1 to 100).",
|
|
310
|
+
"schema": {
|
|
311
|
+
"type": "integer",
|
|
312
|
+
"minimum": 1,
|
|
313
|
+
"maximum": 100,
|
|
314
|
+
"default": 50
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
],
|
|
318
|
+
"responses": {
|
|
319
|
+
"200": {
|
|
320
|
+
"description": "Paginated normalized GPU offers with count (page size), total (all matching offers), offset, limit, sort, and next_offset (integer or null)."
|
|
321
|
+
},
|
|
322
|
+
"400": {
|
|
323
|
+
"description": "Invalid or unknown query parameters (includes allowed_parameters and alias hints such as gpu_model -> use model)"
|
|
324
|
+
},
|
|
325
|
+
"429": {
|
|
326
|
+
"description": "Rate limit exceeded"
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
"/api/v1/agent/calculate": {
|
|
332
|
+
"post": {
|
|
333
|
+
"operationId": "calculateRentalCost",
|
|
334
|
+
"summary": "Deterministically calculate total GPU-hours and estimated rental cost",
|
|
335
|
+
"requestBody": {
|
|
336
|
+
"required": true,
|
|
337
|
+
"content": {
|
|
338
|
+
"application/json": {
|
|
339
|
+
"schema": {
|
|
340
|
+
"type": "object",
|
|
341
|
+
"required": [
|
|
342
|
+
"duration_hours"
|
|
343
|
+
],
|
|
344
|
+
"properties": {
|
|
345
|
+
"offer_id": {
|
|
346
|
+
"type": "string"
|
|
347
|
+
},
|
|
348
|
+
"gpu_model": {
|
|
349
|
+
"type": "string"
|
|
350
|
+
},
|
|
351
|
+
"gpu_count": {
|
|
352
|
+
"type": "integer",
|
|
353
|
+
"default": 1
|
|
354
|
+
},
|
|
355
|
+
"duration_hours": {
|
|
356
|
+
"type": "number"
|
|
357
|
+
},
|
|
358
|
+
"hourly_price_per_gpu_usd": {
|
|
359
|
+
"type": "number"
|
|
360
|
+
},
|
|
361
|
+
"storage_gb": {
|
|
362
|
+
"type": "number",
|
|
363
|
+
"default": 0
|
|
364
|
+
},
|
|
365
|
+
"storage_cost_per_gb_month_usd": {
|
|
366
|
+
"type": "number"
|
|
367
|
+
},
|
|
368
|
+
"egress_gb": {
|
|
369
|
+
"type": "number",
|
|
370
|
+
"default": 0
|
|
371
|
+
},
|
|
372
|
+
"egress_cost_per_gb_usd": {
|
|
373
|
+
"type": "number"
|
|
374
|
+
},
|
|
375
|
+
"additional_flat_fees_usd": {
|
|
376
|
+
"type": "number",
|
|
377
|
+
"default": 0
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
"responses": {
|
|
385
|
+
"200": {
|
|
386
|
+
"description": "Deterministic cost breakdown"
|
|
387
|
+
},
|
|
388
|
+
"400": {
|
|
389
|
+
"description": "Invalid calculation input"
|
|
390
|
+
},
|
|
391
|
+
"404": {
|
|
392
|
+
"description": "Referenced offer_id not found"
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
"/api/v1/agent/status": {
|
|
398
|
+
"get": {
|
|
399
|
+
"operationId": "getProviderStatus",
|
|
400
|
+
"summary": "Retrieve current GPU provider synchronization health, timestamps, and inventory counts",
|
|
401
|
+
"description": "summary.totalOffers counts all normalized catalog offers across all 8 providers including currently unavailable listings. summary.filteredOffers counts currently available offers (availability_status != 'unavailable'), matching the exact total obtained by paginating through GET /api/v1/agent/offers with default filters.",
|
|
402
|
+
"responses": {
|
|
403
|
+
"200": {
|
|
404
|
+
"description": "Provider status summary"
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latens/sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "TypeScript SDK, GPU hardware normalizer, price history client, LLM VRAM sizing estimator, deterministic multi-offer TCO ranker, and $LTNS holder tier engine for the LATENS Read-Only Agent API v1.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src",
|
|
20
|
+
"openapi",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json",
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
|
+
"test": "tsc -p tsconfig.json && node --test tests/sdk.test.mjs"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"gpu",
|
|
31
|
+
"compute",
|
|
32
|
+
"ai-agents",
|
|
33
|
+
"ltns",
|
|
34
|
+
"robinhood-chain",
|
|
35
|
+
"cloud-pricing",
|
|
36
|
+
"openapi",
|
|
37
|
+
"typescript"
|
|
38
|
+
],
|
|
39
|
+
"homepage": "https://latens.trade/docs",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/LatensRbh/latens-sdk.git"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"typescript": "^5.8.3"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ComputeCostBreakdown, ComputeCostInput } from "./types.js";
|
|
2
|
+
import { roundUsd } from "./normalizer.js";
|
|
3
|
+
|
|
4
|
+
const HOURS_PER_MONTH = 730;
|
|
5
|
+
|
|
6
|
+
export function calculateDeterministicComputeCost(
|
|
7
|
+
input: ComputeCostInput
|
|
8
|
+
): ComputeCostBreakdown {
|
|
9
|
+
if (input.hourlyRatePerInstanceUsd < 0) {
|
|
10
|
+
throw new RangeError("hourlyRatePerInstanceUsd must be non-negative.");
|
|
11
|
+
}
|
|
12
|
+
if (input.durationHours <= 0) {
|
|
13
|
+
throw new RangeError("durationHours must be greater than zero.");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const instances = input.instanceCount ?? 1;
|
|
17
|
+
if (!Number.isInteger(instances) || instances < 1) {
|
|
18
|
+
throw new RangeError("instanceCount must be a positive integer.");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const computeSubtotal =
|
|
22
|
+
input.hourlyRatePerInstanceUsd * instances * input.durationHours;
|
|
23
|
+
|
|
24
|
+
const storageGb = Math.max(0, input.storageGb ?? 0);
|
|
25
|
+
const storageMonthlyRate = Math.max(0, input.storageCostPerGbMonthUsd ?? 0);
|
|
26
|
+
const storageSubtotal =
|
|
27
|
+
storageGb * (storageMonthlyRate / HOURS_PER_MONTH) * input.durationHours;
|
|
28
|
+
|
|
29
|
+
const egressGb = Math.max(0, input.egressGb ?? 0);
|
|
30
|
+
const egressRate = Math.max(0, input.egressCostPerGbUsd ?? 0);
|
|
31
|
+
const egressSubtotal = egressGb * egressRate;
|
|
32
|
+
|
|
33
|
+
const total = computeSubtotal + storageSubtotal + egressSubtotal;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
computeSubtotalUsd: roundUsd(computeSubtotal, 4),
|
|
37
|
+
storageSubtotalUsd: roundUsd(storageSubtotal, 4),
|
|
38
|
+
egressSubtotalUsd: roundUsd(egressSubtotal, 4),
|
|
39
|
+
totalEstimatedUsd: roundUsd(total, 4),
|
|
40
|
+
effectiveHourlyUsd: roundUsd(total / input.durationHours, 4),
|
|
41
|
+
currency: "USD",
|
|
42
|
+
};
|
|
43
|
+
}
|