x402

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Browser Use Cloud — pay with x402 (crypto wallet)

Browser Use Cloud — 使用x402(加密钱包)支付

This is a scripted flow. Follow the steps in order. x402 only works through the SDK (
browser-use-sdk
for Python, the
browser-use
npm package for TS) — there is no
browser-use
CLI command for it, so every step runs a short SDK script.
这是一个脚本化流程,请按顺序执行步骤。x402仅通过SDK(Python版为
browser-use-sdk
,TS版为
browser-use
npm包)工作——没有对应的
browser-use
CLI命令,因此每一步都需要运行一段简短的SDK脚本。

How to use this script

如何使用本脚本

  • Lines under Say: are spoken to the user word for word. Don't paraphrase, add, or drop anything.
  • <like this>
    inside a Say block is a fill-in — replace it with the real value, keep the rest exact.
  • Lines under Ask: use the AskUserQuestion tool. Use the question and option text exactly as written.
  • To show an explanation before a question, put it inside the AskUserQuestion
    question
    field
    (it renders above the options). Don't send it as separate chat text before calling the tool — that text gets dropped when the question UI opens. So: explanation + the actual question both go in the
    question
    field, in one tool call.
  • Lines under Do: are your actions. Don't read them out.
  • Track two facts as you go:
    SETUP
    (A or B, from Step 1) and
    MODE
    (A or B, from Step 2).
  • SETUP
    ,
    MODE
    , and the Path A/B/C names are internal labels for you only. Never say them to the user.
    Describe choices in plain words instead (e.g. "top up your account" / "accountless wallet"), never "Mode B" or "Path A".

  • Say: 下的内容需一字不差地告知用户,不得改写、添加或删减内容。
  • Say块中的
    <like this>
    为填充内容——替换为实际值,其余内容保持原样。
  • Ask: 下的内容需使用AskUserQuestion工具,问题和选项文本需完全按原文使用。
  • 如需在提问前展示说明,请将说明放入AskUserQuestion的
    question
    字段
    (会在选项上方显示)。不要在调用工具前单独发送该文本——打开问题UI时,该文本会被丢弃。因此:说明+实际问题需一同放入
    question
    字段,通过一次工具调用发送。
  • Do: 下的内容是您需要执行的操作,无需读出。
  • 流程中需跟踪两个信息:
    SETUP
    (步骤1的A或B)和
    MODE
    (步骤2的A或B)。
  • **
    SETUP
    MODE
    以及路径A/B/C名称仅为您的内部标记,绝不能告知用户。**请用通俗语言描述选项(例如“为您的账户充值”/“无账户钱包”),绝不能说“Mode B”或“Path A”。

Step 1 — Open and pick the setup

步骤1 — 选择设置方式

Ask: (header:
Use x402
) — put the explanation and the question both in the
question
field, exactly:
x402 is a protocol from Coinbase that, instead of presenting an API key, allows you to use crypto to pay for API requests. x402 lets you pay Browser Use per request from a crypto wallet with USDC on Base — no signup, API key, or credit card needed, just a wallet. Setup takes a few minutes: get or make a wallet, add funds, save the key in
.env
, and test it.
How do you want to use x402?
  • Just use it — Run Browser Use tasks, paid from your wallet, here in terminal by asking me. I set up the wallet and key.
  • Build it in — You're coding an app and want x402 in it. I will help you install the SDK, save the key to your project's
    .env
    , and add code.
Do: "Just use it" →
SETUP = A
. "Build it in" →
SETUP = B
.

Ask:(标题:
使用x402
)——将说明和问题一同放入
question
字段,内容如下:
x402是Coinbase推出的协议,无需提供API密钥,即可使用加密货币支付API请求费用。x402允许您通过Base主网的USDC加密钱包按请求支付Browser Use费用——无需注册、API密钥或信用卡,只需一个钱包即可。设置仅需几分钟:获取或创建钱包、充值、在
.env
中保存密钥并进行测试。
您希望如何使用x402?
  • 直接使用——在终端中让我运行Browser Use任务,费用从您的钱包扣除。我会帮您设置钱包和密钥。
  • 集成到项目——您正在开发应用,希望将x402集成其中。我会帮您安装SDK、将密钥保存到项目的
    .env
    并添加代码。
