OpenGradient Python SDK
The OpenGradient Python SDK allows programmatic access to our model repository and decentralized AI infrastructure. Model developers can use the SDK to publish and manage their model deployments on OpenGradient and integrate it directly into their development workflow. On the other hand, our Inference SDK offers traditional application developers and AI users the ability to build directly on top of our end-to-end verified and decentralized AI network, providing a superior alternative to centralized AI providers such as HuggingFace and OpenAI.
In addition to the OpenGradient Python library that applications can build on top of, the SDK also includes a CLI tool called opengradient
for easier access.
Getting Started
To install the OpenGradient Python SDK and CLI, run the following command:
pip install opengradient
Accounts and Credentials
To use the SDK to upload or download models and run inferences, you need to create 2 accounts:
- Model Hub account: you can create this using your email and password on the Hub Sign Up page if you haven't already.
- OpenGradient account: this is a blockchain account that will be used to send verifiable inference transactions to our network. You can use any existing Ethereum-compatible wallet with an account (e.g. MetaMask) or create a new one using our SDK (see below).
We provide an account creation wizard in our SDK that guides you through this process. You can access it by running:
opengradient create-account
NOTE
The wizard will also take you to our Test Faucet where you can fund your OpenGradient account with credits.
CLI Configuration
In order to use the OpenGradient CLI, you need to provide your credentials through a config file. You can simply run opengradient config init
to create the configuration file and provide the required fields.
TIP
You can use opengradient config show
to see your current configurations If you want to try out our SDK and don't want to set up your account, you can use one of the pre-configured accounts from here Demo Accounts. -->
Authentication
To provide your private key to the SDK, expose it as OPENGRADIENT_PRIVATE_KEY
environment variable or pass it explicitly to the library (using the og.init
method).
Library Use
To use OpenGradient library, run:
import opengradient as og
og.init(email="<email>", password="<password>")
CLI Use
Set the following environment variables as needed or use the current CLI defaults:
# Required arguments for OpenGradient client
export OPENGRADIENT_PRIVATE_KEY="<my_private_key>"
export OPENGRADIENT_EMAIL="<email>"
export OPENGRADIENT_PASSWORD="<password>"
Check that the OpenGradient client reflects your settings (private key, email, etc.)
opengradient client-settings
To ensure everything is correctly set up, run the following inference:
opengradient infer -m QmbUqS93oc4JTLMHwpVxsE39mhNxy6hpf6Py3r9oANr8aZ --input '{"num_input1":[1.0, 2.0, 3.0], "num_input2":10, "str_input1":["hello", "ONNX"], "str_input2":" world"}''
Library Configuration
To initialize and use OpenGradient library, you need to call og.init
with the private key of your blockchain account and the email and password of your Model Hub account.
import opengradient as og
og.init(
private_key="<private_key>",
email="<email>",
password="<password>")
TIP
You can use opengradient config show
to get these values from your config file
More Information
To see all commands and parameters we support in the CLI, you can run:
opengradient --help