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.2.0.tar.gz (25.2 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.2.0-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: solvela_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 25.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 ec995808d904049570f8786f432614b45883f36f9e83cd6bab56f10dfa41eca5
MD5 364c0aa183a8fbe3e9c546fbd0bbfe7f
BLAKE2b-256 d3fe7c0c98551d706cfcf8b9adf9ab4f073d024cfb3971de5fa079f41d9a4a3e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: solvela_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.4 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aec935a5e6b153edddec9df3df0b7e7d965d6dd27826571b95ce21bc5ff93645
MD5 2fe2a9f38eda25728805f5c85266ec95
BLAKE2b-256 818e1355a1b5ee77d9452d67c00b6e71cf5474f77ae7fd7bdc63092002861e8f

See more details on using hashes here.

Provenance

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