Do: 选择“直接使用”→
SETUP = A
;选择“集成到项目”→
SETUP = B

Step 2 — Find the account (check before asking)

步骤2 — 检查账户(提问前先执行)

Do: Look for an existing Browser Use API key, in this order. Don't say anything yet.
  1. BROWSER_USE_API_KEY
    in the environment
  2. a
    BROWSER_USE_API_KEY=
    line in
    ./.env
  3. ~/.browser-use/config.json
    (saved by
    browser-use cloud login
    /
    signup
    )
  4. browser-use doctor
    output, if the CLI is installed
If no key is found anywhere:
Say:
No Browser Use key found, so I'll set this up accountless: the wallet is your identity, and the first payment makes a project named after it.
Do:
MODE = A
. Go to Step 3.
If a key is found:
Ask: (header:
Account
) — question:
I found a Browser Use API key in <location>. Where should the USDC credits go?
  • Top up that account — Credits go to your existing API key's project. Good if your free credits ran out, or you'd rather pay with crypto than a card.
  • Accountless wallet — The wallet is a separate identity. The first payment makes a fresh project named after the wallet, apart from your existing account.
Do: "Top up that account" →
MODE = B
. "Accountless wallet" →
MODE = A
.

Do: 按以下顺序查找现有的Browser Use API密钥,暂不告知用户。
  1. 环境变量中的
    BROWSER_USE_API_KEY
  2. ./.env
    文件中的
    BROWSER_USE_API_KEY=
  3. ~/.browser-use/config.json
    (由
    browser-use cloud login
    /
    signup
    保存)
  4. 若已安装CLI,查看
    browser-use doctor
    的输出
若未找到任何密钥:
Say:
未找到Browser Use密钥,因此我将设置无账户模式:钱包即为您的身份标识,首次支付会创建一个以钱包命名的项目。
Do:
MODE = A
,进入步骤3。
若找到密钥:
Ask:(标题:
账户
)——问题:
我在<位置>找到一个Browser Use API密钥。USDC额度应存入何处?
  • 为该账户充值——额度存入您现有API密钥对应的项目。适合免费额度用完,或更倾向于用加密货币而非银行卡支付的场景。
  • 无账户钱包——钱包作为独立身份标识。首次支付会创建一个以钱包命名的全新项目,与您现有账户分离。
Do: 选择“为该账户充值”→
MODE = B
;选择“无账户钱包”→
MODE = A

Step 3 — Wallet

步骤3 — 钱包设置

Ask: (header:
Wallet
) — question:
Do you have a wallet ready, or should I set one up?
  • I have a funded wallet — An EVM wallet (MetaMask, Rabby, Coinbase Wallet, Frame, Phantom, …) with USDC on Base mainnet.
  • Walk me through it — I'll guide you through making a wallet, adding Base, and buying USDC.
  • Make a fresh one — I'll generate a throwaway wallet for automation. You'll still need to fund it.
Branch on the answer.
Ask:(标题:
钱包
)——问题:
您已准备好钱包,还是需要我帮您设置?
  • 我已有充值后的钱包——一个包含Base主网USDC的EVM钱包(MetaMask、Rabby、Coinbase Wallet、Frame、Phantom等)。
  • 引导我完成设置——我会指导您创建钱包、添加Base网络并购买USDC。
  • 创建新钱包——我会生成一个用于自动化的临时钱包,您仍需为其充值。
根据回答进入对应分支。

Path A — "I have a funded wallet"

路径A — “我已有充值后的钱包”

Do: Check
.env
is in
.gitignore
; add it if missing.
Ask: (header:
Add key
) — put the note and the question both in the
question
field:
Your wallet's private key needs to go into
.env
. You can paste it here and I'll add it for you, or add it yourself. Heads up: anything pasted in chat is saved in the transcript, so for a high-value wallet, adding it yourself is a bit safer. How do you want to do it?
  • Paste it here — Paste your private key in the chat and I'll write it to
    .env
    for you.
  • I'll add it myself — You add it to
    .env
    , then send me just your public address.
