Prerequisites
- Python 3.8 or higher
- A wallet with 0G tokens (testnet or mainnet)
- An EVM-compatible private key for signing transactions
Earlier versions required Node.js for cryptographic operations. As of v0.2.0 the SDK is pure Python — Node.js is not required.
Install the SDK
Install the published package from PyPI:Verify the install
Configure environment variables
Create a.env file in your project root with your private key and an RPC URL:
- Testnet
- Mainnet
NETWORK is optional when RPC_URL is set.
Get testnet tokens
You need 0G tokens to fund inference requests. For testnet:Visit the faucet
Open faucet.0g.ai and request tokens for your address.
Confirm receipt
Check your balance on the Galileo block explorer.
Create your first broker
The broker is your main entry point to the SDK. It wires up the ledger, inference, and fine-tuning managers from a single factory call.Load credentials from .env
If you created a .env file above, use create_broker_from_env:
python-dotenv. Install it with pip install python-dotenv if you haven’t already.
Network configuration
| Network | Chain ID | RPC URL |
|---|---|---|
| Mainnet | 16661 | https://evmrpc.0g.ai |
| Testnet (Galileo) | 16602 | https://evmrpc-testnet.0g.ai |
create_broker(..., ledger_address=..., inference_address=...) if you’re working against a custom deployment.
Troubleshooting
Failed to connect to RPC endpoint
Failed to connect to RPC endpoint
Check that the RPC URL is reachable (
curl https://evmrpc-testnet.0g.ai) and that your machine has internet access. The SDK raises ConfigurationError on connection failure.ModuleNotFoundError: No module named 'zerog_py_sdk'
ModuleNotFoundError: No module named 'zerog_py_sdk'
The package installs as
0g-inference-sdk on PyPI but is imported as zerog_py_sdk. Make sure you activated the correct virtual environment.PRIVATE_KEY not found in environment
PRIVATE_KEY not found in environment
Either pass the key explicitly to
create_broker(private_key=...) or ensure your .env file is in the working directory and python-dotenv is installed.Next steps
Run your first inference
Discover providers, fund your account, and send a chat completion request.
Account management
Deposit, transfer, and refund funds on the Ledger contract.