# Using the SDK

The OpenGPU Python SDK provides programmatic access to the network for automation and integration. Currently Python-only, covering core functionality.

**Full documentation**: [opengpu-network.github.io/sdk-ogpu-py](https://opengpu-network.github.io/sdk-ogpu-py/)

## Installation

```bash
pip install ogpu
```

## Configuration

Create a `.env` file with your credentials:

```
CLIENT_PRIVATE_KEY=your_private_key_here
```

## Verify Installation

```python
import ogpu
print(f"OpenGPU SDK version: {ogpu.__version__}")

from ogpu.service import task
from ogpu.client import OGPUClient
print("OpenGPU SDK installed successfully!")
```

## Client API

### Publish a Source

```python
from ogpu.client import publish_source, SourceInfo, ImageEnvironments, DeliveryMethod

source_info = SourceInfo(
    name="My-Model",
    description="My AI model",
    image_environments=ImageEnvironments(
        nvidia="docker-compose-nvidia.yml"
    ),
    delivery_method=DeliveryMethod.FIRST_RESPONSE
)

source_address = publish_source(source_info)
```

### Publish a Task

```python
from ogpu.client import publish_task, TaskInfo, TaskInput

task_info = TaskInfo(
    source_address="0x...",
    task_input=TaskInput(
        function_name="process",
        input_data={"text": "Hello!"}
    ),
    expiry_time=3600,
    payment=0.01
)

task_address = publish_task(task_info)
```

### Get Responses

```python
from ogpu.client import get_task_responses, confirm_response

responses = get_task_responses(task_address)

# For Manual Confirmation delivery method
confirm_response(response_address)
```

## Service API

For building task handlers that run on provider nodes:

```python
import ogpu.service
from pydantic import BaseModel

class Request(BaseModel):
    text: str

class Response(BaseModel):
    result: str

@ogpu.service.init()
def load_model():
    ogpu.service.logger.info("Loading model...")

@ogpu.service.expose(timeout=60)
def process(data: Request) -> Response:
    return Response(result="processed")

if __name__ == "__main__":
    ogpu.service.start()
```

## Network Selection

```python
from ogpu.client import set_chain, ChainId

set_chain(ChainId.OGPU_MAINNET)  # Chain ID: 1071
# or
set_chain(ChainId.OGPU_TESTNET)  # Chain ID: 200820172034
```

## Best Practices

* **Store private keys securely**: Use environment variables
* **Set appropriate timeouts**: Network operations may take time
* **Use Pydantic models**: Required for service input/output

> See [SDK Documentation](https://opengpu-network.github.io/sdk-ogpu-py/) for API reference.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://opengpu-network.gitbook.io/opengpu-network/for-clients/using-the-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
