@latens/sdk 1.3.0 → 1.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 CHANGED
@@ -75,6 +75,17 @@ const ranked = rankOffersByTco(page1.offers, {
75
75
  });
76
76
 
77
77
  console.log(sizing.recommendedVramGb, ranked.ranked[0], ranked.spreadMultiplier);
78
+
79
+ // Phase 03: HTTP 402 (x402) Autonomous GPU Execution on Robinhood Chain (4663)
80
+ const challenge = await client.requestX402Quote({
81
+ gpuModel: "RTX 4090",
82
+ durationHours: 2,
83
+ paymentAsset: "LTNS",
84
+ sshPublicKey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... agent@latens",
85
+ maxSpendUsd: 5.0,
86
+ });
87
+ // After broadcasting challenge.quote.paymentAmountRaw on Chain 4663:
88
+ // const receipt = await client.settleX402Execution({ quoteId: challenge.quote.id, txHash });
78
89
  ```
79
90
 
80
91
  ## `totalOffers` vs `filteredOffers`
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AgentCalculateInput, AgentOffersQuery, AgentOffersSort, GpuPriceHistoryQuery, GpuPriceHistoryResponse, HolderTierId, LlmSizingInput, LlmSizingResult, NormalizedGpuOffer, OfferTcoComparisonOptions, OfferTcoComparisonResult, TokenStandingResponse } from "./types.js";
1
+ import type { AgentCalculateInput, AgentOffersQuery, AgentOffersSort, GpuPriceHistoryQuery, GpuPriceHistoryResponse, HolderTierId, LlmSizingInput, LlmSizingResult, NormalizedGpuOffer, OfferTcoComparisonOptions, OfferTcoComparisonResult, TokenStandingResponse, X402ExecutionReceipt, X402QuoteChallenge, X402QuoteRequestInput } from "./types.js";
2
2
  export interface LatensClientOptions {
3
3
  baseUrl?: string;
4
4
  walletAddress?: string;
@@ -75,4 +75,19 @@ export declare class LatensReadOnlyClient {
75
75
  comparison: OfferTcoComparisonResult;
76
76
  }>;
77
77
  private requestJson;
78
+ requestX402Quote(input: X402QuoteRequestInput): Promise<X402QuoteChallenge>;
79
+ settleX402Execution(params: {
80
+ quoteId: string;
81
+ txHash: string;
82
+ payer?: string;
83
+ }): Promise<X402ExecutionReceipt>;
84
+ getAgentRentalStatus(rentalId: string, rentalAccessToken: string): Promise<{
85
+ object: string;
86
+ rental: Record<string, unknown>;
87
+ }>;
88
+ terminateAgentRental(rentalId: string, rentalAccessToken: string): Promise<{
89
+ object: string;
90
+ rental: Record<string, unknown>;
91
+ }>;
78
92
  }
93
+ export declare const LatensAgentClient: typeof LatensReadOnlyClient;
package/dist/client.js CHANGED
@@ -126,8 +126,9 @@ export class LatensReadOnlyClient {
126
126
  try {
127
127
  const headers = {
128
128
  Accept: "application/json",
129
+ ...(init?.headers ?? {}),
129
130
  };
130
- if (this.walletAddress) {
131
+ if (this.walletAddress && !headers["X-Latens-Wallet"]) {
131
132
  headers["X-Latens-Wallet"] = this.walletAddress;
132
133
  }
133
134
  if (init?.body !== undefined) {
@@ -139,7 +140,7 @@ export class LatensReadOnlyClient {
139
140
  body: init?.body !== undefined ? JSON.stringify(init.body) : undefined,
140
141
  signal: controller.signal,
141
142
  });
142
- if (!res.ok) {
143
+ if (!res.ok && !(init?.allowStatuses ?? []).includes(res.status)) {
143
144
  throw new Error(`LATENS API HTTP ${res.status} on ${pathname}`);
144
145
  }
145
146
  return (await res.json());
@@ -148,4 +149,46 @@ export class LatensReadOnlyClient {
148
149
  clearTimeout(timer);
149
150
  }
150
151
  }
152
+ async requestX402Quote(input) {
153
+ return this.requestJson("/api/v1/agent/execute", {
154
+ method: "POST",
155
+ body: {
156
+ walletAddress: input.walletAddress ?? this.walletAddress ?? undefined,
157
+ ...input,
158
+ },
159
+ allowStatuses: [402],
160
+ });
161
+ }
162
+ async settleX402Execution(params) {
163
+ const encoded = Buffer.from(JSON.stringify({
164
+ quoteId: params.quoteId,
165
+ txHash: params.txHash,
166
+ payer: params.payer ?? this.walletAddress ?? undefined,
167
+ }), "utf8").toString("base64");
168
+ return this.requestJson("/api/v1/agent/execute", {
169
+ method: "POST",
170
+ headers: {
171
+ "X-Payment": encoded,
172
+ ...(params.payer ? { "X-Latens-Wallet": params.payer } : {}),
173
+ },
174
+ body: {},
175
+ });
176
+ }
177
+ async getAgentRentalStatus(rentalId, rentalAccessToken) {
178
+ return this.requestJson(`/api/v1/agent/rentals/${encodeURIComponent(rentalId)}`, {
179
+ method: "GET",
180
+ headers: {
181
+ Authorization: `Bearer ${rentalAccessToken.replace(/^Bearer\s+/i, "")}`,
182
+ },
183
+ });
184
+ }
185
+ async terminateAgentRental(rentalId, rentalAccessToken) {
186
+ return this.requestJson(`/api/v1/agent/rentals/${encodeURIComponent(rentalId)}`, {
187
+ method: "DELETE",
188
+ headers: {
189
+ Authorization: `Bearer ${rentalAccessToken.replace(/^Bearer\s+/i, "")}`,
190
+ },
191
+ });
192
+ }
151
193
  }
194
+ export const LatensAgentClient = LatensReadOnlyClient;
package/dist/types.d.ts CHANGED
@@ -228,3 +228,57 @@ export interface OfferTcoComparisonResult {
228
228
  spreadMultiplier: number;
229
229
  ranked: RankedGpuOfferTco[];
230
230
  }
231
+ export interface X402QuoteRequestInput {
232
+ walletAddress?: string;
233
+ offerId?: string;
234
+ gpuModel?: string;
235
+ gpuCount?: number;
236
+ minVramGb?: number;
237
+ durationHours?: number;
238
+ diskGb?: number;
239
+ dockerImage?: string;
240
+ runtype?: "ssh_direct" | "ssh" | "jupyter_direct";
241
+ paymentAsset?: "LTNS" | "USDG" | "ETH";
242
+ sshPublicKey: string;
243
+ maxSpendUsd?: number;
244
+ }
245
+ export interface X402QuoteChallenge {
246
+ object: "x402_payment_required";
247
+ x402Version: number;
248
+ error: string;
249
+ message: string;
250
+ quote: {
251
+ id: string;
252
+ rentalCode: string;
253
+ offerId: string;
254
+ gpuModel: string;
255
+ gpuCount: number;
256
+ vramPerGpuGb: number;
257
+ region: string;
258
+ durationHours: number;
259
+ diskGb: number;
260
+ dockerImage: string;
261
+ hourlyPriceUsd: number;
262
+ platformFeeBps: number;
263
+ totalUsd: number;
264
+ holderTier: HolderTierId;
265
+ paymentAsset: "LTNS" | "USDG" | "ETH";
266
+ paymentAmountRaw: string;
267
+ paymentAmountFormatted: string;
268
+ treasuryWallet: string;
269
+ escrowContract: string | null;
270
+ escrowLeaseId: string;
271
+ quoteExpiresAt: string;
272
+ };
273
+ accepts: Array<Record<string, unknown>>;
274
+ }
275
+ export interface X402ExecutionReceipt {
276
+ object: "x402_execution_receipt";
277
+ settled: boolean;
278
+ rental: Record<string, unknown>;
279
+ credentials: {
280
+ rentalAccessToken: string;
281
+ pollEndpoint: string;
282
+ authorizationHeader: string;
283
+ };
284
+ }
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "openapi": "3.1.0",
3
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."
4
+ "title": "LATENS Autonomous Agent Discovery & x402 Execution API",
5
+ "version": "1.5.0",
6
+ "description": "Normalized multi-cloud GPU discovery across 8 providers, genuine 15-minute GPU price history, deterministic compute cost calculation, and HTTP 402 (x402) payment-gated autonomous GPU node execution settled on Robinhood Chain (4663) in $LTNS, USDG, and ETH."
7
7
  },
8
8
  "servers": [
9
9
  {
@@ -405,6 +405,124 @@
405
405
  }
406
406
  }
407
407
  }
408
+ },
409
+ "/api/v1/agent/execute": {
410
+ "post": {
411
+ "operationId": "executeAutonomousGpuLeaseX402",
412
+ "summary": "HTTP 402 (x402) payment-gated autonomous GPU provisioning on Robinhood Chain (4663)",
413
+ "description": "Step 1 (unpaid): send desired GPU spec, sshPublicKey, paymentAsset (LTNS, USDG, or ETH), and maxSpendUsd ceiling with X-Latens-Wallet header; returns HTTP 402 Payment Required with exact Robinhood Chain (4663) payment quote and WWW-Authenticate x402 challenge. Step 2 (settled): broadcast on-chain transfer or LatensComputeEscrow lock from the agent wallet and retry with X-Payment header containing base64 JSON {quoteId, txHash}; verifies receipt on-chain and provisions live SSH container, returning HTTP 200 with rentalAccessToken.",
414
+ "requestBody": {
415
+ "required": false,
416
+ "content": {
417
+ "application/json": {
418
+ "schema": {
419
+ "type": "object",
420
+ "properties": {
421
+ "walletAddress": {
422
+ "type": "string"
423
+ },
424
+ "offerId": {
425
+ "type": "string"
426
+ },
427
+ "gpuModel": {
428
+ "type": "string"
429
+ },
430
+ "gpuCount": {
431
+ "type": "integer",
432
+ "default": 1
433
+ },
434
+ "durationHours": {
435
+ "type": "integer",
436
+ "default": 2
437
+ },
438
+ "diskGb": {
439
+ "type": "integer",
440
+ "default": 80
441
+ },
442
+ "dockerImage": {
443
+ "type": "string"
444
+ },
445
+ "paymentAsset": {
446
+ "type": "string",
447
+ "enum": [
448
+ "LTNS",
449
+ "USDG",
450
+ "ETH"
451
+ ],
452
+ "default": "LTNS"
453
+ },
454
+ "sshPublicKey": {
455
+ "type": "string"
456
+ },
457
+ "maxSpendUsd": {
458
+ "type": "number",
459
+ "default": 25
460
+ }
461
+ }
462
+ }
463
+ }
464
+ }
465
+ },
466
+ "responses": {
467
+ "200": {
468
+ "description": "Verified on-chain settlement receipt, provisioned container details, and Bearer rentalAccessToken"
469
+ },
470
+ "400": {
471
+ "description": "Validation error, spend cap exceeded, or unverified payment receipt"
472
+ },
473
+ "402": {
474
+ "description": "x402 Payment Required challenge with quoteId, exact token/wei amount, and settlement instructions"
475
+ }
476
+ }
477
+ }
478
+ },
479
+ "/api/v1/agent/rentals/{id}": {
480
+ "get": {
481
+ "operationId": "getAgentRentalStatus",
482
+ "summary": "Poll live SSH host, port, and container lifecycle status using x402 Bearer rentalAccessToken",
483
+ "parameters": [
484
+ {
485
+ "name": "id",
486
+ "in": "path",
487
+ "required": true,
488
+ "schema": {
489
+ "type": "string",
490
+ "format": "uuid"
491
+ }
492
+ }
493
+ ],
494
+ "responses": {
495
+ "200": {
496
+ "description": "Hydrated SSH host, port, and lease expiry"
497
+ },
498
+ "401": {
499
+ "description": "Missing or expired Bearer rentalAccessToken"
500
+ }
501
+ }
502
+ },
503
+ "delete": {
504
+ "operationId": "terminateAgentRental",
505
+ "summary": "Terminate an active autonomous GPU instance using x402 Bearer rentalAccessToken",
506
+ "parameters": [
507
+ {
508
+ "name": "id",
509
+ "in": "path",
510
+ "required": true,
511
+ "schema": {
512
+ "type": "string",
513
+ "format": "uuid"
514
+ }
515
+ }
516
+ ],
517
+ "responses": {
518
+ "200": {
519
+ "description": "Instance terminated"
520
+ },
521
+ "401": {
522
+ "description": "Missing or expired Bearer rentalAccessToken"
523
+ }
524
+ }
525
+ }
408
526
  }
409
527
  }
410
528
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@latens/sdk",
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.",
3
+ "version": "1.4.0",
4
+ "description": "TypeScript SDK, GPU hardware normalizer, price history client, LLM VRAM sizing estimator, deterministic multi-offer TCO ranker, $LTNS holder tier engine, and HTTP 402 (x402) autonomous GPU execution client for LATENS on Robinhood Chain (4663).",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
package/src/client.ts CHANGED
@@ -13,6 +13,9 @@ import type {
13
13
  OfferTcoComparisonOptions,
14
14
  OfferTcoComparisonResult,
15
15
  TokenStandingResponse,
16
+ X402ExecutionReceipt,
17
+ X402QuoteChallenge,
18
+ X402QuoteRequestInput,
16
19
  } from "./types.js";
17
20
 
18
21
  export interface LatensClientOptions {
@@ -240,15 +243,21 @@ export class LatensReadOnlyClient {
240
243
 
241
244
  private async requestJson<T>(
242
245
  pathname: string,
243
- init?: { method?: "GET" | "POST"; body?: unknown }
246
+ init?: {
247
+ method?: "GET" | "POST" | "DELETE";
248
+ body?: unknown;
249
+ headers?: Record<string, string>;
250
+ allowStatuses?: number[];
251
+ }
244
252
  ): Promise<T> {
245
253
  const controller = new AbortController();
246
254
  const timer = setTimeout(() => controller.abort(), this.timeoutMs);
247
255
  try {
248
256
  const headers: Record<string, string> = {
249
257
  Accept: "application/json",
258
+ ...(init?.headers ?? {}),
250
259
  };
251
- if (this.walletAddress) {
260
+ if (this.walletAddress && !headers["X-Latens-Wallet"]) {
252
261
  headers["X-Latens-Wallet"] = this.walletAddress;
253
262
  }
254
263
  if (init?.body !== undefined) {
@@ -261,7 +270,7 @@ export class LatensReadOnlyClient {
261
270
  body: init?.body !== undefined ? JSON.stringify(init.body) : undefined,
262
271
  signal: controller.signal,
263
272
  });
264
- if (!res.ok) {
273
+ if (!res.ok && !(init?.allowStatuses ?? []).includes(res.status)) {
265
274
  throw new Error(`LATENS API HTTP ${res.status} on ${pathname}`);
266
275
  }
267
276
  return (await res.json()) as T;
@@ -269,4 +278,65 @@ export class LatensReadOnlyClient {
269
278
  clearTimeout(timer);
270
279
  }
271
280
  }
281
+
282
+ async requestX402Quote(input: X402QuoteRequestInput): Promise<X402QuoteChallenge> {
283
+ return this.requestJson<X402QuoteChallenge>("/api/v1/agent/execute", {
284
+ method: "POST",
285
+ body: {
286
+ walletAddress: input.walletAddress ?? this.walletAddress ?? undefined,
287
+ ...input,
288
+ },
289
+ allowStatuses: [402],
290
+ });
291
+ }
292
+
293
+ async settleX402Execution(params: {
294
+ quoteId: string;
295
+ txHash: string;
296
+ payer?: string;
297
+ }): Promise<X402ExecutionReceipt> {
298
+ const encoded = Buffer.from(
299
+ JSON.stringify({
300
+ quoteId: params.quoteId,
301
+ txHash: params.txHash,
302
+ payer: params.payer ?? this.walletAddress ?? undefined,
303
+ }),
304
+ "utf8"
305
+ ).toString("base64");
306
+
307
+ return this.requestJson<X402ExecutionReceipt>("/api/v1/agent/execute", {
308
+ method: "POST",
309
+ headers: {
310
+ "X-Payment": encoded,
311
+ ...(params.payer ? { "X-Latens-Wallet": params.payer } : {}),
312
+ },
313
+ body: {},
314
+ });
315
+ }
316
+
317
+ async getAgentRentalStatus(
318
+ rentalId: string,
319
+ rentalAccessToken: string
320
+ ): Promise<{ object: string; rental: Record<string, unknown> }> {
321
+ return this.requestJson(`/api/v1/agent/rentals/${encodeURIComponent(rentalId)}`, {
322
+ method: "GET",
323
+ headers: {
324
+ Authorization: `Bearer ${rentalAccessToken.replace(/^Bearer\s+/i, "")}`,
325
+ },
326
+ });
327
+ }
328
+
329
+ async terminateAgentRental(
330
+ rentalId: string,
331
+ rentalAccessToken: string
332
+ ): Promise<{ object: string; rental: Record<string, unknown> }> {
333
+ return this.requestJson(`/api/v1/agent/rentals/${encodeURIComponent(rentalId)}`, {
334
+ method: "DELETE",
335
+ headers: {
336
+ Authorization: `Bearer ${rentalAccessToken.replace(/^Bearer\s+/i, "")}`,
337
+ },
338
+ });
339
+ }
272
340
  }
341
+
342
+ export const LatensAgentClient = LatensReadOnlyClient;
package/src/types.ts CHANGED
@@ -276,3 +276,60 @@ export interface OfferTcoComparisonResult {
276
276
  spreadMultiplier: number;
277
277
  ranked: RankedGpuOfferTco[];
278
278
  }
279
+
280
+ export interface X402QuoteRequestInput {
281
+ walletAddress?: string;
282
+ offerId?: string;
283
+ gpuModel?: string;
284
+ gpuCount?: number;
285
+ minVramGb?: number;
286
+ durationHours?: number;
287
+ diskGb?: number;
288
+ dockerImage?: string;
289
+ runtype?: "ssh_direct" | "ssh" | "jupyter_direct";
290
+ paymentAsset?: "LTNS" | "USDG" | "ETH";
291
+ sshPublicKey: string;
292
+ maxSpendUsd?: number;
293
+ }
294
+
295
+ export interface X402QuoteChallenge {
296
+ object: "x402_payment_required";
297
+ x402Version: number;
298
+ error: string;
299
+ message: string;
300
+ quote: {
301
+ id: string;
302
+ rentalCode: string;
303
+ offerId: string;
304
+ gpuModel: string;
305
+ gpuCount: number;
306
+ vramPerGpuGb: number;
307
+ region: string;
308
+ durationHours: number;
309
+ diskGb: number;
310
+ dockerImage: string;
311
+ hourlyPriceUsd: number;
312
+ platformFeeBps: number;
313
+ totalUsd: number;
314
+ holderTier: HolderTierId;
315
+ paymentAsset: "LTNS" | "USDG" | "ETH";
316
+ paymentAmountRaw: string;
317
+ paymentAmountFormatted: string;
318
+ treasuryWallet: string;
319
+ escrowContract: string | null;
320
+ escrowLeaseId: string;
321
+ quoteExpiresAt: string;
322
+ };
323
+ accepts: Array<Record<string, unknown>>;
324
+ }
325
+
326
+ export interface X402ExecutionReceipt {
327
+ object: "x402_execution_receipt";
328
+ settled: boolean;
329
+ rental: Record<string, unknown>;
330
+ credentials: {
331
+ rentalAccessToken: string;
332
+ pollEndpoint: string;
333
+ authorizationHeader: string;
334
+ };
335
+ }