Skip to main content

Spraay x402 Gateway integration for Haystack - multi-chain batch payments, balances, RPC, and oracles for AI agents

Project description

๐Ÿ’ง haystack-spraay

PyPI License

Spraay x402 Gateway integration for Haystack โ€” multi-chain batch payments, balance checks, RPC calls, and oracle prices for AI agents and pipelines.

What is Spraay?

Spraay is a multi-chain batch payment protocol and x402 gateway that lets AI agents make USDC micropayments across 16+ blockchains. The gateway exposes 76+ paid endpoints covering payments, RPC, oracles, AI inference, storage, and more โ€” all payable via the x402 HTTP payment protocol.

What is Haystack?

Haystack is an open-source AI orchestration framework by deepset for building production-ready LLM applications with modular pipelines and agent workflows.

Installation

pip install haystack-spraay

Quick Start โ€” Agent with Payment Tools

import os
from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_spraay.tools import spraay_batch_payment, spraay_check_balance, spraay_oracle_price

os.environ["OPENAI_API_KEY"] = "<YOUR_KEY>"

# Create an agent with Spraay payment tools
agent = Agent(
    chat_generator=OpenAIChatGenerator(model="gpt-4o-mini"),
    tools=[spraay_batch_payment, spraay_check_balance, spraay_oracle_price],
    system_prompt="You are a helpful blockchain payment assistant. You can send payments, check balances, and look up token prices across 16+ blockchains.",
)

# Run it
result = agent.run(
    messages=[ChatMessage.from_user("What's the current price of ETH in USD?")]
)
print(result["last_message"].text)

Quick Start โ€” Pipeline Component

from haystack import Pipeline
from haystack_spraay.components import SpraayBalanceCheck, SpraayBatchPayment

# Use components directly
balance_checker = SpraayBalanceCheck(chain="base")
result = balance_checker.run(address="0xAd62f03C7514bb8c51f1eA70C2b75C37404695c8")
print(result)

# Or in a pipeline
pipeline = Pipeline()
pipeline.add_component("balance", SpraayBalanceCheck(chain="base"))
result = pipeline.run({"balance": {"address": "0x1234...", "token": "USDC"}})

Available Components

Component Description
SpraayBatchPayment Send batch USDC payments to multiple recipients
SpraayBalanceCheck Check token balances on any chain
SpraayGasPrice Get real-time gas prices
SpraayRPCCall Make raw JSON-RPC calls to any chain
SpraayOraclePrice Get real-time token prices

Available Tools (for Agents)

Tool Description
spraay_batch_payment Send multi-recipient payments
spraay_check_balance Query wallet balances
spraay_gas_price Estimate transaction costs
spraay_rpc_call Raw blockchain queries
spraay_oracle_price Token price lookups

Supported Chains

Base, Ethereum, Arbitrum, Polygon, BNB Chain, Avalanche, Solana, Stellar, XRP Ledger, Bitcoin, BOB, Unichain, Plasma, Bittensor, Stacks.

Advanced: Multi-Step Payment Pipeline

from haystack import Pipeline
from haystack_spraay.components import (
    SpraayBalanceCheck,
    SpraayGasPrice,
    SpraayBatchPayment,
)

# Build a payment pipeline: check balance โ†’ estimate gas โ†’ send payment
pipeline = Pipeline()
pipeline.add_component("balance", SpraayBalanceCheck(chain="base"))
pipeline.add_component("gas", SpraayGasPrice())
pipeline.add_component("payment", SpraayBatchPayment(chain="base"))

# Run steps individually or connect them with custom routing logic
balance_result = pipeline.run(
    {"balance": {"address": "0xSenderAddr", "token": "USDC"}}
)

Advanced: Use with Haystack Agent + Other Tools

from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.tools import ComponentTool
from haystack.components.websearch import SerperDevWebSearch
from haystack_spraay.tools import spraay_batch_payment, spraay_oracle_price

# Combine Spraay tools with web search
search_tool = ComponentTool(
    component=SerperDevWebSearch(api_key=Secret.from_env_var("SERPERDEV_API_KEY")),
    name="web_search",
    description="Search the web for information",
)

agent = Agent(
    chat_generator=OpenAIChatGenerator(model="gpt-4o"),
    tools=[spraay_batch_payment, spraay_oracle_price, search_tool],
    system_prompt=(
        "You are a crypto research assistant that can search the web, "
        "check token prices, and send payments when instructed."
    ),
)

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Haystack    โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚  Agent /       โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚  Spraay Tools   โ”‚
โ”‚  Pipeline    โ”‚     โ”‚  ToolInvoker   โ”‚     โ”‚  & Components   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                     โ”‚
                                           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                           โ”‚  Spraay x402       โ”‚
                                           โ”‚  Gateway            โ”‚
                                           โ”‚  gateway.spraay.app โ”‚
                                           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                     โ”‚
                                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                     โ”‚               โ”‚               โ”‚
                               โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”
                               โ”‚  Base    โ”‚    โ”‚  Solana  โ”‚    โ”‚  15+    โ”‚
                               โ”‚          โ”‚    โ”‚          โ”‚    โ”‚  more   โ”‚
                               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Contributing

  1. Clone: git clone https://github.com/plagtech/haystack-spraay.git
  2. Install dev deps: pip install -e ".[dev]"
  3. Run tests: pytest tests/ -v

Links

Payment Address

All x402 payments route to: 0xAd62f03C7514bb8c51f1eA70C2b75C37404695c8

License

Apache-2.0

Author

Built by @plagtech | @plag on Farcaster | @Spraay_app

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

haystack_spraay-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

haystack_spraay-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file haystack_spraay-0.1.0.tar.gz.

File metadata

  • Download URL: haystack_spraay-0.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for haystack_spraay-0.1.0.tar.gz
Algorithm Hash digest
SHA256 045423f24f1a0f20d781fda442ad073a650bc8b687de2a88d51f205fea7ede59
MD5 3b9310126c6f9601b8707cfe3f74d629
BLAKE2b-256 5662c70b92cbbfb5f11616383c9fd7952a27b9df77a78464cda6c25bbf4a0ef2

See more details on using hashes here.

File details

Details for the file haystack_spraay-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for haystack_spraay-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36fca04bf3ecbcd6be1eab983590e72aa42c6a707c56304a84e26181d86dcc6d
MD5 0ffc6514ac0568d1427fd056068ff061
BLAKE2b-256 b760e30b19195790c139f5bc3904e84e995b79f95538f57391c5dde54bf889c2

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