If "Paste it here":
Do: Write
BROWSER_USE_X402_PRIVATE_KEY=<pasted key>
to
.env
(create the file if needed; make sure
.env
is gitignored). Never echo the key back or print it anywhere.
Say:
Saved your key to
.env
— I won't print it back.
Do: Go to Step 4.
If "I'll add it myself":
Say:
Add this line to your
.env
, then send me your wallet's public address (the
0x…
one — safe to share):
BROWSER_USE_X402_PRIVATE_KEY=<your private key>
Do: When they send the address, check it matches
^0x[0-9a-fA-F]{40}$
.
Say:
Got it:
<address>
. That's a valid address.
Do: Go to Step 4.
Do: 检查
.env
是否在
.gitignore
中;若未添加则补充。
Ask:(标题:
添加密钥
)——将提示和问题一同放入
question
字段:
您钱包的私钥需要放入
.env
文件。您可以在此粘贴私钥,我会帮您添加;也可以自行添加。注意:聊天中粘贴的任何内容都会保存到对话记录中,因此对于高价值钱包,自行添加会更安全。您希望如何操作?
  • 在此粘贴——在聊天中粘贴您的私钥,我会帮您写入
    .env
  • 我自行添加——您自行添加到
    .env
    ,然后仅将钱包的公钥发送给我。
若选择“在此粘贴”:
Do:
BROWSER_USE_X402_PRIVATE_KEY=<粘贴的密钥>
写入
.env
(若文件不存在则创建;确保
.env
已添加到git忽略列表)。绝不能回显或打印密钥。
Say:
已将您的密钥保存到
.env
——我不会回显该密钥。
Do: 进入步骤4。
若选择“我自行添加”:
Say:
将以下行添加到您的
.env
文件,然后发送您钱包的公钥(以
0x…
开头的地址,可安全分享):
BROWSER_USE_X402_PRIVATE_KEY=<您的私钥>
Do: 用户发送地址后,检查是否符合
^0x[0-9a-fA-F]{40}$
格式。
Say:
已收到:
<地址>
。这是一个有效的地址。
Do: 进入步骤4。

Path B — "Walk me through it"

路径B — “引导我完成设置”

Say:
  1. Install MetaMask (or Rabby, Coinbase Wallet, Frame, Trust Wallet, Phantom, …) from the official site only: https://metamask.io. Make a wallet, save the seed phrase offline, set a password.
  2. Add Base as a network. Open https://chainlist.org/chain/8453 → "Connect Wallet" → "Add to MetaMask", then approve it in your wallet.
  3. Click "Buy" in your wallet. Pick USDC, network Base, pay with card / Apple Pay / bank. The USDC lands straight in your wallet.
  4. Get the private key: account menu → Account details → Show private key → enter password → copy.
  5. Add it to your
    .env
    (make sure
    .env
    is gitignored):
BROWSER_USE_X402_PRIVATE_KEY=<your private key>
  1. Send me your wallet's public address (the
    0x…
    one) so I can check it.
Do: Then follow Path A from the address check onward.
Say:
  1. 仅从官方网站安装MetaMask(或Rabby、Coinbase Wallet、Frame、Trust Wallet、Phantom等):https://metamask.io。创建钱包,离线保存助记词,设置密码。
  2. 添加Base网络。打开https://chainlist.org/chain/8453 → “Connect Wallet” → “Add to MetaMask”,然后在钱包中确认。
  3. 点击钱包中的“Buy”按钮。选择USDC,网络选择Base,使用银行卡/Apple Pay/银行转账支付。USDC会直接存入您的钱包。
  4. 获取私钥:账户菜单→账户详情→显示私钥→输入密码→复制。
  5. 将其添加到您的
    .env
    文件(确保
    .env
    已添加到git忽略列表):
BROWSER_USE_X402_PRIVATE_KEY=<您的私钥>
  1. 将您钱包的公钥(以
    0x…
    开头的地址)发送给我,以便我验证。
