0g-compute
0G Compute Network guide for decentralized AI inference, fine-tuning, and GPU services. Covers chatbots, image generation, speech-to-text, SDK integration (0g-serving-broker), processResponse API, broker.inference methods, CLI commands (0g-compute-cli), and account management. Use this skill for any 0G compute, 0G AI, or decentralized GPU question.
git clone --depth 1 https://github.com/internet-court/internet-court-skill /tmp/0g-compute && cp -r /tmp/0g-compute/vendored/0g/0g-compute ~/.claude/skills/0g-computeSKILL.md
# 0G Compute Network
This skill provides instructions for building with the 0G Compute Network — a decentralized GPU marketplace for AI inference and model fine-tuning. Follow these patterns exactly when generating code.
## Code Generation Rules
1. Copy code patterns from this skill verbatim. Do NOT generate from training data.
2. Call `processResponse()` after every API response (see processResponse section below).
3. Use environment variables for private keys. Never hardcode secrets.
4. Route users to testnet for initial development.
When unsure about a pattern, reference the detailed guides:
- Inference patterns: [references/inference.md](references/inference.md)
- Fine-tuning workflow: [references/fine-tuning.md](references/fine-tuning.md)
- Account management: [references/account-management.md](references/account-management.md)
- Production examples: [references/examples/](references/examples/README.md)
## Network Information
| Network | RPC URL | Inference | Fine-tuning |
|---------|---------|-----------|-------------|
| Mainnet | `https://evmrpc.0g.ai` | Yes | Yes |
| Testnet | `https://evmrpc-testnet.0g.ai` | Yes | Yes |
Model availability changes frequently. Always use `broker.inference.listService()` or `0g-compute-cli inference list-providers` to check current models. On-chain model names use `org/model-name` format.
## Prerequisites
```bash
node --version # Must be >= 22.0.0
pnpm add @0glabs/0g-serving-broker # SDK for applications
pnpm add @0glabs/0g-serving-broker -g # CLI for direct usage
```
## Quick Setup
```bash
0g-compute-cli setup-network # Choose testnet or mainnet
0g-compute-cli login # Login with wallet private key
0g-compute-cli deposit --amount 10 # Deposit funds
0g-compute-cli get-account # Check balance
```
## Inference (SDK)
```typescript
import { ethers } from "ethers";
import { createZGComputeNetworkBroker } from "@0glabs/0g-serving-broker";
const RPC_URL = process.env.NODE_ENV === 'production'
? "https://evmrpc.0g.ai"
: "https://evmrpc-testnet.0g.ai";
const provider = new ethers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
const broker = await createZGComputeNetworkBroker(wallet);
// Discover services
const services = await broker.inference.listService();
services.forEach(s => {
console.log(`${s.provider} | ${s.model} | ${s.serviceType}`);
});
// Make inference request
const { endpoint, model } = await broker.inference.getServiceMetadata(providerAddress);
const headers = await broker.inference.getRequestHeaders(providerAddress);
const response = await fetch(`${endpoint}/chat/completions`, {
method: "POST",
headers: { "Content-Type": "application/json", ...headers },
body: JSON.stringify({ messages, model })
});
const data = await response.json();
// Extract chatID (see chatID table below)
let chatID = response.headers.get("ZG-Res-Key") || response.headers.get("zg-res-key");
if (!chatID) chatID = data.id;
// CRITICAL: Always call processResponse
await broker.inference.processResponse(
providerAddress, // 1st: provider address
chatID, // 2nd: response identifier for verification
JSON.stringify(data.usage) // 3rd: usage data for fee calculation
);
```
For streaming, browser SDK, cURL, and Python examples, see [references/inference.md](references/inference.md).
## processResponse (CRITICAL)
Call `broker.inference.processResponse()` after EVERY API response for fee settlement and TEE verification.
```typescript
await broker.inference.processResponse(
providerAddress, // 1st: provider address
chatID, // 2nd: response identifier for verification
JSON.stringify(data.usage) // 3rd: usage data for fee calculation
);
```
Parameter order: **provider, chatID, usageData**. Do NOT reorder.
### chatID Retrieval by Service Type
Always try `ZG-Res-Key` response header first. Use fallback only when header is absent.
| Service Type | chatID Source | Fallback |
|---|---|---|
| Chatbot | `ZG-Res-Key` header | `data.id` from response body |
| Text-to-Image | `ZG-Res-Key` header | none |
| Speech-to-Text | `ZG-Res-Key` header | none |
| Chatbot Streaming | `ZG-Res-Key` header | `id` from stream chunk |
| Audio Streaming | `ZG-Res-Key` header | none |
## Fine-tuning
Fine-tuning is available on both **mainnet** and **testnet**. It is a 6-step CLI process: list providers, upload dataset, calculate tokens, create task, monitor, download and decrypt.
For the complete workflow, see [references/fine-tuning.md](references/fine-tuning.md).
## Account Management
The 0G Compute Network uses Main Accounts (deposits/withdrawals) and Provider Sub-Accounts (service payments). Sub-account refunds have a 24-hour lock period.
```bash
0g-compute-cli get-account # Check balance
0g-compute-cli deposit --amount 10 # Deposit to main
0g-compute-cli transfer-fund --provider <ADDR> --amount 5 # Transfer to sub-account
0g-compute-cli retrieve-fund # Retrieve from sub (24h lock)
0g-compute-cli refund --amount 5 # Withdraw to wallet
```
For detailed account management, see [references/account-management.md](references/account-management.md).
## CLI Quick Reference
```bash
# Inference
0g-compute-cli inference list-providers # List all providers
0g-compute-cli inference verify --provider <ADDR> # Verify TEE attestation
0g-compute-cli inference acknowledge-provider --provider <ADDR> # Required before first use
0g-compute-cli inference get-secret --provider <ADDR> # Get API key for direct calls
0g-compute-cli inference serve --provider <ADDR> --port 3000 # Local OpenAI-compatible proxy
# Fine-tuning
0g-compute-cli fine-tuning list-providers # List fine-tuningEntry point for Internet Court — the trust layer for agent-to-agent commerce. Use whenever an agent needs to transact with another agent or a paid service, or a user mentions agent payments, paid APIs (HTTP 402/x402), wallet custody or trust concerns, spending mandates, delegated permissions (ERC-7710/7715), escrow, agent identity or reputation (ERC-8004), negotiation between agents (A2A), agent jobs (ERC-8183), machine payments (MPP, AP2), supervision of agent behavior, revocation, verification, or dispute resolution (GenLayer) — even if they never say "Internet Court". Routes to the vendored protocol skills and connector skills in this package.
Connect GenLayer Intelligent Contract decisions to ERC-7710-style delegated authority. Use when an agent needs to design the interface, message schema, relayer/bridge path, EVM revocation controller, constraint updates, proof/finality assumptions, and failure handling that turn a GenLayer agent-performance review into ERC-7710 revocation or policy changes.
Internet Court adapter for GenLayer Intelligent Contract supervision. Use to specify agent-performance rubrics, evidence schemas, decision outputs, and ERC-7710 connector expectations, while delegating actual GenLayer contract writing, linting, testing, deployment, and CLI interaction to the official GenLayer skills at https://skills.genlayer.com/.
Design and implement demos combining x402 HTTP payments with ERC-7710 smart contract delegations and ERC-7715 wallet permission requests for subscriptions, bounded agent budgets, recurring spend, pay-per-use APIs, and agentic commerce.
Use this skill when the user asks to list, create, inspect, update, disable, re-enable, or revoke AltLLM Portal API keys for external agents or applications. Do NOT use for wallet login, billing history, or payment links.
Use this skill when the user asks to log in or out with a wallet session, fetch a wallet sign-in challenge, verify an externally signed challenge, or troubleshoot AltLLM Portal wallet login for the local altllm CLI. Do NOT use for API key management, billing history, or payment links.
Use this skill when the user asks to inspect AltLLM Portal balance, redeem a promo code, review billing transactions, or view usage analytics by period, model, or API key using the local altllm CLI. Do NOT use for API key lifecycle management or payment-link execution.
Use this umbrella skill when the request spans multiple AltLLM Portal CLI domains, or when you need to navigate the local altllm CLI in this repository across auth, API keys, billing history, NOWPayments payment links, and related x402 Portal top-up guidance.