Kobaru
  1. Integration
Kobaru
  • Kobaru.io Gateway API
    • Introduction
      • What is Kobaru?
      • Quick start
      • How x402 works
    • Integration
      • Standard x402 SDK
      • Advanced SDK
      • Transparent proxy integration
      • Direct API integration
    • Core Concepts
      • Available Chains and Assets
      • Payment schemes
      • Security
      • Usage models
    • Guides
      • Pricing your API
      • Going to Production
      • Testing with devnet
      • Bazaar discovery
    • API Reference
      • Error Handling
      • Get Supported Payment Kinds
      • Verify Payment Authorization
      • Settle Payment
    • Discovery
      • List Discovery Resources
    • Schemas
      • SupportedResponse
      • ErrorResponse
      • UnauthorizedResponse
      • RateLimitResponse
      • VerifySuccessResponse
      • VerifyErrorResponse
      • SettleSuccessResponse
      • SettleErrorResponse
      • DiscoveryResourceItem
      • ListDiscoveryResourcesResponse
  1. Integration

Transparent proxy integration

Transparent proxy integration#

Go from unpaid API to paid API in under 5 minutes. No code changes. No deployment.
Kobaru's transparent proxy sits between your clients and your backend, handling payment verification, usage tracking, and automatic refunds. Just configure your service once in the console—all your endpoints become payment-gated instantly.

How it works#

