From 3670e05d842e196e9b67932a02df078d77eda2ca Mon Sep 17 00:00:00 2001 From: "balogh.adam@icloud.com" Date: Mon, 9 Feb 2026 16:11:14 +0100 Subject: [PATCH 1/4] sepolia --- README.md | 10 ++++++++++ examples/run_x402_llm.py | 2 ++ src/opengradient/__init__.py | 2 ++ src/opengradient/cli.py | 4 +--- src/opengradient/client/client.py | 5 ++++- src/opengradient/client/llm.py | 15 +++++++++++---- src/opengradient/defaults.py | 1 + src/opengradient/types.py | 21 +++++++++++++++++++++ 8 files changed, 52 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 874bbe4..fc68e2c 100644 --- a/README.md +++ b/README.md @@ -269,6 +269,16 @@ result = client.llm.chat( ) ``` +### Payment Network Selection + +By default, payments settle on the OG EVM network. To pay via Base Sepolia instead, set the `payment_network` parameter at client initialization: +```python +client = og.Client( + private_key=os.environ.get("OG_PRIVATE_KEY"), + payment_network=og.PaymentNetwork.BASE_SEPOLIA, +) +``` + ## Examples Additional code examples are available in the [examples](./examples) directory. diff --git a/examples/run_x402_llm.py b/examples/run_x402_llm.py index 8926de2..3db49ff 100644 --- a/examples/run_x402_llm.py +++ b/examples/run_x402_llm.py @@ -15,6 +15,8 @@ client = og.Client( private_key=os.environ.get("OG_PRIVATE_KEY"), + # To pay via Base Sepolia instead of OG EVM: + # payment_network=og.PaymentNetwork.BASE_SEPOLIA, ) messages = [ diff --git a/src/opengradient/__init__.py b/src/opengradient/__init__.py index 375581b..2085021 100644 --- a/src/opengradient/__init__.py +++ b/src/opengradient/__init__.py @@ -86,6 +86,7 @@ InferenceResult, ModelOutput, ModelRepository, + PaymentNetwork, SchedulerParams, TextGenerationOutput, TextGenerationStream, @@ -132,6 +133,7 @@ def init( "init", "TEE_LLM", "InferenceMode", + "PaymentNetwork", "HistoricalInputQuery", "SchedulerParams", "CandleType", diff --git a/src/opengradient/cli.py b/src/opengradient/cli.py index 54225a7..72ffec5 100644 --- a/src/opengradient/cli.py +++ b/src/opengradient/cli.py @@ -324,9 +324,7 @@ def infer(ctx, model_cid: str, inference_mode: str, input_data, input_file: Path model_input = json.load(file) click.echo(f'Running {inference_mode} inference for model "{model_cid}"') - inference_result = client.alpha.infer( - model_cid=model_cid, inference_mode=InferenceModes[inference_mode], model_input=model_input - ) + inference_result = client.alpha.infer(model_cid=model_cid, inference_mode=InferenceModes[inference_mode], model_input=model_input) click.echo() # Add a newline for better spacing click.secho("✅ Transaction successful", fg="green", bold=True) diff --git a/src/opengradient/client/client.py b/src/opengradient/client/client.py index 31086f6..1125ee4 100644 --- a/src/opengradient/client/client.py +++ b/src/opengradient/client/client.py @@ -11,6 +11,7 @@ DEFAULT_OPENGRADIENT_LLM_STREAMING_SERVER_URL, DEFAULT_RPC_URL, ) +from ..types import PaymentNetwork from .alpha import Alpha from .llm import LLM from .model_hub import ModelHub @@ -50,6 +51,7 @@ def __init__( contract_address: str = DEFAULT_INFERENCE_CONTRACT_ADDRESS, og_llm_server_url: Optional[str] = DEFAULT_OPENGRADIENT_LLM_SERVER_URL, og_llm_streaming_server_url: Optional[str] = DEFAULT_OPENGRADIENT_LLM_STREAMING_SERVER_URL, + payment_network: PaymentNetwork = PaymentNetwork.OG_EVM, ): """ Initialize the OpenGradient client. @@ -63,6 +65,7 @@ def __init__( contract_address: Inference contract address. og_llm_server_url: OpenGradient LLM server URL. og_llm_streaming_server_url: OpenGradient LLM streaming server URL. + payment_network: Payment network for x402 transactions. Defaults to OG_EVM. """ blockchain = Web3(Web3.HTTPProvider(rpc_url)) wallet_account = blockchain.eth.account.from_key(private_key) @@ -78,6 +81,7 @@ def __init__( wallet_account=wallet_account, og_llm_server_url=og_llm_server_url, og_llm_streaming_server_url=og_llm_streaming_server_url, + network_filter=payment_network.value, ) self.alpha = Alpha( @@ -86,4 +90,3 @@ def __init__( inference_hub_contract_address=contract_address, api_url=api_url, ) - diff --git a/src/opengradient/client/llm.py b/src/opengradient/client/llm.py index 2d13224..d39b627 100644 --- a/src/opengradient/client/llm.py +++ b/src/opengradient/client/llm.py @@ -53,16 +53,23 @@ class LLM: result = client.llm.completion(model=TEE_LLM.CLAUDE_3_5_HAIKU, prompt="Hello") """ - def __init__(self, wallet_account: LocalAccount, og_llm_server_url: str, og_llm_streaming_server_url: str): + def __init__( + self, + wallet_account: LocalAccount, + og_llm_server_url: str, + og_llm_streaming_server_url: str, + network_filter: str = DEFAULT_NETWORK_FILTER, + ): self._wallet_account = wallet_account self._og_llm_server_url = og_llm_server_url self._og_llm_streaming_server_url = og_llm_streaming_server_url + self._network_filter = network_filter - def _og_payment_selector(self, accepts, network_filter=DEFAULT_NETWORK_FILTER, scheme_filter=None, max_value=None): + def _og_payment_selector(self, accepts, network_filter=None, scheme_filter=None, max_value=None): """Custom payment selector for OpenGradient network.""" return x402Client.default_payment_requirements_selector( accepts, - network_filter=network_filter, + network_filter=network_filter or self._network_filter, scheme_filter=scheme_filter, max_value=max_value, ) @@ -418,7 +425,7 @@ async def _tee_llm_chat_stream_async( limits=LIMITS, http2=False, follow_redirects=False, - auth=X402Auth(account=self._wallet_account, network_filter=DEFAULT_NETWORK_FILTER), # type: ignore + auth=X402Auth(account=self._wallet_account, network_filter=self._network_filter), # type: ignore verify=True, ) as client: headers = { diff --git a/src/opengradient/defaults.py b/src/opengradient/defaults.py index cd796da..581fa2e 100644 --- a/src/opengradient/defaults.py +++ b/src/opengradient/defaults.py @@ -9,3 +9,4 @@ DEFAULT_OPENGRADIENT_LLM_SERVER_URL = "https://llmogevm.opengradient.ai" DEFAULT_OPENGRADIENT_LLM_STREAMING_SERVER_URL = "https://llmogevm.opengradient.ai" DEFAULT_NETWORK_FILTER = "og-evm" +DEFAULT_BASE_SEPOLIA_NETWORK_FILTER = "base-sepolia" diff --git a/src/opengradient/types.py b/src/opengradient/types.py index fa89c98..0aa6ee9 100644 --- a/src/opengradient/types.py +++ b/src/opengradient/types.py @@ -10,6 +10,27 @@ import numpy as np +class PaymentNetwork(str, Enum): + """ + Payment network for x402 payment protocol transactions. + + Controls which blockchain network is used for paying for LLM inference. + + Attributes: + OG_EVM: Pay on the OpenGradient EVM network (default). + BASE_SEPOLIA: Pay on the Base Sepolia testnet using the OG token. + + Examples: + >>> client = og.Client( + ... private_key="0x...", + ... payment_network=og.PaymentNetwork.BASE_SEPOLIA, + ... ) + """ + + OG_EVM = "og-evm" + BASE_SEPOLIA = "base-sepolia" + + class x402SettlementMode(str, Enum): """ Settlement modes for x402 payment protocol transactions. From 640b7d546813f4c81824227ab8f15f6d7e61db32 Mon Sep 17 00:00:00 2001 From: "balogh.adam@icloud.com" Date: Mon, 9 Feb 2026 17:25:44 +0100 Subject: [PATCH 2/4] note --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc68e2c..de67bf5 100644 --- a/README.md +++ b/README.md @@ -271,7 +271,7 @@ result = client.llm.chat( ### Payment Network Selection -By default, payments settle on the OG EVM network. To pay via Base Sepolia instead, set the `payment_network` parameter at client initialization: +By default, payments settle on the OG EVM network. To pay via Base Sepolia instead, set the `payment_network` parameter at client initialization. The Base Sepolia payment network uses the OG token at address `0x240b09731D96979f50B2C649C9CE10FcF9C7987F`. ```python client = og.Client( private_key=os.environ.get("OG_PRIVATE_KEY"), From 6a5e4fbac607c0e2c02baf30031c700ffd485226 Mon Sep 17 00:00:00 2001 From: "balogh.adam@icloud.com" Date: Mon, 9 Feb 2026 17:25:57 +0100 Subject: [PATCH 3/4] docs --- docs/opengradient/client/client.md | 3 ++- docs/opengradient/client/index.md | 3 ++- docs/opengradient/client/llm.md | 2 +- docs/opengradient/index.md | 19 ++++++++++++++++++- docs/opengradient/types.md | 16 ++++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/docs/opengradient/client/client.md b/docs/opengradient/client/client.md index 91e0ad4..cf0c492 100644 --- a/docs/opengradient/client/client.md +++ b/docs/opengradient/client/client.md @@ -21,7 +21,7 @@ blockchain private key and optional Model Hub credentials. #### Constructor ```python -def __init__(private_key: str, email: Optional[str] = None, password: Optional[str] = None, rpc_url: str = 'https://ogevmdevnet.opengradient.ai', api_url: str = 'https://sdk-devnet.opengradient.ai', contract_address: str = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str] = 'https://llmogevm.opengradient.ai', og_llm_streaming_server_url: Optional[str] = 'https://llmogevm.opengradient.ai') +def __init__(private_key: str, email: Optional[str] = None, password: Optional[str] = None, rpc_url: str = 'https://ogevmdevnet.opengradient.ai', api_url: str = 'https://sdk-devnet.opengradient.ai', contract_address: str = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str] = 'https://llmogevm.opengradient.ai', og_llm_streaming_server_url: Optional[str] = 'https://llmogevm.opengradient.ai', payment_network: `PaymentNetwork` = PaymentNetwork.OG_EVM) ``` **Arguments** @@ -34,6 +34,7 @@ def __init__(private_key: str, email: Optional[str] = None, password: Optio * **`contract_address`**: Inference contract address. * **`og_llm_server_url`**: OpenGradient LLM server URL. * **`og_llm_streaming_server_url`**: OpenGradient LLM streaming server URL. +* **`payment_network`**: Payment network for x402 transactions. Defaults to OG_EVM. #### Variables diff --git a/docs/opengradient/client/index.md b/docs/opengradient/client/index.md index e3fbf7a..e79f98b 100644 --- a/docs/opengradient/client/index.md +++ b/docs/opengradient/client/index.md @@ -66,7 +66,7 @@ blockchain private key and optional Model Hub credentials. #### Constructor ```python -def __init__(private_key: str, email: Optional[str] = None, password: Optional[str] = None, rpc_url: str = 'https://ogevmdevnet.opengradient.ai', api_url: str = 'https://sdk-devnet.opengradient.ai', contract_address: str = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str] = 'https://llmogevm.opengradient.ai', og_llm_streaming_server_url: Optional[str] = 'https://llmogevm.opengradient.ai') +def __init__(private_key: str, email: Optional[str] = None, password: Optional[str] = None, rpc_url: str = 'https://ogevmdevnet.opengradient.ai', api_url: str = 'https://sdk-devnet.opengradient.ai', contract_address: str = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str] = 'https://llmogevm.opengradient.ai', og_llm_streaming_server_url: Optional[str] = 'https://llmogevm.opengradient.ai', payment_network: `PaymentNetwork` = PaymentNetwork.OG_EVM) ``` **Arguments** @@ -79,6 +79,7 @@ def __init__(private_key: str, email: Optional[str] = None, password: Optio * **`contract_address`**: Inference contract address. * **`og_llm_server_url`**: OpenGradient LLM server URL. * **`og_llm_streaming_server_url`**: OpenGradient LLM streaming server URL. +* **`payment_network`**: Payment network for x402 transactions. Defaults to OG_EVM. #### Variables diff --git a/docs/opengradient/client/llm.md b/docs/opengradient/client/llm.md index eb40f00..dbe7361 100644 --- a/docs/opengradient/client/llm.md +++ b/docs/opengradient/client/llm.md @@ -21,7 +21,7 @@ Supports both streaming and non-streaming responses. #### Constructor ```python -def __init__(wallet_account: `LocalAccount`, og_llm_server_url: str, og_llm_streaming_server_url: str) +def __init__(wallet_account: `LocalAccount`, og_llm_server_url: str, og_llm_streaming_server_url: str, network_filter: str = 'og-evm') ``` #### Methods diff --git a/docs/opengradient/index.md b/docs/opengradient/index.md index 33641cb..6dd9dfa 100644 --- a/docs/opengradient/index.md +++ b/docs/opengradient/index.md @@ -126,7 +126,7 @@ blockchain private key and optional Model Hub credentials. #### Constructor ```python -def __init__(private_key: str, email: Optional[str] = None, password: Optional[str] = None, rpc_url: str = 'https://ogevmdevnet.opengradient.ai', api_url: str = 'https://sdk-devnet.opengradient.ai', contract_address: str = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str] = 'https://llmogevm.opengradient.ai', og_llm_streaming_server_url: Optional[str] = 'https://llmogevm.opengradient.ai') +def __init__(private_key: str, email: Optional[str] = None, password: Optional[str] = None, rpc_url: str = 'https://ogevmdevnet.opengradient.ai', api_url: str = 'https://sdk-devnet.opengradient.ai', contract_address: str = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str] = 'https://llmogevm.opengradient.ai', og_llm_streaming_server_url: Optional[str] = 'https://llmogevm.opengradient.ai', payment_network: `PaymentNetwork` = PaymentNetwork.OG_EVM) ``` **Arguments** @@ -139,6 +139,7 @@ def __init__(private_key: str, email: Optional[str] = None, password: Optio * **`contract_address`**: Inference contract address. * **`og_llm_server_url`**: OpenGradient LLM server URL. * **`og_llm_streaming_server_url`**: OpenGradient LLM streaming server URL. +* **`payment_network`**: Payment network for x402 transactions. Defaults to OG_EVM. #### Variables @@ -156,6 +157,22 @@ Enum for the different inference modes available for inference (VANILLA, ZKML, T * static `VANILLA` * static `ZKML` +### `PaymentNetwork` + +Payment network for x402 payment protocol transactions. + +Controls which blockchain network is used for paying for LLM inference. + +**Attributes** + +* **`OG_EVM`**: Pay on the OpenGradient EVM network (default). +* **`BASE_SEPOLIA`**: Pay on the Base Sepolia testnet using the OG token. + +#### Variables + +* static `BASE_SEPOLIA` +* static `OG_EVM` + ### `TEE_LLM` Enum for LLM models available for TEE (Trusted Execution Environment) execution. diff --git a/docs/opengradient/types.md b/docs/opengradient/types.md index 71ecfd4..882b844 100644 --- a/docs/opengradient/types.md +++ b/docs/opengradient/types.md @@ -220,6 +220,22 @@ def __init__(name: str, values: List[Tuple[int, int]]) * static `name` : str * static `values` : List[Tuple[int, int]] +### `PaymentNetwork` + +Payment network for x402 payment protocol transactions. + +Controls which blockchain network is used for paying for LLM inference. + +**Attributes** + +* **`OG_EVM`**: Pay on the OpenGradient EVM network (default). +* **`BASE_SEPOLIA`**: Pay on the Base Sepolia testnet using the OG token. + +#### Variables + +* static `BASE_SEPOLIA` +* static `OG_EVM` + ### `SchedulerParams` #### Constructor From 60404e6f892c28126cd4c9e8e8ca54019057a5ec Mon Sep 17 00:00:00 2001 From: "balogh.adam@icloud.com" Date: Mon, 9 Feb 2026 17:27:31 +0100 Subject: [PATCH 4/4] docs --- docs/opengradient/index.md | 3 ++- docs/opengradient/types.md | 3 ++- src/opengradient/types.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/opengradient/index.md b/docs/opengradient/index.md index 6dd9dfa..c5d9a16 100644 --- a/docs/opengradient/index.md +++ b/docs/opengradient/index.md @@ -166,7 +166,8 @@ Controls which blockchain network is used for paying for LLM inference. **Attributes** * **`OG_EVM`**: Pay on the OpenGradient EVM network (default). -* **`BASE_SEPOLIA`**: Pay on the Base Sepolia testnet using the OG token. +* **`BASE_SEPOLIA`**: Pay on the Base Sepolia testnet using the OG token + at address ``0x240b09731D96979f50B2C649C9CE10FcF9C7987F``. #### Variables diff --git a/docs/opengradient/types.md b/docs/opengradient/types.md index 882b844..0f94103 100644 --- a/docs/opengradient/types.md +++ b/docs/opengradient/types.md @@ -229,7 +229,8 @@ Controls which blockchain network is used for paying for LLM inference. **Attributes** * **`OG_EVM`**: Pay on the OpenGradient EVM network (default). -* **`BASE_SEPOLIA`**: Pay on the Base Sepolia testnet using the OG token. +* **`BASE_SEPOLIA`**: Pay on the Base Sepolia testnet using the OG token + at address ``0x240b09731D96979f50B2C649C9CE10FcF9C7987F``. #### Variables diff --git a/src/opengradient/types.py b/src/opengradient/types.py index 0aa6ee9..f18cf1a 100644 --- a/src/opengradient/types.py +++ b/src/opengradient/types.py @@ -18,7 +18,8 @@ class PaymentNetwork(str, Enum): Attributes: OG_EVM: Pay on the OpenGradient EVM network (default). - BASE_SEPOLIA: Pay on the Base Sepolia testnet using the OG token. + BASE_SEPOLIA: Pay on the Base Sepolia testnet using the OG token + at address ``0x240b09731D96979f50B2C649C9CE10FcF9C7987F``. Examples: >>> client = og.Client(