Skip to main content

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 URL
  • timeout: Request timeout in seconds
  • verify_ssl: Verify SSL certificates

Methods:

  • discover()List[ServiceInfo] — List all services
  • discover_dict()Dict[str, ServiceInfo] — Services as dict
  • health()Dict — Health check
  • get_metrics()Dict — Service metrics
  • call_service(service, payment_token, **kwargs)ServiceResponse — Call a service
  • settle_payment(pay_to, service, price, admin_api_key)Dict — Admin settlement
  • close() — 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_atomic
  • network, tags, required_fields, allowed_fields, examples
  • price_float — Parsed price as float

ServiceResponse

Dataclass with service response:

  • status, service, request_id, result, payment_verified, timestamp
  • is_success — Property returning True if successful

Requirements

  • Python 3.9+
  • httpx (automatically installed)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

basecodeagent-0.1.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

basecodeagent-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

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

Hashes for basecodeagent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aa806f60527ecd51240cc35b76ef6963d1ef575b37cde9ff90c677e70c0403c8
MD5 c889c3b8d073e723f5c3bc11c8919f7d
BLAKE2b-256 fac49ad8ae8c490c0d56c12613ad48115fa4f47026beee9376580ebb07147db4

See more details on using hashes here.

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

Hashes for basecodeagent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b015ae58ca1e454f8d7de1683abc485d1567cb54b6b562e659f00a8eb048ceed
MD5 e7729539c41aad4c0384bd467f6d9963
BLAKE2b-256 eeeabf56d6f6cfb6ce05d350669c553cb94b718101b4aef0e66dab709e0abaf4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page