Do: 之后按照路径A中的地址验证步骤继续。

Path C — "Make a fresh one"

路径C — “创建新钱包”

Do: Generate a wallet. Save the key to
.env
. Show the address only.
Python:
bash
pip install eth-account
python
from eth_account import Account
acc = Account.create()
print("Address:", acc.address)
print("Private key:", acc.key.hex())
TypeScript:
bash
npm install viem
typescript
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
const key = generatePrivateKey();
console.log("Address:", privateKeyToAccount(key).address);
console.log("Private key:", key);
Say:
Made a fresh wallet. Your public address is
<address>
, and I've saved the private key to
.env
. Now it needs funds.
Do: Go to Step 4 (funding).

Do: 生成钱包,将密钥保存到
.env
,仅展示地址。
Python:
bash
pip install eth-account
python
from eth_account import Account
acc = Account.create()
print("Address:", acc.address)
print("Private key:", acc.key.hex())
TypeScript:
bash
npm install viem
typescript
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
const key = generatePrivateKey();
console.log("Address:", privateKeyToAccount(key).address);
console.log("Private key:", key);
Say:
已创建新钱包。您的公钥地址是
<address>
,我已将私钥保存到
.env
。现在需要为其充值。
Do: 进入步骤4(充值)。

Step 4 — Add funds

步骤4 — 充值

If Path A or B (already funded):
Say:
Your wallet's already funded, so we'll skip ahead to the test.
Do: Go to Step 5.
If Path C:
Say:
Two ways to get USDC into your wallet on Base:
  • In-wallet Buy button (easiest): click "Buy", pick USDC, set the network to Base, pay with a card. No exchange needed.
  • From an exchange: send USDC to
    <address>
    and pick "Base" as the network — not Ethereum, which costs $5–$20 in fees.
Add at least $20: that covers the $1 test plus a few real tasks. I'll watch the balance and tell you when it lands.
Do: Check the on-chain balance every 5s with Base's public RPC:
bash
PADDED=$(printf "%064s" "${WALLET_ADDR:2}" | tr ' ' '0')
curl -s https://mainnet.base.org \
  -H "Content-Type: application/json" \
  -d "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{\"to\":\"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\"data\":\"0x70a08231${PADDED}\"},\"latest\"],\"id\":1}"
Read
result
as a hex number; divide by
1_000_000
(USDC has 6 decimals). Stop once it's $20 or more.
Say:
Funded — I see $<amount> on Base. Next, a quick test.

若为路径A或B(已充值):
Say:
您的钱包已充值,我们直接跳转到测试环节。
Do: 进入步骤5。
若为路径C:
Say:
有两种方式将USDC存入您的Base钱包:
  • 钱包内Buy按钮(最简单):点击“Buy”,选择USDC,设置网络为Base,使用银行卡支付。无需通过交易所。
  • 通过交易所:将USDC发送到
    <address>
    ,选择“Base”作为网络——不要选Ethereum,否则会产生5-20美元的手续费。
至少充值20美元:涵盖1美元的测试费用以及一些实际任务的费用。我会监控余额,到账后告知您。
Do: 每5秒通过Base的公共RPC检查链上余额:
bash
PADDED=$(printf "%064s" "${WALLET_ADDR:2}" | tr ' ' '0')
curl -s https://mainnet.base.org \
  -H "Content-Type: application/json" \
  -d "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{\"to\":\"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\"data\":\"0x70a08231${PADDED}\"},\"latest\"],\"id\":1}"
result
读取为十六进制数;除以
1_000_000
(USDC有6位小数)。当余额达到20美元或以上时停止检查。
Say:
充值完成——我在Base网络上看到您的余额为$<amount>。接下来进行快速测试。

Step 5 — Test run (~$1)

步骤5 — 测试运行(约1美元)