What happens at each step:
1.
Client requests your endpoint through access.kobaru.io/{your-slug}/endpoint
2.
No payment token? Kobaru returns HTTP 402 with payment instructions
3.
Client pays by signing a Solana transaction
4.
Client retries with payment proof in the Authorization header
5.
Kobaru verifies the payment and checks remaining usage (you don't need to do anything)
6.
Request forwarded to your backend with X-Kobaru-Payment-Hash header
7.
Response returned to client, usage tracked, refunds processed if needed

Setup#

Step 1: Create your service#

In the Kobaru Console:
1.
Navigate to Services
2.
Click Create Service
3.
Configure your service:
FieldExampleDescription
Service nameweather-apiDisplay name for your service
SlugweatherYour merchant identifier in the proxy URL
Backend URLhttps://api.yourcompany.comYour actual API base URL
How routing works:
Requests to access.kobaru.io/{slug}/path are proxied to {backend-url}/path:
Client requestsKobaru proxies to
access.kobaru.io/weather/forecastapi.yourcompany.com/forecast
access.kobaru.io/weather/data/historyapi.yourcompany.com/data/history
access.kobaru.io/weather/v2/realtimeapi.yourcompany.com/v2/realtime
All paths are automatically proxied—no need to configure each route individually.

Step 2: Configure payment defaults#

Set the default payment options for your entire service:
FieldExampleDescription
NetworksSolana Mainnet, DevnetWhich blockchain networks to accept
CurrencyUSDCPayment currency
Wallet addressYourSolana...Where you receive payments
Price10000Default price in atomic units ($0.01)
Usage modelpay_per_requestHow usage is tracked
Usage limit1Requests or seconds included
These defaults apply to all requests to your service.

Step 3: Configure route overrides (optional)#

Need different pricing for specific endpoints? Add route-level overrides:
Route patternPriceUsage ModelLimitEffective Cost
GET /forecast/*10000pay_per_request10$0.001 per request
GET /historical/*100000pay_per_request1$0.10 per request
POST /realtime100000pay_per_time3600$0.10 per hour
Route overrides take precedence over service defaults. Routes without overrides use the service defaults.
When to use route overrides:
Expensive endpoints that need higher pricing (e.g., AI inference, large data exports)
High-frequency endpoints that benefit from time-based access
Free endpoints that should bypass payment (set price to 0)

Step 4: Activate your service#

1.
Review your configuration
2.
Click Activate Service
3.
Your entire API is now payment-gated at: https://access.kobaru.io/{your-slug}/

Usage models#

Kobaru supports two usage models for tracking how clients consume their payments.

Pay-per-request#

Clients pay for a bundle of requests. Each successful request decrements their remaining count.
{
  "extensions": {
    "usage": {
      "model": "pay_per_request",
      "limit": 10,
      "unit": "request"
    }
  }
}
Behavior:
Client pays once, gets 10 requests
Each request decrements the counter
Refunds increment the counter back (for eligible errors)
When counter reaches 0, client must pay again
Best for: API calls with predictable value per request.

Pay-per-time#

Clients pay for unlimited access within a time window.
{
  "extensions": {
    "usage": {
      "model": "pay_per_time",
      "limit": 3600,
      "unit": "second"
    }
  }
}
Behavior:
Clock starts on first request after payment
Unlimited requests until time expires
No refunds (time has elapsed regardless of errors)
When time expires, client must pay again
Best for: High-frequency access, streaming data, real-time feeds.

Headers forwarded to your backend#

When Kobaru forwards a paid request to your backend, it modifies headers for security and traceability.
Note: Your backend receives clean requests with payment details removed but tracking information added.

Headers added#

HeaderValueDescription
X-Kobaru-Payment-Hashabc123...Unique payment identifier for this transaction

Headers removed#

HeaderReason
AuthorizationPrevents leaking x402 payment token to your backend
HostReplaced with your backend's host
cf-connecting-ipCloudflare-specific header

Using the payment hash#

Your backend can use X-Kobaru-Payment-Hash to:
Log which payment was used for each request
Implement custom rate limiting per payment
Track usage analytics by payment
Correlate requests across your logging systems

Automatic refunds#

Kobaru automatically refunds usage when your backend returns errors that are not the client's fault. This applies only to the pay_per_request usage model.

Refund decision matrix#

Status CodeCategoryRefunded?Reason
200-299SuccessNoRequest completed successfully
400Bad RequestNoClient sent invalid request
404Not FoundNoClient requested non-existent resource
422Unprocessable EntityNoClient sent semantically invalid data
401UnauthorizedYesYour backend rejected the request (auth issue on your side)
403ForbiddenYesYour backend rejected the request (permission issue on your side)
429Too Many RequestsYesYour backend rate-limited the request
500-599Server ErrorYesYour backend encountered an error
502Bad GatewayYesKobaru could not reach your backend
Key principle: If the client paid and did everything correctly, but your backend failed, they get their usage back. If the client made an error (bad request, wrong endpoint), they do not get a refund.

Pay-per-time refunds#

The pay_per_time model does not issue refunds. Time continues to elapse regardless of errors. If your backend experiences issues, clients still consume their time window.

Testing your integration#

Testing with Devnet#

Before going to production, test with Solana Devnet:
1.
In the console, set your service to use Devnet: solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1
2.
Get test USDC from a faucet
3.
Test the complete payment flow

Verify payment requirements#

Request your endpoint without payment to see the 402 response:
Expected response:

Verify paid request flow#

After paying, include the token in subsequent requests:
Expected response: Your backend's normal response, forwarded through Kobaru.

Limitations#

The transparent proxy has some constraints due to its edge-first architecture.
LimitationValueWorkaround
WebSocket connectionsNot supportedUse Standard SDK for WebSocket APIs
Custom authenticationForwarded but not validatedYour backend handles its own auth
Request timeout50 secondsOptimize slow endpoints

When to use the SDK instead#

Consider the Standard SDK integration if you need:
WebSocket or long-lived connections
Custom payment verification logic
Full control over the 402 response format
Note: Route-based dynamic pricing (different prices per endpoint) is fully supported in the proxy via route overrides. Use the SDK only if you need pricing based on request body content, user identity, or runtime conditions.

Next steps#

Usage models - Understand pay-per-request vs pay-per-time
Pricing your API - Best practices for setting prices
Testing with devnet - Complete testing guide
Going to production - Production checklist
Modified at 2026-01-04 15:28:23
Previous
Advanced SDK
Next
Direct API integration
Built with