Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Before using the SDK, you will need:

1. **Private Key**: An Ethereum-compatible wallet private key funded with **Base Sepolia OPG tokens** for x402 LLM payments
2. **Test Tokens**: Obtain free test tokens from the [OpenGradient Faucet](https://faucet.opengradient.ai) for testnet LLM inference
3. **Alpha Private Key** (Optional): A separate private key funded with **OpenGradient testnet gas tokens** for Alpha Testnet on-chain inference. If not provided, the primary `private_key` is used for both chains.
3. **Alpha Testnet Key** (Optional): A private key funded with **OpenGradient testnet gas tokens** for Alpha Testnet on-chain inference (can be the same or a different key)
4. **Model Hub Account** (Optional): Required only for model uploads. Register at [hub.opengradient.ai/signup](https://hub.opengradient.ai/signup)

### Configuration
Expand All @@ -66,29 +66,30 @@ The following Firebase configuration variables are **optional** and only needed

**Note**: If you're only using the SDK for LLM inference, you don't need to configure any environment variables.

### Client Initialization
### Initialization

The SDK provides separate clients for each service. Create only the ones you need:

```python
import os
import opengradient as og

client = og.Client(
private_key=os.environ.get("OG_PRIVATE_KEY"), # Base Sepolia OPG tokens for LLM payments
alpha_private_key=os.environ.get("OG_ALPHA_PRIVATE_KEY"), # Optional: OpenGradient testnet tokens for on-chain inference
email=None, # Optional: required only for model uploads
password=None,
)
```
# LLM inference — settles via x402 on Base Sepolia using OPG tokens
llm = og.LLM(private_key=os.environ.get("OG_PRIVATE_KEY"))

The client operates across two chains:
- **LLM inference** (`client.llm`) settles via x402 on **Base Sepolia** using OPG tokens (funded by `private_key`)
- **Alpha Testnet** (`client.alpha`) runs on the **OpenGradient network** using testnet gas tokens (funded by `alpha_private_key`, or `private_key` when not provided)
# Alpha Testnet — on-chain inference on the OpenGradient network using testnet gas tokens
alpha = og.Alpha(private_key=os.environ.get("OG_PRIVATE_KEY"))

# Model Hub — requires email/password, only needed for model uploads
hub = og.ModelHub(email="you@example.com", password="...")
```

### OPG Token Approval

Before making LLM requests, your wallet must approve OPG token spending via the [Permit2](https://github.com/Uniswap/permit2) protocol. Call this once (it's idempotent — no transaction is sent if the allowance already covers the requested amount):

```python
client.llm.ensure_opg_approval(opg_amount=5)
llm.ensure_opg_approval(opg_amount=5)
```

See [Payment Settlement](#payment-settlement) for details on settlement modes.
Expand All @@ -99,7 +100,7 @@ See [Payment Settlement](#payment-settlement) for details on settlement modes.

OpenGradient provides secure, verifiable inference through Trusted Execution Environments. All supported models include cryptographic attestation verified by the OpenGradient network. LLM methods are async:
```python
completion = await client.llm.chat(
completion = await llm.chat(
model=og.TEE_LLM.GPT_5,
messages=[{"role": "user", "content": "Hello!"}],
)
Expand All @@ -111,7 +112,7 @@ print(f"Transaction hash: {completion.transaction_hash}")

For real-time generation, enable streaming:
```python
stream = await client.llm.chat(
stream = await llm.chat(
model=og.TEE_LLM.CLAUDE_SONNET_4_6,
messages=[{"role": "user", "content": "Explain quantum computing"}],
max_tokens=500,
Expand Down Expand Up @@ -190,7 +191,7 @@ The Alpha Testnet provides access to experimental capabilities including custom

Browse models on the [Model Hub](https://hub.opengradient.ai/) or deploy your own:
```python
result = client.alpha.infer(
result = alpha.infer(
model_cid="your-model-cid",
model_input={"input": [1.0, 2.0, 3.0]},
inference_mode=og.InferenceMode.VANILLA,
Expand All @@ -204,12 +205,7 @@ Deploy on-chain AI workflows with optional scheduling:
```python
import opengradient as og

client = og.Client(
private_key="your-private-key", # Base Sepolia OPG tokens
alpha_private_key="your-alpha-private-key", # OpenGradient testnet tokens
email="your-email",
password="your-password",
)
alpha = og.Alpha(private_key="your-private-key")

# Define input query for historical price data
input_query = og.HistoricalInputQuery(
Expand All @@ -222,7 +218,7 @@ input_query = og.HistoricalInputQuery(
)

# Deploy workflow with optional scheduling
contract_address = client.alpha.new_workflow(
contract_address = alpha.new_workflow(
model_cid="your-model-cid",
input_query=input_query,
input_tensor_name="input",
Expand All @@ -237,14 +233,14 @@ print(f"Workflow deployed at: {contract_address}")
### Workflow Execution and Monitoring
```python
# Manually trigger workflow execution
result = client.alpha.run_workflow(contract_address)
result = alpha.run_workflow(contract_address)
print(f"Inference output: {result}")

# Read the latest result
latest = client.alpha.read_workflow_result(contract_address)
latest = alpha.read_workflow_result(contract_address)

# Retrieve historical results
history = client.alpha.read_workflow_history(
history = alpha.read_workflow_history(
contract_address,
num_results=5
)
Expand Down Expand Up @@ -299,7 +295,7 @@ OpenGradient supports multiple settlement modes through the x402 payment protoco

Specify settlement mode in your requests:
```python
result = await client.llm.chat(
result = await llm.chat(
model=og.TEE_LLM.GPT_5,
messages=[{"role": "user", "content": "Hello"}],
x402_settlement_mode=og.x402SettlementMode.BATCH_HASHED,
Expand Down
51 changes: 25 additions & 26 deletions docs/CLAUDE_SDK_USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ pip install opengradient
import opengradient as og
import os

# Initialize client
client = og.Client(
private_key=os.environ["OG_PRIVATE_KEY"], # Required: Ethereum private key
)
# Create an LLM client
llm = og.LLM(private_key=os.environ["OG_PRIVATE_KEY"])

# LLM Chat (TEE-verified with x402 payments, async)
result = await client.llm.chat(
result = await llm.chat(
model=og.TEE_LLM.CLAUDE_HAIKU_4_5,
messages=[{"role": "user", "content": "Hello!"}],
max_tokens=100,
Expand All @@ -34,24 +32,25 @@ print(result.chat_output["content"])

## Core API Reference

### Client Initialization
### Initialization

Each service has its own client class:

```python
# Option 1: Create client instance (recommended)
client = og.Client(
private_key="0x...", # Required: Ethereum private key
email=None, # Optional: Model Hub auth
password=None, # Optional: Model Hub auth
)
# LLM inference (Base Sepolia OPG tokens for x402 payments)
llm = og.LLM(private_key="0x...")

# On-chain model inference (OpenGradient testnet gas tokens)
alpha = og.Alpha(private_key="0x...")

# Option 2: Global initialization
og.init(private_key="0x...", email="...", password="...")
# Model Hub (email/password auth, only needed for model uploads)
hub = og.ModelHub(email="...", password="...")
```

### LLM Chat

```python
result = await client.llm.chat(
result = await llm.chat(
model: TEE_LLM, # og.TEE_LLM enum value
messages: List[Dict], # [{"role": "user", "content": "..."}]
max_tokens: int = 100,
Expand All @@ -72,7 +71,7 @@ result = await client.llm.chat(
### LLM Completion

```python
result = await client.llm.completion(
result = await llm.completion(
model: TEE_LLM,
prompt: str,
max_tokens: int = 100,
Expand All @@ -88,7 +87,7 @@ result = await client.llm.completion(
### ONNX Model Inference

```python
result = client.alpha.infer(
result = alpha.infer(
model_cid: str, # IPFS CID of model
inference_mode: og.InferenceMode, # VANILLA, TEE, or ZKML
model_input: Dict[str, Any], # Input tensors
Expand Down Expand Up @@ -139,7 +138,7 @@ og.TEE_LLM.GROK_4_1_FAST_NON_REASONING
All models are accessed through the OpenGradient TEE infrastructure with x402 payments:

```python
result = await client.llm.chat(
result = await llm.chat(
model=og.TEE_LLM.GPT_5,
messages=[{"role": "user", "content": "Hello"}],
)
Expand All @@ -165,7 +164,7 @@ tools = [{
}
}]

result = await client.llm.chat(
result = await llm.chat(
model=og.TEE_LLM.CLAUDE_SONNET_4_6,
messages=[{"role": "user", "content": "What's the weather in NYC?"}],
tools=tools,
Expand All @@ -180,7 +179,7 @@ if result.chat_output.get("tool_calls"):
### Streaming

```python
stream = await client.llm.chat(
stream = await llm.chat(
model=og.TEE_LLM.CLAUDE_SONNET_4_6,
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
Expand All @@ -200,7 +199,7 @@ from langgraph.prebuilt import create_react_agent
# Create LangChain-compatible LLM
llm = og.agents.langchain_adapter(
private_key=os.environ["OG_PRIVATE_KEY"],
model_cid=og.LLM.CLAUDE_SONNET_4_6,
model_cid=og.TEE_LLM.CLAUDE_SONNET_4_6,
max_tokens=300,
)

Expand Down Expand Up @@ -228,19 +227,19 @@ input_query = og.HistoricalInputQuery(
scheduler = og.SchedulerParams(frequency=60, duration_hours=2)

# Deploy
contract = client.alpha.new_workflow(
contract = alpha.new_workflow(
model_cid="your-model-cid",
input_query=input_query,
input_tensor_name="price_data",
scheduler_params=scheduler,
)

# Manually trigger execution
result = client.alpha.run_workflow(contract)
result = alpha.run_workflow(contract)

# Read results
latest = client.alpha.read_workflow_result(contract)
history = client.alpha.read_workflow_history(contract, num_results=5)
latest = alpha.read_workflow_result(contract)
history = alpha.read_workflow_history(contract, num_results=5)
```

### AlphaSense Tool Creation
Expand Down Expand Up @@ -287,7 +286,7 @@ LLM methods raise `RuntimeError` on failure and `ValueError` for invalid argumen

```python
try:
result = await client.llm.chat(...)
result = await llm.chat(...)
except RuntimeError as e:
print(f"Inference failed: {e}")
except ValueError as e:
Expand Down
8 changes: 4 additions & 4 deletions docs/opengradient/client/alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ including on-chain ONNX model inference, workflow deployment, and execution.

```python
def __init__(
blockchain: `Web3`,
wallet_account: `LocalAccount`,
inference_hub_contract_address: str,
api_url: str
private_key: str,
rpc_url: str = 'https://ogevmdevnet.opengradient.ai',
inference_contract_address: str = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE',
api_url: str = 'https://sdk-devnet.opengradient.ai'
)
```

Expand Down
83 changes: 0 additions & 83 deletions docs/opengradient/client/client.md

This file was deleted.

Loading
Loading