Python SDK for BaseCodeAgent — discoverable AI agent services on Base with x402 payments
Project description
BaseCodeAgent SDK
Python SDK for interacting with BaseCodeAgent — discoverable AI agent services on Base with x402 payments.
Installation
pip install httpx # required dependency
# or install from local path:
pip install -e .
Quick Start
Sync Client
from basecodeagent import BaseCodeAgent
# Initialize
client = BaseCodeAgent(url="https://agent-service-production-bb95.up.railway.app")
# Discover services
services = client.discover()
for svc in services:
print(f"• {svc.name}: {svc.price_usd}")
# Check health
health = client.health()
print(f"Agent: {health['agent']}")
# Get metrics
metrics = client.get_metrics()
print(f"Requests: {metrics['requests']['total']}")
# Call a service (requires payment token)
result = client.call_service(
service="code-review",
payment_token="x402-mock-abc123",
code="def hello(): print('world')",
language="python"
)
if result.is_success:
print(result.result)
Async Client
import asyncio
from basecodeagent import AsyncBaseCodeAgent
async def main():
async with AsyncBaseCodeAgent() as client:
# Discover services
services = await client.discover()
# Call service
result = await client.call_service(
service="code-review",
payment_token="x402-mock-abc123",
code="def hello(): print('world')",
language="python"
)
print(result)
asyncio.run(main())
Context Manager (Auto-close)
from basecodeagent import BaseCodeAgent
with BaseCodeAgent() as client:
services = client.discover()
print(f"{len(services)} services available")
# Client automatically closed
API Reference
BaseCodeAgent(url, timeout=30, verify_ssl=True)
Parameters:
url: Agent service base URLtimeout: Request timeout in secondsverify_ssl: Verify SSL certificates
Methods:
discover()→List[ServiceInfo]— List all servicesdiscover_dict()→Dict[str, ServiceInfo]— Services as dicthealth()→Dict— Health checkget_metrics()→Dict— Service metricscall_service(service, payment_token, **kwargs)→ServiceResponse— Call a servicesettle_payment(pay_to, service, price, admin_api_key)→Dict— Admin settlementclose()— Close HTTP connection
AsyncBaseCodeAgent(url, timeout=30, verify_ssl=True)
Same interface as sync client, but all methods are async.
ServiceInfo
Dataclass with service metadata:
name,description,price_usd,price_atomicnetwork,tags,required_fields,allowed_fields,examplesprice_float— Parsed price as float
ServiceResponse
Dataclass with service response:
status,service,request_id,result,payment_verified,timestampis_success— Property returningTrueif successful
Requirements
- Python 3.9+
- httpx (automatically installed)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file basecodeagent-0.1.0.tar.gz.
File metadata
- Download URL: basecodeagent-0.1.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa806f60527ecd51240cc35b76ef6963d1ef575b37cde9ff90c677e70c0403c8
|
|
| MD5 |
c889c3b8d073e723f5c3bc11c8919f7d
|
|
| BLAKE2b-256 |
fac49ad8ae8c490c0d56c12613ad48115fa4f47026beee9376580ebb07147db4
|
File details
Details for the file basecodeagent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: basecodeagent-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b015ae58ca1e454f8d7de1683abc485d1567cb54b6b562e659f00a8eb048ceed
|
|
| MD5 |
e7729539c41aad4c0384bd467f6d9963
|
|
| BLAKE2b-256 |
eeeabf56d6f6cfb6ce05d350669c553cb94b718101b4aef0e66dab709e0abaf4
|