Skip to content
Open
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
29 changes: 29 additions & 0 deletions python/ampersend-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,42 @@ agent = X402RemoteA2aAgent(
result = await agent.run("your query")
```

## BlockRun AI Integration

Access 30+ AI models (GPT-4o, Claude, Gemini, etc.) with x402 micropayments.

```python
from ampersend_sdk.integrations.blockrun import BlockRunAI
from ampersend_sdk.x402.treasurers.naive import NaiveTreasurer
from ampersend_sdk.x402.wallets.account import AccountWallet

wallet = AccountWallet(private_key="0x...")
treasurer = NaiveTreasurer(wallet)

async with BlockRunAI(treasurer=treasurer) as ai:
response = await ai.chat("gpt-4o", "What is 2+2?")
print(response) # "4"
```

### Available Models

- **OpenAI**: `gpt-4o`, `gpt-4o-mini`, `o1`, `o1-mini`
- **Anthropic**: `claude-sonnet`, `claude-haiku`
- **Google**: `gemini-pro`, `gemini-flash`
- **DeepSeek**: `deepseek`, `deepseek-reasoner`
- **Meta**: `llama`

Powered by [BlockRun.ai](https://blockrun.ai) - The Discovery Layer for AI Agents.

## Package Structure

```
ampersend_sdk/
├── a2a/
│ ├── client/ # Client-side x402 support
│ └── server/ # Server-side x402 support
├── integrations/ # Pre-built integrations
│ └── blockrun.py # BlockRun AI (30+ models)
└── x402/ # Core x402 components
├── treasurer.py
└── wallets/ # EOA & Smart Account wallets
Expand Down
71 changes: 71 additions & 0 deletions python/ampersend-sdk/examples/blockrun_ai_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
BlockRun AI Integration Example.

This example shows how to use BlockRun AI with Ampersend SDK to add
AI capabilities to your agents. BlockRun provides 30+ AI models including
GPT-4o, Claude, Gemini via x402 micropayments.

Setup:
pip install ampersend-sdk httpx

Usage:
export BASE_CHAIN_WALLET_KEY="0x..."
python blockrun_ai_example.py
"""

import asyncio
import os

from ampersend_sdk.integrations.blockrun import BlockRunAI
from ampersend_sdk.x402.treasurers.naive import NaiveTreasurer
from ampersend_sdk.x402.wallets.account import AccountWallet


async def main():
# Setup wallet with your private key
private_key = os.environ.get("BASE_CHAIN_WALLET_KEY")
if not private_key:
print("Please set BASE_CHAIN_WALLET_KEY environment variable")
return

# Create wallet and treasurer
wallet = AccountWallet(private_key=private_key)
treasurer = NaiveTreasurer(wallet)

print(f"Wallet address: {wallet.address}")

# Create BlockRun AI client
async with BlockRunAI(treasurer=treasurer) as ai:
# Simple chat with GPT-4o
print("\n--- GPT-4o ---")
response = await ai.chat("gpt-4o", "What is the capital of France?")
print(f"Response: {response}")

# Chat with Claude
print("\n--- Claude Sonnet ---")
response = await ai.chat(
"claude-sonnet",
"Explain x402 payments in one sentence.",
)
print(f"Response: {response}")

# Chat with system prompt
print("\n--- GPT-4o with system prompt ---")
response = await ai.chat(
"gpt-4o",
"What should I invest in?",
system="You are a helpful AI assistant. Keep responses brief.",
)
print(f"Response: {response}")

# List available models
print("\n--- Available Models ---")
models = await ai.list_models()
for model in models[:5]: # Show first 5
print(f" - {model.get('id')}: {model.get('pricing', {})}")

print("\nDone!")


if __name__ == "__main__":
asyncio.run(main())
14 changes: 14 additions & 0 deletions python/ampersend-sdk/src/ampersend_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Ampersend SDK - x402 payment capabilities for A2A protocol applications.

BlockRun AI Integration:
- BlockRunAI: Direct AI client for 30+ models (GPT-4o, Claude, Gemini, etc.)
"""

# Re-export integrations for convenience
from .integrations import BlockRunAI, BlockRunAIError

__all__ = [
"BlockRunAI",
"BlockRunAIError",
]
15 changes: 15 additions & 0 deletions python/ampersend-sdk/src/ampersend_sdk/integrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Ampersend SDK Integrations.

BlockRun AI:
- BlockRunAI: Direct AI client for 30+ models (GPT-4o, Claude, Gemini, etc.)
- chat: Quick one-line chat function
"""

from .blockrun import BlockRunAI, BlockRunAIError, chat

__all__ = [
"BlockRunAI",
"BlockRunAIError",
"chat",
]
Loading