Do: If
SETUP = A
, make sure the SDK is installed where you'll run scripts (default Python). If
SETUP = B
, install it into the project in the project's language — work out the language from the cwd (
package.json
/
tsconfig.json
→ TypeScript;
pyproject.toml
/
requirements.txt
/
*.py
→ Python; ask only if you can't tell):
bash
undefined
Do:
SETUP = A
,确保SDK已安装在您将运行脚本的环境中(默认Python)。若
SETUP = B
,将SDK安装到项目中,根据当前目录判断语言(
package.json
/
tsconfig.json
→TypeScript;
pyproject.toml
/
requirements.txt
/
*.py
→Python;无法判断时再询问):
bash
undefined

Python (needs 3.10+ for the x402 extra)

Python(x402扩展需要3.10+版本)

pip install "browser-use-sdk[x402]"
pip install "browser-use-sdk[x402]"

TypeScript

TypeScript

npm install browser-use-sdk @x402/fetch @x402/evm viem

**Ask:** (header: `Test run`) — question: `Ready to test? This spends exactly $1 USDC from your wallet to check payment + run work end to end.`
- **Use the default task** — "Go to example.com and tell me the heading text." (~5 seconds, cheap)
- **I'll give you a task** — Tell me a short task to run instead.
- **Skip the test** — Skip the test and go straight to using x402.

**Do:**
- "I'll give you a task" → **Say:** `What's the task? Keep it short.` Wait for it.
- "Skip the test" → go to Step 6.
- Otherwise use the default task.

**Do:** Run the test. Use the raw x402 client with `max_value` of $1.50 so it pays $1, not the $5 the SDK uses by default:
```python
import asyncio, os
from decimal import Decimal
from x402 import x402Client
from x402.http.clients import x402HttpxClient
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.exact.register import register_exact_evm_client
from eth_account import Account

async def main():
    client = x402Client()
    register_exact_evm_client(
        client,
        EthAccountSigner(Account.from_key(os.environ["BROWSER_USE_X402_PRIVATE_KEY"])),
    )
    # max_value caps the spend per request — picks the $1 option over the $5 default.
    async with x402HttpxClient(client, max_value=Decimal("1.5"), timeout=180.0) as http:
        resp = await http.post(
            "https://x402.api.browser-use.com/api/v3/sessions",
            json={"task": "<the task>"},
        )
        print(resp.status_code, resp.json())

asyncio.run(main())
If
MODE = B
, add the API key header, or the $1 goes to a new wallet project instead of the one being topped up:
python
async with x402HttpxClient(
    client, max_value=Decimal("1.5"), timeout=180.0,
    headers={"X-Browser-Use-API-Key": os.environ["BROWSER_USE_API_KEY"]},
) as http:
    ...
If the installed
x402
lib has no
max_value
, Say:
That x402 version can't force a $1 charge, so the test will cost $5 instead. Want me to go ahead?
— wait for a yes before running.
Say:
Paid. On-chain proof: https://basescan.org/address/<address>#tokentxns — look for a USDC transfer out of exactly $1.000000.
Do: Read the balance. If
MODE = A
(needs
browser-use-sdk
≥ 3.8.0; if older, say to run
pip install -U "browser-use-sdk[x402]"
or skip this):
python
import asyncio, os
from browser_use_sdk.v3 import get_wallet_balance

async def main():
    bal = await get_wallet_balance(os.environ["BROWSER_USE_X402_PRIVATE_KEY"])
    print(bal['total_credits_usd'])

asyncio.run(main())
If
MODE = B
, skip
get_wallet_balance
(it returns 404 — the credits sit in the API key's project, that's normal, don't show it as an error) and read it the normal way:
python
from browser_use_sdk.v3 import AsyncBrowserUse
client = AsyncBrowserUse(api_key=os.environ["BROWSER_USE_API_KEY"])
acct = await client.billing.account()
print(acct.total_credits_balance_usd)
Say:
Done. Your Browser Use balance is now $<balance> (the test cost about $<cost>). Tasks draw from this, and the SDK adds another $5 when it runs out.

npm install browser-use-sdk @x402/fetch @x402/evm viem

**Ask:**(标题:`测试运行`)——问题:`准备好测试了吗?本次测试将从您的钱包中扣除1美元USDC,以端到端验证支付和任务运行流程。`
- **使用默认任务**——“访问example.com并告知我标题文本。”(约5秒,费用低廉)
- **我自定义任务**——告诉我一个简短的任务来运行。
- **跳过测试**——跳过测试直接使用x402。

**Do:**
- 选择“我自定义任务”→**Say:** `任务是什么?请简短描述。`等待用户回复。
- 选择“跳过测试”→进入步骤6。
- 否则使用默认任务。

**Do:** 运行测试。使用原始x402客户端,设置`max_value`为1.50美元,这样会支付1美元而非SDK默认的5美元:
```python
import asyncio, os
from decimal import Decimal
from x402 import x402Client
from x402.http.clients import x402HttpxClient
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.exact.register import register_exact_evm_client
from eth_account import Account

