Official SDK · Java
x402 Spring Boot SDKSpring Boot 3 (Java 17+)
Thin x402 payment-gate filter for Spring Boot. Implements the frozen X402v1 wire contract. No payment logic in your app; relays to the platform's signed challenge/verify and fails closed (502, never serves paid content if the platform is unreachable).
Source is public on GitHub — official registry packages (npm · PyPI · Packagist · Go · Maven Central · NuGet · RubyGems) are coming. Each SDK implements the same frozen X402v1 wire contract.
Add pay-per-request to any Spring Boot route with one filter.
- 01Create an account & register a route
In the dashboard, add the route + price and issue a test or live API key.
- 02Install the SDK
One package; the per-SDK command is below.
- 03Add one middleware
Wrap the route — it now returns a signed x402 challenge and only serves paid content after the agent pays in USDC.
Maven: dev.x402:x402-spring:0.1.0Package id: dev.x402:x402-spring
import dev.x402.spring.X402Filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
class X402Setup {
@Bean
FilterRegistrationBean<X402Filter> premiumGate() {
FilterRegistrationBean<X402Filter> reg =
new FilterRegistrationBean<>(new X402Filter("/premium", "0.10"));
reg.addUrlPatterns("/premium");
return reg;
}
}| X402_API_KEY | your key id | Identifies the key (from the API Keys page). |
| X402_SECRET | shown once | HMAC signing secret — shown once on key creation, stored encrypted. |
| X402_ENV | sandbox | live | sandbox = test key (synthetic settlement); live = real on-chain USDC. |
| X402_BASE_URL | https://api.payrelayer.com | Platform base URL the SDK calls. |
Use a test key with X402_ENV=sandbox: payments settle synthetically so you can build and CI-assert the full challenge → pay → verify → allow loop with zero real USDC, then flip to a live key — no code change.
- Thin client — no settlement, custody, or crypto code runs in your process. Keys, fees, the on-chain 95/5 split and payouts all live on the platform; you add one middleware.
- Fails closed — if the platform is unreachable the gated route returns 502 and never serves paid content. It cannot accidentally give away a paid response.
- One frozen wire contract — X402v1 is byte-identical across all 9 SDKs, enforced by a shared known-answer signature test, so behaviour can't drift between languages.
- Signed, retried webhooks (payment.settled, payout.sent, payout.failed) + a live dashboard of requests, balances and payouts — reconciliation is done for you.
- OncePerRequestFilter / Spring Boot auto-config.
- Java 17+, Spring Boot 3.
No. The SDK is a thin HTTP client. Settlement, the 95/5 split and payouts happen on-chain on the platform side; you add one middleware and read the result.
No. It fails closed — if the platform is unreachable the gated route returns 502 and never serves the paid response.
Use a test/sandbox key (X402_ENV=sandbox). Payments settle synthetically end-to-end; flip to a live key when you're ready, with no code change.
Yes. X402v1 is a frozen wire contract, byte-identical across all 9 SDKs and enforced by a shared known-answer signature test.
No — it's a standalone filter; add it to any route, Security-independent.