Skip to main content

Overview

The RelayService class enables service providers to:
  • Register services with pricing and metadata
  • Handle payments via x402 protocol
  • Prove delivery with cryptographic evidence
  • Track reputation based on outcomes
Design Philosophy: Explicit service definition, proof-first delivery, reputation as first-class.

Installation


Quick Start


Core Methods

constructor(config: ServiceConfig)

Initialize the service provider. Parameters:

register(definition: ServiceDefinition): Promise<RegisteredService>

Register service on the RelayCore platform. Parameters:
Returns:
Example:

handlePayment<TInput, TOutput>(handler: (ctx: PaymentContext<TInput>) => Promise<void>): void

Set payment handler for incoming requests. Parameters:
Delivery Proof:
Example:

getReputation(): Promise<ProviderReputation>

Get current reputation score and metrics. Returns:
Example:

getMetrics(): Promise<ServiceMetrics>

Get detailed service performance metrics. Returns:
Example:

deactivate(): Promise<void>

Deactivate the service (stop accepting new requests). Example:

Reputation System

How Reputation is Calculated

Reputation Updates

Reputation updates after each delivery:

Payment Events

Listen to payment events for logging and analytics:

Advanced Usage

SLA Enforcement

Cryptographic Proof

Rate Limiting


Best Practices

1. Always Provide Proof

2. Handle Errors Gracefully

3. Track Latency

4. Validate Input


Monetization

Pricing Strategies

Revenue Tracking


Next Steps

Agent SDK

Build agents that use your service

Session Management

Accept session-based payments

x402 Protocol

Understanding payment flow

Build Service Guide

Complete tutorial