async def main():
    client = x402Client()
    register_exact_evm_client(
        client,
        EthAccountSigner(Account.from_key(os.environ["BROWSER_USE_X402_PRIVATE_KEY"])),
    )
    # max_value限制每次请求的花费——选择1美元选项而非默认的5美元。
    async with x402HttpxClient(client, max_value=Decimal("1.5"), timeout=180.0) as http:
        resp = await http.post(
            "https://x402.api.browser-use.com/api/v3/sessions",
            json={"task": "<任务内容>"},
        )
        print(resp.status_code, resp.json())

asyncio.run(main())
MODE = B
,添加API密钥头,否则1美元会存入新钱包项目而非您要充值的账户:
python
async with x402HttpxClient(
    client, max_value=Decimal("1.5"), timeout=180.0,
    headers={"X-Browser-Use-API-Key": os.environ["BROWSER_USE_API_KEY"]},
) as http:
    ...
若安装的
x402
库没有
max_value
参数,Say:
该x402版本无法强制收取1美元费用,因此测试将花费5美元。是否继续?
——收到用户确认后再运行。
Say:
支付完成。链上凭证:https://basescan.org/address/<address>#tokentxns——查找转出金额恰好为1.000000美元的USDC转账记录。
Do: 读取余额。若
MODE = A
(需要
browser-use-sdk
≥3.8.0;版本较低时,告知用户运行
pip install -U "browser-use-sdk[x402]"
或跳过此步骤):
python
import asyncio, os
from browser_use_sdk.v3 import get_wallet_balance

async def main():
    bal = await get_wallet_balance(os.environ["BROWSER_USE_X402_PRIVATE_KEY"])
    print(bal['total_credits_usd'])

asyncio.run(main())
MODE = B
,跳过
get_wallet_balance
(会返回404——额度存入API密钥对应的账户,这是正常现象,不要显示为错误),按常规方式读取:
python
from browser_use_sdk.v3 import AsyncBrowserUse
client = AsyncBrowserUse(api_key=os.environ["BROWSER_USE_API_KEY"])
acct = await client.billing.account()
print(acct.total_credits_balance_usd)
Say:
测试完成。您的Browser Use余额现为$<balance>(本次测试花费约$<cost>)。任务将从该余额中扣除,余额不足时SDK会自动添加5美元额度。

Step 6 — Wrap up

步骤6 — 收尾

If
SETUP = A
:
Say:
All set. Ask me to run any browser task and I'll run it through the SDK, paid from your wallet.
Do: When they ask for a task, write a throwaway script (in
/tmp
, or a background job for long ones), run it, report the result, and delete it — don't leave files in their cwd. The SDK reads
BROWSER_USE_X402_PRIVATE_KEY
and finds the x402 endpoint on its own:
python
import asyncio, os
from browser_use_sdk.v3 import AsyncBrowserUse

async def main():
    client = AsyncBrowserUse()  # Mode B: AsyncBrowserUse(api_key=os.environ["BROWSER_USE_API_KEY"])
    result = await client.run(task="<the task>")
    print(result.output)

asyncio.run(main())
If
SETUP = B
:
Say:
All set. Here's the client to use in your code — it reads the key and endpoint from your
.env
:
Do: Add the client in the project's language and point them at the
cloud
skill / SDK docs for the rest:
python
from browser_use_sdk.v3 import AsyncBrowserUse

