0G Compute Network
Interface with the 0G Compute Network — a decentralized AI inference marketplace with TEE-verified model integrity.
Prerequisites
- -
0g-compute-cli installed: INLINECODE1
- Note: npm package name is
@0glabs/0g-serving-broker (the old
@0glabs/0g-compute-cli package name no longer resolves), but the binary command is still
0g-compute-cli.
- - Wallet funded with 0G tokens
- Logged in: avoid passing key on the command line when possible (it can be visible in shell history/process list). Prefer reading from a protected prompt/env:
-
read -s OG_PK; 0g-compute-cli login --private-key "$OG_PK"; unset OG_PK
- - Network configured: INLINECODE6
Core Workflows
1. Discover Models
CODEBLOCK0
Filter output by model name, price, health status, and TeeML support (models running in Trusted Execution Environment).
2. Verify Provider Integrity
Always verify before trusting a new provider. TEE verification ensures the model runs in a secure enclave with hardware-attested integrity.
CODEBLOCK1
The verify command checks:
- - TEE signer address matches contract
- Docker Compose hash integrity
- DStack TEE (Intel TDX) attestation
3. Wallet & Balance
CODEBLOCK2
Important: Inference calls fail if sub-account balance is depleted. Monitor balances regularly.
4. Configure OpenClaw Provider
Get API key from a verified provider (interactive — prompts for expiration):
CODEBLOCK3
Add to openclaw.json:
CODEBLOCK4
Register in agents.defaults.models with an alias. Set cost: 0 since billing is on-chain.
See references/openclaw-config.md for complete setup guide.
5. Price Comparison (0G vs OpenRouter)
Compare 0G pricing against OpenRouter for the same models:
CODEBLOCK5
No API keys needed — uses public endpoints:
- - CoinGecko for 0G token → USD price
- OpenRouter
/api/v1/models for model pricing - 0G CLI for provider pricing
Shows side-by-side USD/1M tokens with savings percentage. Set OG_TOKEN_PRICE_USD env var to override CoinGecko price.
6. Status Check
CODEBLOCK6
Safety Guidelines
- - Always run
inference verify on new providers before use - Check provider health/uptime before relying on them
- Monitor sub-account balances — depleted funds cause inference failures
- Private key stored in
~/.0g-compute-cli/config.json — never expose this file
Reference Documentation
0G 计算网络
与 0G 计算网络交互——一个具有 TEE 验证模型完整性的去中心化 AI 推理市场。
前置条件
- - 已安装 0g-compute-cli:npm i -g @0glabs/0g-serving-broker
- 注意:npm 包名为 @0glabs/0g-serving-broker(旧的 @0glabs/0g-compute-cli 包名已不再解析),但二进制命令仍为 0g-compute-cli。
- - 钱包已充值 0G 代币
- 已登录:尽可能避免在命令行中传递密钥(它可能在 shell 历史/进程列表中可见)。建议从受保护的提示/环境变量中读取:
- read -s OG
PK; 0g-compute-cli login --private-key $OGPK; unset OG_PK
- - 网络已配置:0g-compute-cli setup-network
核心工作流
1. 发现模型
bash
列出所有提供商及其模型、价格、可验证性
0g-compute-cli inference list-providers
详细视图,包含健康/运行时间指标
0g-compute-cli inference list-providers-detail
包含没有有效 TEE 签名者的提供商
0g-compute-cli inference list-providers --include-invalid
按模型名称、价格、健康状态和 TeeML 支持(在可信执行环境中运行的模型)过滤输出。
2. 验证提供商完整性
在信任新提供商之前务必进行验证。 TEE 验证确保模型在具有硬件证明完整性的安全飞地中运行。
bash
完整的 TEE 认证检查
0g-compute-cli inference verify --provider <地址>
下载原始认证数据
0g-compute-cli inference download-report --provider <地址> --output report.json
verify 命令检查:
- - TEE 签名者地址与合约匹配
- Docker Compose 哈希完整性
- DStack TEE(Intel TDX)认证
3. 钱包与余额
bash
账户概览
0g-compute-cli get-account
每个提供商的子账户余额
0g-compute-cli get-sub-account --provider <地址> --service inference
资金操作
0g-compute-cli deposit --amount <0G> # 存入主账户
0g-compute-cli transfer-fund --provider <地址> --amount <0G> --service inference # 转入子账户
0g-compute-cli retrieve-fund --service inference # 从子账户提取
0g-compute-cli refund --amount <0G> # 提现到钱包
重要提示:如果子账户余额耗尽,推理调用将失败。请定期监控余额。
4. 配置 OpenClaw 提供商
从已验证的提供商获取 API 密钥(交互式——提示输入过期时间):
bash
0g-compute-cli inference get-secret --provider <地址>
添加到 openclaw.json:
json
providers: {
0g-<模型名称>: {
baseUrl: <提供商URL>/v1/proxy,
apiKey: <密钥>,
api: openai-completions,
models: [{ id: <模型ID>, name: <显示名称> }]
}
}
使用别名在 agents.defaults.models 中注册。设置 cost: 0,因为计费在链上进行。
完整设置指南请参见 references/openclaw-config.md。
5. 价格比较(0G vs OpenRouter)
比较相同模型的 0G 定价与 OpenRouter 定价:
bash
scripts/0g-price-compare.sh
无需 API 密钥——使用公共端点:
- - CoinGecko 用于 0G 代币 → USD 价格
- OpenRouter /api/v1/models 用于模型定价
- 0G CLI 用于提供商定价
显示并排的 USD/百万代币价格及节省百分比。设置 OGTOKENPRICE_USD 环境变量以覆盖 CoinGecko 价格。
6. 状态检查
bash
登录状态与钱包
0g-compute-cli status
当前网络(主网/测试网)
0g-compute-cli show-network
安全指南
- - 使用新提供商前务必运行 inference verify
- 在依赖提供商前检查其健康/运行时间
- 监控子账户余额——资金耗尽会导致推理失败
- 私钥存储在 ~/.0g-compute-cli/config.json 中——切勿暴露此文件
参考文档