browser-use-sdk 3.5.0 → 3.8.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/dist/v3.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { H as HttpClient } from './errors-BtB79l7x.js';
3
- export { B as BrowserUseError } from './errors-BtB79l7x.js';
2
+ import { H as HttpClient, X as X402Client } from './errors-DaHgFhIQ.js';
3
+ export { B as BrowserUseError, a as X402WalletBalance, g as getWalletBalance } from './errors-DaHgFhIQ.js';
4
4
 
5
5
  interface components {
6
6
  schemas: {
@@ -908,118 +908,10 @@ interface components {
908
908
  * @enum {string}
909
909
  */
910
910
  ProxyCountryCode: "ad" | "ae" | "af" | "ag" | "ai" | "al" | "am" | "an" | "ao" | "aq" | "ar" | "as" | "at" | "au" | "aw" | "az" | "ba" | "bb" | "bd" | "be" | "bf" | "bg" | "bh" | "bi" | "bj" | "bl" | "bm" | "bn" | "bo" | "bq" | "br" | "bs" | "bt" | "bv" | "bw" | "by" | "bz" | "ca" | "cc" | "cd" | "cf" | "cg" | "ch" | "ck" | "cl" | "cm" | "co" | "cr" | "cs" | "cu" | "cv" | "cw" | "cx" | "cy" | "cz" | "de" | "dj" | "dk" | "dm" | "do" | "dz" | "ec" | "ee" | "eg" | "eh" | "er" | "es" | "et" | "fi" | "fj" | "fk" | "fm" | "fo" | "fr" | "ga" | "gd" | "ge" | "gf" | "gg" | "gh" | "gi" | "gl" | "gm" | "gn" | "gp" | "gq" | "gr" | "gs" | "gt" | "gu" | "gw" | "gy" | "hk" | "hm" | "hn" | "hr" | "ht" | "hu" | "id" | "ie" | "il" | "im" | "in" | "iq" | "ir" | "is" | "it" | "je" | "jm" | "jo" | "jp" | "ke" | "kg" | "kh" | "ki" | "km" | "kn" | "kp" | "kr" | "kw" | "ky" | "kz" | "la" | "lb" | "lc" | "li" | "lk" | "lr" | "ls" | "lt" | "lu" | "lv" | "ly" | "ma" | "mc" | "md" | "me" | "mf" | "mg" | "mh" | "mk" | "ml" | "mm" | "mn" | "mo" | "mp" | "mq" | "mr" | "ms" | "mt" | "mu" | "mv" | "mw" | "mx" | "my" | "mz" | "na" | "nc" | "ne" | "nf" | "ng" | "ni" | "nl" | "no" | "np" | "nr" | "nu" | "nz" | "om" | "pa" | "pe" | "pf" | "pg" | "ph" | "pk" | "pl" | "pm" | "pn" | "pr" | "ps" | "pt" | "pw" | "py" | "qa" | "re" | "ro" | "rs" | "ru" | "rw" | "sa" | "sb" | "sc" | "sd" | "se" | "sg" | "sh" | "si" | "sj" | "sk" | "sl" | "sm" | "sn" | "so" | "sr" | "ss" | "st" | "sv" | "sx" | "sy" | "sz" | "tc" | "td" | "tf" | "tg" | "th" | "tj" | "tk" | "tl" | "tm" | "tn" | "to" | "tr" | "tt" | "tv" | "tw" | "tz" | "ua" | "ug" | "uk" | "us" | "uy" | "uz" | "va" | "vc" | "ve" | "vg" | "vi" | "vn" | "vu" | "wf" | "ws" | "xk" | "ye" | "yt" | "za" | "zm" | "zw";
911
- /**
912
- * RunTaskRequest
913
- * @description Create a new session, dispatch a task, or both.
914
- *
915
- * - **No `sessionId` + no `task`**: creates an idle session (useful for uploading files before running a task).
916
- * - **No `sessionId` + `task`**: creates a new session and immediately runs the task.
917
- * - **`sessionId` + `task`**: dispatches the task to an existing idle session.
918
- * - **`sessionId` + no `task`**: returns 422 — a task is required when targeting an existing session.
919
- */
911
+ /** RunTaskRequest */
920
912
  RunTaskRequest: {
921
- /**
922
- * Task
923
- * @description The natural-language instruction for the agent to execute (e.g. "Go to amazon.com and find the best-rated wireless mouse under $50"). Required when dispatching to an existing session.
924
- */
925
- task?: string | null;
926
- /**
927
- * @description The model to use. "gemini-3-flash" is fast and cheap, "claude-sonnet-4.6" is balanced, "claude-opus-4.7" is most capable (default). See BuModel for details.
928
- * @default claude-opus-4.7
929
- */
930
- model: components["schemas"]["BuModel"];
931
- /**
932
- * Sessionid
933
- * @description ID of an existing idle session to dispatch the task to. If omitted, a new session is created.
934
- */
935
- sessionId?: string | null;
936
- /**
937
- * Keepalive
938
- * @description If true, the session stays alive in idle state after the task completes instead of automatically stopping. This lets you dispatch follow-up tasks to the same session, preserving browser state and files.
939
- * @default false
940
- */
941
- keepAlive: boolean;
942
- /**
943
- * Maxcostusd
944
- * @description Maximum total cost in USD allowed for this session. The task will be stopped if this limit is reached. If omitted, a default limit applies (capped by your available balance). When dispatching a follow-up task to an existing session (`sessionId` is set), supplying this value overrides the session's budget for the upcoming dispatch; otherwise the budget is automatically refreshed to current spend + default.
945
- */
946
- maxCostUsd?: number | string | null;
947
- /**
948
- * Profileid
949
- * @description ID of a browser profile to load into the session. Profiles persist cookies, local storage, and other browser state across sessions. Create profiles via the Profiles API.
950
- */
951
- profileId?: string | null;
952
- /**
953
- * Workspaceid
954
- * @description ID of a workspace to attach to the session. Workspaces provide persistent file storage that carries across sessions. Create workspaces via the Workspaces API.
955
- */
956
- workspaceId?: string | null;
957
- /**
958
- * @description Country code for the browser proxy (e.g. "US", "DE", "JP"). Set to null to disable the proxy. The proxy routes browser traffic through the specified country, useful for accessing geo-restricted content.
959
- * @default us
960
- */
961
- proxyCountryCode: components["schemas"]["ProxyCountryCode"] | null;
962
- /**
963
- * Outputschema
964
- * @description A JSON Schema that the agent's final output must conform to. When set, the agent will return structured data matching this schema in the `output` field of the response. Example: {"type": "object", "properties": {"price": {"type": "number"}, "title": {"type": "string"}}}.
965
- */
966
- outputSchema?: {
967
- [key: string]: unknown;
968
- } | null;
969
- /**
970
- * Enablescheduledtasks
971
- * @description If true, the agent can create scheduled tasks that run on a recurring basis (e.g. "every Monday morning, check my inbox and summarize new emails"). Scheduled tasks are tied to your project and persist beyond the session. Note: all scheduled tasks are visible project-wide, so avoid enabling this in multi-user setups where task isolation is needed.
972
- * @default false
973
- */
974
- enableScheduledTasks: boolean;
975
- /**
976
- * Sensitivedata
977
- * @description Key-value pairs of sensitive data (e.g. passwords, API keys) that the agent can use via secure placeholders. Keys are exposed to the LLM; values are never shown. The agent uses `<secret>key</secret>` placeholders in browser_type_text to securely enter values.
978
- */
979
- sensitiveData?: {
980
- [key: string]: string;
981
- } | null;
982
- /**
983
- * Enablerecording
984
- * @description If true, records a video of the browser session. The recording URLs will be available in the `recordingUrls` field of the session response after the task completes.
985
- * @default false
986
- */
987
- enableRecording: boolean;
988
- /**
989
- * Skills
990
- * @description If true, enables built-in agent skills like Google Sheets integration and file management. Set to false to restrict the agent to browser-only actions.
991
- * @default true
992
- */
993
- skills: boolean;
994
- /**
995
- * Agentmail
996
- * @description If true, provisions a temporary email inbox (via AgentMail) for the session. The email address is available in the `agentmailEmail` field of the session response. Useful for tasks that require email verification or sign-ups.
997
- * @default true
998
- */
999
- agentmail: boolean;
1000
- /**
1001
- * Codemode
1002
- * @description When true, the agent returns structured output with `text` (summary) and `code` (validated Python source) fields instead of free-form text.
1003
- * @default false
1004
- */
1005
- codeMode: boolean;
1006
- /**
1007
- * Cachescript
1008
- * @description Controls deterministic script caching. `null` (default): auto-detected — enabled when the task contains `@{{value}}` brackets and a workspace is attached. `true`: force-enable script caching even without brackets (caches the exact task). `false`: force-disable, even if brackets are present. When active, the first call runs the full agent and saves a reusable script. Subsequent calls with the same task template execute the cached script with $0 LLM cost. Requires workspace_id when enabled. Example: "Get prices from @{{https://example.com}} for @{{electronics}}".
1009
- */
1010
- cacheScript?: boolean | null;
1011
- /**
1012
- * Useownkey
1013
- * @description If true, uses your own LLM API key (configured in project settings) instead of Browser Use managed keys. You pay your provider directly for inference; Browser Use charges a reduced orchestration fee (0.2× of provider list prices). If no key is configured for the model's provider, the request is rejected.
1014
- * @default false
1015
- */
1016
- useOwnKey: boolean;
1017
- /**
1018
- * Autoheal
1019
- * @description When cache_script is active, controls whether a lightweight LLM validates the cached script output. If the output looks incorrect (empty, error, wrong structure), the system automatically re-triggers the full agent to generate a new version of the script. Set to false to disable validation and always return the raw script output.
1020
- * @default true
1021
- */
1022
- autoHeal: boolean;
913
+ /** Prompt */
914
+ prompt: string;
1023
915
  };
1024
916
  /** SessionListResponse */
1025
917
  SessionListResponse: {
@@ -1319,10 +1211,12 @@ interface components {
1319
1211
  * TrialEligibilityView
1320
1212
  * @description GET /me/trial-eligibility — is this user eligible for a free trial?
1321
1213
  *
1214
+ * Account-scoped — paid users see this too (one free trial per user,
1215
+ * regardless of payment tier).
1216
+ *
1322
1217
  * `reason` is a stable machine-readable code the FE branches on:
1323
1218
  * - 'already_used' — user has already started a trial in their
1324
1219
  * lifetime. Render an "upgrade to deploy" CTA.
1325
- * - 'not_free_tier' — paying customer; FE shows the normal flow.
1326
1220
  * - 'no_owner' — couldn't resolve the project's owner profile (rare,
1327
1221
  * older projects). FE falls back to generic "add credits" copy.
1328
1222
  * - None when eligible=True.
@@ -1331,7 +1225,7 @@ interface components {
1331
1225
  /** Eligible */
1332
1226
  eligible: boolean;
1333
1227
  /** Reason */
1334
- reason?: ("already_used" | "not_free_tier" | "no_owner") | null;
1228
+ reason?: ("already_used" | "no_owner") | null;
1335
1229
  /** Message */
1336
1230
  message?: string | null;
1337
1231
  };
@@ -1476,10 +1370,118 @@ interface components {
1476
1370
  */
1477
1371
  updatedAt: string;
1478
1372
  };
1479
- /** RunTaskRequest */
1480
- app__endpoints__api__v3__boxes__views__RunTaskRequest: {
1481
- /** Prompt */
1482
- prompt: string;
1373
+ /**
1374
+ * RunTaskRequest
1375
+ * @description Create a new session, dispatch a task, or both.
1376
+ *
1377
+ * - **No `sessionId` + no `task`**: creates an idle session (useful for uploading files before running a task).
1378
+ * - **No `sessionId` + `task`**: creates a new session and immediately runs the task.
1379
+ * - **`sessionId` + `task`**: dispatches the task to an existing idle session.
1380
+ * - **`sessionId` + no `task`**: returns 422 — a task is required when targeting an existing session.
1381
+ */
1382
+ app__endpoints__api__v3__sessions__views__RunTaskRequest: {
1383
+ /**
1384
+ * Task
1385
+ * @description The natural-language instruction for the agent to execute (e.g. "Go to amazon.com and find the best-rated wireless mouse under $50"). Required when dispatching to an existing session.
1386
+ */
1387
+ task?: string | null;
1388
+ /**
1389
+ * @description The model to use. "gemini-3-flash" is fast and cheap, "claude-sonnet-4.6" is balanced, "claude-opus-4.7" is most capable (default). See BuModel for details.
1390
+ * @default claude-opus-4.7
1391
+ */
1392
+ model: components["schemas"]["BuModel"];
1393
+ /**
1394
+ * Sessionid
1395
+ * @description ID of an existing idle session to dispatch the task to. If omitted, a new session is created.
1396
+ */
1397
+ sessionId?: string | null;
1398
+ /**
1399
+ * Keepalive
1400
+ * @description If true, the session stays alive in idle state after the task completes instead of automatically stopping. This lets you dispatch follow-up tasks to the same session, preserving browser state and files.
1401
+ * @default false
1402
+ */
1403
+ keepAlive: boolean;
1404
+ /**
1405
+ * Maxcostusd
1406
+ * @description Maximum total cost in USD allowed for this session. The task will be stopped if this limit is reached. If omitted, a default limit applies (capped by your available balance). When dispatching a follow-up task to an existing session (`sessionId` is set), supplying this value overrides the session's budget for the upcoming dispatch; otherwise the budget is automatically refreshed to current spend + default.
1407
+ */
1408
+ maxCostUsd?: number | string | null;
1409
+ /**
1410
+ * Profileid
1411
+ * @description ID of a browser profile to load into the session. Profiles persist cookies, local storage, and other browser state across sessions. Create profiles via the Profiles API.
1412
+ */
1413
+ profileId?: string | null;
1414
+ /**
1415
+ * Workspaceid
1416
+ * @description ID of a workspace to attach to the session. Workspaces provide persistent file storage that carries across sessions. Create workspaces via the Workspaces API.
1417
+ */
1418
+ workspaceId?: string | null;
1419
+ /**
1420
+ * @description Country code for the browser proxy (e.g. "US", "DE", "JP"). Set to null to disable the proxy. The proxy routes browser traffic through the specified country, useful for accessing geo-restricted content.
1421
+ * @default us
1422
+ */
1423
+ proxyCountryCode: components["schemas"]["ProxyCountryCode"] | null;
1424
+ /**
1425
+ * Outputschema
1426
+ * @description A JSON Schema that the agent's final output must conform to. When set, the agent will return structured data matching this schema in the `output` field of the response. Example: {"type": "object", "properties": {"price": {"type": "number"}, "title": {"type": "string"}}}.
1427
+ */
1428
+ outputSchema?: {
1429
+ [key: string]: unknown;
1430
+ } | null;
1431
+ /**
1432
+ * Enablescheduledtasks
1433
+ * @description If true, the agent can create scheduled tasks that run on a recurring basis (e.g. "every Monday morning, check my inbox and summarize new emails"). Scheduled tasks are tied to your project and persist beyond the session. Note: all scheduled tasks are visible project-wide, so avoid enabling this in multi-user setups where task isolation is needed.
1434
+ * @default false
1435
+ */
1436
+ enableScheduledTasks: boolean;
1437
+ /**
1438
+ * Sensitivedata
1439
+ * @description Key-value pairs of sensitive data (e.g. passwords, API keys) that the agent can use via secure placeholders. Keys are exposed to the LLM; values are never shown. The agent uses `<secret>key</secret>` placeholders in browser_type_text to securely enter values.
1440
+ */
1441
+ sensitiveData?: {
1442
+ [key: string]: string;
1443
+ } | null;
1444
+ /**
1445
+ * Enablerecording
1446
+ * @description If true, records a video of the browser session. The recording URLs will be available in the `recordingUrls` field of the session response after the task completes.
1447
+ * @default false
1448
+ */
1449
+ enableRecording: boolean;
1450
+ /**
1451
+ * Skills
1452
+ * @description If true, enables built-in agent skills like Google Sheets integration and file management. Set to false to restrict the agent to browser-only actions.
1453
+ * @default true
1454
+ */
1455
+ skills: boolean;
1456
+ /**
1457
+ * Agentmail
1458
+ * @description If true, provisions a temporary email inbox (via AgentMail) for the session. The email address is available in the `agentmailEmail` field of the session response. Useful for tasks that require email verification or sign-ups.
1459
+ * @default true
1460
+ */
1461
+ agentmail: boolean;
1462
+ /**
1463
+ * Codemode
1464
+ * @description When true, the agent returns structured output with `text` (summary) and `code` (validated Python source) fields instead of free-form text.
1465
+ * @default false
1466
+ */
1467
+ codeMode: boolean;
1468
+ /**
1469
+ * Cachescript
1470
+ * @description Controls deterministic script caching. `null` (default): auto-detected — enabled when the task contains `@{{value}}` brackets and a workspace is attached. `true`: force-enable script caching even without brackets (caches the exact task). `false`: force-disable, even if brackets are present. When active, the first call runs the full agent and saves a reusable script. Subsequent calls with the same task template execute the cached script with $0 LLM cost. Requires workspace_id when enabled. Example: "Get prices from @{{https://example.com}} for @{{electronics}}".
1471
+ */
1472
+ cacheScript?: boolean | null;
1473
+ /**
1474
+ * Useownkey
1475
+ * @description If true, uses your own LLM API key (configured in project settings) instead of Browser Use managed keys. You pay your provider directly for inference; Browser Use charges a reduced orchestration fee (0.2× of provider list prices). If no key is configured for the model's provider, the request is rejected.
1476
+ * @default false
1477
+ */
1478
+ useOwnKey: boolean;
1479
+ /**
1480
+ * Autoheal
1481
+ * @description When cache_script is active, controls whether a lightweight LLM validates the cached script output. If the output looks incorrect (empty, error, wrong structure), the system automatically re-triggers the full agent to generate a new version of the script. Set to false to disable validation and always return the raw script output.
1482
+ * @default true
1483
+ */
1484
+ autoHeal: boolean;
1483
1485
  };
1484
1486
  };
1485
1487
  responses: never;
@@ -1553,7 +1555,7 @@ declare class Profiles {
1553
1555
  delete(profileId: string): Promise<void>;
1554
1556
  }
1555
1557
 
1556
- type RunTaskRequest$2 = components["schemas"]["RunTaskRequest"];
1558
+ type RunTaskRequest$2 = components["schemas"]["app__endpoints__api__v3__sessions__views__RunTaskRequest"];
1557
1559
  /** All fields optional — omit `task` to create an idle session. */
1558
1560
  type CreateSessionBody = Partial<RunTaskRequest$2>;
1559
1561
  type SessionResponse$2 = components["schemas"]["SessionResponse"];
@@ -1569,9 +1571,13 @@ interface SessionMessagesParams {
1569
1571
  before?: string | null;
1570
1572
  limit?: number;
1571
1573
  }
1574
+ interface SessionsOptions {
1575
+ useOwnKey?: boolean;
1576
+ }
1572
1577
  declare class Sessions {
1573
1578
  private readonly http;
1574
- constructor(http: HttpClient);
1579
+ private readonly options;
1580
+ constructor(http: HttpClient, options?: SessionsOptions);
1575
1581
  /** Create a session and optionally dispatch a task. */
1576
1582
  create(body?: CreateSessionBody): Promise<SessionResponse$2>;
1577
1583
  /** List sessions for the authenticated project. */
@@ -1716,12 +1722,29 @@ declare class SessionRun<T = string> implements PromiseLike<SessionResult<T>> {
1716
1722
  private _parseOutput;
1717
1723
  }
1718
1724
 
1719
- type RunTaskRequest$1 = components["schemas"]["RunTaskRequest"];
1725
+ type RunTaskRequest$1 = components["schemas"]["app__endpoints__api__v3__sessions__views__RunTaskRequest"];
1720
1726
  interface BrowserUseOptions {
1721
1727
  apiKey?: string;
1722
1728
  baseUrl?: string;
1723
1729
  maxRetries?: number;
1724
1730
  timeout?: number;
1731
+ /**
1732
+ * Use your own LLM API key configured in Browser Use project settings for v3 agent runs.
1733
+ */
1734
+ useOwnKey?: boolean;
1735
+ /**
1736
+ * Pre-built x402 client (advanced — for custom signers / multi-network).
1737
+ * If set, the SDK uses pay-per-request authentication via USDC instead of
1738
+ * an API key. Requires the optional peer deps `@x402/fetch`, `@x402/evm`,
1739
+ * and `viem`.
1740
+ */
1741
+ x402?: X402Client;
1742
+ /**
1743
+ * EVM wallet private key for x402 mode. Equivalent to building an x402
1744
+ * client from this key and passing it as `x402`. Falls back to
1745
+ * `BROWSER_USE_X402_PRIVATE_KEY`.
1746
+ */
1747
+ x402PrivateKey?: string;
1725
1748
  }
1726
1749
  type RunSessionOptions = Partial<Omit<RunTaskRequest$1, "task">> & RunOptions & {
1727
1750
  schema?: z.ZodType;
@@ -1764,7 +1787,7 @@ type MessageListResponse = S["MessageListResponse"];
1764
1787
  type MessageResponse = S["MessageResponse"];
1765
1788
  type WorkspaceView = S["WorkspaceView"];
1766
1789
  type WorkspaceListResponse = S["WorkspaceListResponse"];
1767
- type RunTaskRequest = S["RunTaskRequest"];
1790
+ type RunTaskRequest = S["app__endpoints__api__v3__sessions__views__RunTaskRequest"];
1768
1791
  type StopSessionRequest = S["StopSessionRequest"];
1769
1792
  type FileUploadRequest = S["FileUploadRequest"];
1770
1793
  type FileUploadItem = S["FileUploadItem"];
@@ -1790,4 +1813,4 @@ type BuModel = S["BuModel"];
1790
1813
  type ProxyCountryCode = S["ProxyCountryCode"];
1791
1814
  type StopStrategy = S["StopStrategy"];
1792
1815
 
1793
- export { type AccountView, Billing, type BrowserDownloadFile, type BrowserDownloadListResponse, type BrowserDownloadsParams, type BrowserListParams, type BrowserSessionItemView, type BrowserSessionListResponse, type BrowserSessionStatus, type BrowserSessionUpdateAction, type BrowserSessionView, BrowserUse, type BrowserUseOptions, Browsers, type BuAgentSessionStatus, type BuModel, type CreateBrowserSessionRequest, type CreateSessionBody, type FileInfo, type FileListResponse, type FileUploadItem, type FileUploadRequest, type FileUploadResponse, type FileUploadResponseItem, type MessageListResponse, type MessageResponse, type PlanInfo, type ProfileCreateRequest, type ProfileListParams, type ProfileListResponse, type ProfileUpdateRequest, type ProfileView, Profiles, type ProxyCountryCode, type RunOptions, type RunSessionOptions, type RunTaskRequest, type SessionListParams, type SessionListResponse, type SessionMessagesParams, type SessionResponse, type SessionResult, SessionRun, Sessions, type StopSessionRequest, type StopStrategy, type UpdateBrowserSessionRequest, type components as V3Types, type WorkspaceCreateRequest, type WorkspaceFilesParams, type WorkspaceListParams, type WorkspaceListResponse, type WorkspaceUpdateRequest, type WorkspaceView, Workspaces };
1816
+ export { type AccountView, Billing, type BrowserDownloadFile, type BrowserDownloadListResponse, type BrowserDownloadsParams, type BrowserListParams, type BrowserSessionItemView, type BrowserSessionListResponse, type BrowserSessionStatus, type BrowserSessionUpdateAction, type BrowserSessionView, BrowserUse, type BrowserUseOptions, Browsers, type BuAgentSessionStatus, type BuModel, type CreateBrowserSessionRequest, type CreateSessionBody, type FileInfo, type FileListResponse, type FileUploadItem, type FileUploadRequest, type FileUploadResponse, type FileUploadResponseItem, type MessageListResponse, type MessageResponse, type PlanInfo, type ProfileCreateRequest, type ProfileListParams, type ProfileListResponse, type ProfileUpdateRequest, type ProfileView, Profiles, type ProxyCountryCode, type RunOptions, type RunSessionOptions, type RunTaskRequest, type SessionListParams, type SessionListResponse, type SessionMessagesParams, type SessionResponse, type SessionResult, SessionRun, Sessions, type SessionsOptions, type StopSessionRequest, type StopStrategy, type UpdateBrowserSessionRequest, type components as V3Types, type WorkspaceCreateRequest, type WorkspaceFilesParams, type WorkspaceListParams, type WorkspaceListResponse, type WorkspaceUpdateRequest, type WorkspaceView, Workspaces };
package/dist/v3.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import {
2
2
  BrowserUseError,
3
- HttpClient
4
- } from "./chunk-6TSB5AIP.js";
3
+ HttpClient,
4
+ X402_BASE_URL_DEFAULT,
5
+ getWalletBalance,
6
+ wrapFetchWithX402,
7
+ x402ClientFromPrivateKey
8
+ } from "./chunk-ESJIWN3M.js";
5
9
 
6
10
  // src/v3/client.ts
7
11
  import { z } from "zod";
@@ -80,12 +84,17 @@ var Profiles = class {
80
84
 
81
85
  // src/v3/resources/sessions.ts
82
86
  var Sessions = class {
83
- constructor(http) {
87
+ constructor(http, options = {}) {
84
88
  this.http = http;
89
+ this.options = options;
85
90
  }
86
91
  /** Create a session and optionally dispatch a task. */
87
92
  create(body) {
88
- return this.http.post("/sessions", body ?? {});
93
+ const requestBody = { ...body ?? {} };
94
+ if (this.options.useOwnKey !== void 0 && requestBody.useOwnKey === void 0) {
95
+ requestBody.useOwnKey = this.options.useOwnKey;
96
+ }
97
+ return this.http.post("/sessions", requestBody);
89
98
  }
90
99
  /** List sessions for the authenticated project. */
91
100
  list(params) {
@@ -419,22 +428,40 @@ var BrowserUse = class {
419
428
  workspaces;
420
429
  http;
421
430
  constructor(options = {}) {
422
- const apiKey = options.apiKey ?? process.env.BROWSER_USE_API_KEY ?? "";
423
- if (!apiKey) {
424
- throw new Error(
425
- "No API key provided. Pass apiKey or set BROWSER_USE_API_KEY."
426
- );
431
+ const x402PrivateKey = options.x402PrivateKey ?? process.env.BROWSER_USE_X402_PRIVATE_KEY;
432
+ if (options.x402 || x402PrivateKey) {
433
+ const topupKey = options.apiKey ?? process.env.BROWSER_USE_API_KEY ?? "";
434
+ const fetchPromise = (async () => {
435
+ const x402Client = options.x402 ?? await x402ClientFromPrivateKey(x402PrivateKey);
436
+ return wrapFetchWithX402(globalThis.fetch, x402Client);
437
+ })();
438
+ fetchPromise.catch(() => {
439
+ });
440
+ this.http = new HttpClient({
441
+ apiKey: topupKey,
442
+ baseUrl: options.baseUrl ?? X402_BASE_URL_DEFAULT,
443
+ maxRetries: options.maxRetries,
444
+ timeout: options.timeout,
445
+ fetch: fetchPromise
446
+ });
447
+ } else {
448
+ const apiKey = options.apiKey ?? process.env.BROWSER_USE_API_KEY ?? "";
449
+ if (!apiKey) {
450
+ throw new Error(
451
+ "No credentials provided. Pass apiKey / set BROWSER_USE_API_KEY, or pass x402PrivateKey / set BROWSER_USE_X402_PRIVATE_KEY for pay-per-request access via USDC."
452
+ );
453
+ }
454
+ this.http = new HttpClient({
455
+ apiKey,
456
+ baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
457
+ maxRetries: options.maxRetries,
458
+ timeout: options.timeout
459
+ });
427
460
  }
428
- this.http = new HttpClient({
429
- apiKey,
430
- baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
431
- maxRetries: options.maxRetries,
432
- timeout: options.timeout
433
- });
434
461
  this.billing = new Billing(this.http);
435
462
  this.browsers = new Browsers(this.http);
436
463
  this.profiles = new Profiles(this.http);
437
- this.sessions = new Sessions(this.http);
464
+ this.sessions = new Sessions(this.http, { useOwnKey: options.useOwnKey });
438
465
  this.workspaces = new Workspaces(this.http);
439
466
  }
440
467
  run(task, options) {
@@ -482,6 +509,7 @@ export {
482
509
  Profiles,
483
510
  SessionRun,
484
511
  Sessions,
485
- Workspaces
512
+ Workspaces,
513
+ getWalletBalance
486
514
  };
487
515
  //# sourceMappingURL=v3.js.map