client = AsyncBrowserUse()                                  # Mode A (accountless)
SETUP = A
Say:
设置完成。您可以让我运行任何浏览器任务,我会通过SDK执行,费用从您的钱包扣除。
Do: 用户请求任务时,编写一次性脚本(保存到
/tmp
或后台运行长时间任务),运行后报告结果并删除脚本——不要在用户的当前目录留下文件。SDK会读取
BROWSER_USE_X402_PRIVATE_KEY
并自动查找x402端点:
python
import asyncio, os
from browser_use_sdk.v3 import AsyncBrowserUse

async def main():
    client = AsyncBrowserUse()  # Mode B: AsyncBrowserUse(api_key=os.environ["BROWSER_USE_API_KEY"])
    result = await client.run(task="<任务内容>")
    print(result.output)

asyncio.run(main())
SETUP = B
Say:
设置完成。以下是您代码中可使用的客户端——它会从
.env
中读取密钥和端点:
Do: 添加对应语言的客户端代码,并引导用户查看
cloud
技能/SDK文档获取更多信息:
python
from browser_use_sdk.v3 import AsyncBrowserUse

client = AsyncBrowserUse()                                  # Mode A(无账户)

client = AsyncBrowserUse(api_key="bu_...") # Mode B (top up existing account)

client = AsyncBrowserUse(api_key="bu_...") # Mode B(为现有账户充值)


(x402 needs the **async** client — the sync `BrowserUse` won't run when the x402 env var is set.)

---

(x402需要**异步**客户端——当设置了x402环境变量时,同步`BrowserUse`无法运行。)

---

TypeScript equivalents

TypeScript等效代码

PythonTypeScript
from browser_use_sdk.v3 import AsyncBrowserUse
import { BrowserUse } from "browser-use-sdk/v3"
AsyncBrowserUse()
new BrowserUse()
await client.run(task=...)
.output
await client.run({ task })
.output
get_wallet_balance(key)
getWalletBalance(key)
(
from "browser-use-sdk/v3"
)
pip install "browser-use-sdk[x402]"
npm install browser-use-sdk @x402/fetch @x402/evm viem
Both SDKs read
BROWSER_USE_X402_PRIVATE_KEY
from the env.
PythonTypeScript
from browser_use_sdk.v3 import AsyncBrowserUse
import { BrowserUse } from "browser-use-sdk/v3"
AsyncBrowserUse()
new BrowserUse()
await client.run(task=...)
.output
await client.run({ task })
.output
get_wallet_balance(key)
getWalletBalance(key)
(来自
"browser-use-sdk/v3"
pip install "browser-use-sdk[x402]"
npm install browser-use-sdk @x402/fetch @x402/evm viem
两个SDK都会从环境变量中读取
BROWSER_USE_X402_PRIVATE_KEY

Rules

规则

  • Follow the script in order. Say the Say blocks word for word.
  • Never spend the user's USDC without a clear yes (the Step 5 question is that yes).
  • Always offer both ways to add the key: paste it in chat (you write it to
    .env
    ) or the user adds it themselves. If they paste it, write it straight to
    .env
    and never echo it back or store it anywhere else.
  • Add
    .env
    to
    .gitignore
    before saving keys.
  • Wallets hold real money. Keep keys out of source control, logs, and screenshots; only add what you can afford to lose if it leaks.
  • 严格按顺序执行脚本,Say块内容需一字不差地读出。
  • 未经用户明确同意,绝不能扣除用户的USDC(步骤5的提问即为确认环节)。
  • 始终提供两种添加密钥的方式:在聊天中粘贴(您写入
    .env
    )或用户自行添加。若用户粘贴密钥,直接写入
    .env
    ,绝不能回显或存储到其他地方。
  • 保存密钥前,务必将
    .env
    添加到
    .gitignore
  • **钱包内包含真实货币。**确保密钥不进入版本控制、日志或截图;仅存入您可承受损失的金额。

Reference

参考链接