Skip to main content

Solana-native payment gateway for AI agents — pay for LLM calls with USDC, no API keys

Project description

solvela

Python SDK for Solvela — a Solana-native AI agent payment gateway. AI agents pay for LLM API calls with USDC-SPL on Solana via the x402 protocol.

Installation

pip install solvela-sdk

For development:

pip install -e ".[dev]"

Quick Start

import asyncio
from solvela import SolvelaClient, ClientConfig, Wallet

async def main():
    wallet, mnemonic = Wallet.create()
    print(f"Wallet: {wallet.address()}")
    print(f"Mnemonic (save this!): {mnemonic}")

    config = ClientConfig(gateway_url="http://localhost:8402")
    client = SolvelaClient(config=config, wallet=wallet)

    # List available models
    models = await client.models()
    for m in models:
        print(f"  {m.id}{m.display_name}")

    # Estimate cost (triggers 402)
    cost = await client.estimate_cost("gpt-4o")
    print(f"Cost: {cost.cost_breakdown.total} {cost.cost_breakdown.currency}")

asyncio.run(main())

OpenAI-Compatible Interface

from solvela import SolvelaClient
from solvela.openai_compat import OpenAICompat

client = SolvelaClient()
openai = OpenAICompat(client)

# Same interface as the OpenAI Python SDK
response = await openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)

Smart Features

  • Response cachingenable_cache=True deduplicates identical requests
  • Session trackingenable_sessions=True tracks conversation context with three-strike escalation
  • Quality checksenable_quality_check=True detects degraded responses and retries
  • Balance guard — automatic fallback to free models when USDC balance hits zero
  • Balance monitor — background polling with low-balance callbacks

Configuration

from solvela import ClientConfig, ClientBuilder

# Dataclass
config = ClientConfig(
    gateway_url="http://localhost:8402",
    enable_cache=True,
    enable_sessions=True,
    enable_quality_check=True,
    free_fallback_model="deepseek-chat",
    max_payment_amount=100_000,  # atomic USDC (0.10 USDC)
)

# Fluent builder
config = (
    ClientBuilder()
    .gateway_url("http://localhost:8402")
    .enable_cache(True)
    .max_payment_amount(100_000)
    .build()
)

Running Tests

# Unit + integration tests
pytest tests/unit/ tests/integration/ -v

# Live contract tests (requires running gateway)
SOLVELA_LIVE_TESTS=1 pytest tests/live/ -v

# Linting
ruff check src/ tests/

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

solvela_sdk-0.1.2.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

solvela_sdk-0.1.2-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file solvela_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: solvela_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for solvela_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 98866bc2d44a4278e1780850d48df532c53e6bec129f190142a5fd4189f80dec
MD5 080f7029e556645bac8f0ca7302102a9
BLAKE2b-256 1930a6fa4c9a00456034d511e6e4816451b363212ba1e9b07ff9ed31f38194ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for solvela_sdk-0.1.2.tar.gz:

Publisher: release-pypi.yml on solvela-ai/solvela-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file solvela_sdk-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: solvela_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for solvela_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 afe760a9e51acc08f7ca45f779a925e8507f2cc65b55629f10c4eb715af61b84
MD5 223cf40c68fe99979c5fa0b66c776465
BLAKE2b-256 e67b6a2909f3fb740543a711a4e72f898e7a7a1d03668523b526a811b1872225

See more details on using hashes here.

Provenance

The following attestation bundles were made for solvela_sdk-0.1.2-py3-none-any.whl:

Publisher: release-pypi.yml on solvela-ai/solvela-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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