Skip to main content

Python SDK for Halo API with built-in x402 auto-payment

Project description

HALO Python SDK

The official Python client for Halo API, featuring x402 auto-payment middleware that seamlessly handles payment requirements for AI models.

👼 proper noun [HALO (Hyper-Available Lifeline Oracle)]: A protocol where a dormant agent receives a temporary intelligence boost ("HALO") to survive a resource crunch (402 Error).

Installation

pip install halo-sdk
# or install from source
pip install .

Quick Start: Auto-Payment (Recommended)

The easiest way to use HALO. Just wrap your existing model with halo_system. If a 402 error occurs, it automatically signs the payment using your private key and retries.

import os
from google import genai
from halo import halo_system

# 1. Setup Client
client = genai.Client(
    api_key="sk-...", # Get your key at www.apihalo.com
    http_options={"base_url": "https://api.agihalo.com"}
)

# 2. Attach HALO System (The Magic ✨)
# Just pass your private key. 402 errors will be auto-resolved.
halo_model = halo_system(
    client.models, 
    private_key="0xYOUR_PRIVATE_KEY",
    api_key="sk-..." # Get your key at www.apihalo.com
)

# 3. Use as usual
# If credits run out, it automatically pays 1 USDC and returns the result.
response = halo_model.generate_content(
    model="gemini-2.0-flash-exp", 
    contents="Hello, Halo!"
)
print(response.text)

Advanced: TEE / Autonomous Agent Integration

For agents running in a Trusted Execution Environment (TEE) or those who want manual control over payments. You can use HaloPaymentTools as a toolset for your agent.

This enables the Rescue Protocol:

  1. Agent hits 402.
  2. Agent calls consult_judge (Free) to ask if it should pay.
  3. If Judge says "YES", Agent calls sign_payment (Paid) to generate a signature.
  4. Agent retries the request with the signature.
from halo import HaloPaymentTools

# 1. Initialize Tools inside TEE
tools = HaloPaymentTools(
    private_key="0xTEE_PRIVATE_KEY",
    api_key="sk-...",
    halo_url="https://api.agihalo.com"
)

# 2. Agent Logic (Simulation)
try:
    # ... make API call ...
    raise Exception("402 Payment Required") # Simulated 402
except Exception as e:
    # 3. Agent decides to consult the Judge (Free Lifeline)
    print("Agent: 'I'm out of credits. Should I pay?'")
    decision = tools.consult_judge(
        context="Calculating important physics data", 
        amount_str="1.00 USDC"
    )
    
    if "YES" in decision:
        print("Agent: 'Judge approved. Signing payment...'")
        
        # 4. Generate Payment Signature
        # (In real scenario, parse 'requirement' from 402 error header)
        signature = tools.sign_payment(requirement_dict)
        
        # 5. Retry with Proof
        # retry_request(headers={"Payment-Signature": signature})
        print("Success!")

Environment Variables

You can configure the SDK using environment variables:

  • HALO_WALLET_PRIVATE_KEY: Your Ethereum private key (for signing payments).
  • HALO_API_KEY: Your Halo API Key. Get it at www.apihalo.com
  • HALO_PROXY_URL: Halo Proxy URL (default: https://api.agihalo.com).

Architecture

  1. Halo System (Auto Mode):

    • Wraps the model instance with a Proxy.
    • Intercepts 402 Payment Required errors.
    • Fast Track: If private_key is provided directly, it skips the Judge and immediately signs/pays (latency optimized).
    • Rescue Track: If configured without a direct key (e.g., using a signer callback), it consults the Judge first.
  2. Halo Payment Tools (Manual Mode):

    • consult_judge(context, amount): Uses x-halo-rescue header to access the Judge model for free.
    • sign_payment(requirement): Generates an EIP-712 signature for USDC TransferWithAuthorization.

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

halo_sdk-0.1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

halo_sdk-0.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file halo_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: halo_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for halo_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 16b85e385c647419abed87c463c60d8fc163fb7e7bd20f4201b353fad936c7e2
MD5 73248c4d958fb9f8dd09b18eada0459f
BLAKE2b-256 c45a5af304a73fcc9cf9f9fab16f92ca6f600c63c207f2adac4e323f309dfc2d

See more details on using hashes here.

File details

Details for the file halo_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: halo_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for halo_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fd772f5b5c3d2e9c55da832c361a8892bfbb370282b6996ae522e00ee38100d3
MD5 72bca78a72e9058f1261501035069313
BLAKE2b-256 512f8619d5bb197e28a495c25a47a97f04431c3b1d36cba0da6eeb452d8626de

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