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("openai/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="openai/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/

Documentation

docs.solvela.ai/sdks/python — full reference, async patterns, error handling.

License

Apache-2.0

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.3.0.tar.gz (38.5 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.3.0-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for solvela_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 427a6fc66eb30bd3764be6298c8183c45d505a91a83e3f3c37c1c27c77bfbfa0
MD5 ee8b07f7a3b4e9150cfedc3f3ce44aad
BLAKE2b-256 2056f781a41eff43ec2c7e1a3263bb7e4774da2e6f55346da34111f18a81f3ba

See more details on using hashes here.

Provenance

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

Publisher: sdk-python-publish.yml on solvela-ai/solvela

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.3.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for solvela_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1947b02a5ac77a9e73abbbbe7cc63e017d335be54cadd7cfc1748a19254c92c1
MD5 9fe64346d78e25bbc09b6ea954ed52ca
BLAKE2b-256 dd140ee589d43031b51ba5fcf92402e905942fdefec5b310c2532b6ba836ebaf

See more details on using hashes here.

Provenance

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

Publisher: sdk-python-publish.yml on solvela-ai/solvela

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