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.3.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.3-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: solvela_sdk-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 9382876c4627fab1d385087c5b134e7befd52ad8da7fd1a33dfccc5012158ca7
MD5 251c5f1e0bd1dc7006a2fce6f9108078
BLAKE2b-256 b5489be3deac777016345a6fca5f6792968e1bdc93e414f1c7e1d5433020f9d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for solvela_sdk-0.1.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: solvela_sdk-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4d94d26c549b4a5b890e211588ec82a7ed3a5f73f4ab04b7afe54f09c4000952
MD5 74323fac53f23e348da32f47dd34e645
BLAKE2b-256 9f0132466142600ae8612eb4a91103175ac1f0bffc921eae228ded0f3f96624a

See more details on using hashes here.

Provenance

The following attestation bundles were made for solvela_sdk-0.1.3-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