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

Direct API integration

Direct API integration#

Integrate with Kobaru using raw JSON/REST endpoints for complete control over the payment flow. This approach is ideal for non-TypeScript backends, enterprises building proprietary payment workflows, or when you need intricate internal orchestration.

Overview#

The Direct API integration gives you full control by calling Kobaru's endpoints directly. You implement four steps in your API:
1.
Return HTTP 402 with payment requirements when payment is needed
2.
Parse the PAYMENT-SIGNATURE header from the client's payment proof
3.
Call Kobaru's API to verify or settle the payment
4.
Return the response with payment confirmation
This approach works with any programming language or framework: Go, Python, Rust, Java, Ruby, PHP, or any language that can make HTTP requests.

Authentication#

All requests to Kobaru's API require your API key in the Authorization header:
HeaderValueDescription
AuthorizationBearer <API_KEY>Your Kobaru API key from the console
Content-Typeapplication/jsonRequired for all POST requests
API keys follow the format kbr_{env}_{random} where env is live or test.

Step 1: Return Payment Required (HTTP 402)#

When a request requires payment and no valid payment proof is provided, return an HTTP 402 response with the PAYMENT-REQUIRED header.

Response Format#

The PAYMENT-REQUIRED header contains a base64-encoded JSON object with payment options.

Payment Required Structure#

{
  "x402Version": 2,
  "error": "Payment required",
  "resource": {
    "url": "https://api.yourcompany.com/premium-data",
    "description": "Premium data access",
    "mimeType": "application/json"
  },
  "accepts": [
    {
      "scheme": "exact",
      "network": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
      "amount": "1000",
      "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
      "payTo": "YourSolanaWalletAddress...",
      "maxTimeoutSeconds": 60
    }
  ],
  "extensions": {
    "usage": {
      "model": "pay_per_request",
      "limit": 1,
      "unit": "request"
    }
  }
}

Payment Required Fields#

FieldTypeRequiredDescription
x402VersionintegerYesMust be 2 for x402 v2 protocol
errorstringYesHuman-readable error message
resourceobjectNoInformation about the requested resource
resource.urlstringYesFull URL of the requested resource
resource.descriptionstringNoHuman-readable description of the resource
resource.mimeTypestringNoMIME type of the resource
acceptsarrayYesArray of accepted payment methods
extensionsobjectNoProtocol extensions (e.g., usage tracking)

Payment Method Fields (accepts array items)#

FieldTypeRequiredDescription
schemestringYesPayment scheme. Currently only exact is supported
networkstringYesCAIP-2 network identifier (e.g., solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp)
amountstringYesPayment amount in atomic units (e.g., 1000 = 0.001 USDC)
assetstringYesToken mint address for Solana (USDC: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v)
payTostringYesYour wallet address to receive payment
maxTimeoutSecondsintegerNoMaximum time for payment completion. Default: 60

Supported Networks#

NetworkCAIP-2 IdentifierEnvironment
Solana Mainnetsolana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpProduction
Solana Devnetsolana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1Testing

Amount Calculation#

Amounts are specified in atomic units (smallest denomination):
Human AmountUSDC Atomic UnitsCalculation
$0.00110000.001 x 10^6
$0.01100000.01 x 10^6
$0.101000000.1 x 10^6
$1.0010000001 x 10^6
USDC uses 6 decimal places, so multiply the dollar amount by 1,000,000.

Constructing the Header#


Step 2: Parse Payment Signature#

When a client submits payment proof, they include it in the PAYMENT-SIGNATURE header as a base64-encoded JSON object.

Decoding the Header#

Payment Payload Structure#

{
  "x402Version": 2,
  "resource": {
    "url": "https://api.yourcompany.com/premium-data",
    "description": "Premium data access",
    "mimeType": "application/json"
  },
  "accepted": {
    "scheme": "exact",
    "network": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
    "amount": "1000",
    "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "payTo": "YourSolanaWalletAddress...",
    "maxTimeoutSeconds": 60
  },
  "payload": {
    "transaction": "BASE64_ENCODED_SOLANA_TRANSACTION..."
  }
}

Payment Payload Fields#

FieldTypeRequiredDescription
x402VersionintegerYesMust be 2
resourceobjectNoResource being accessed (echoed from requirements)
acceptedobjectNoThe payment method the client accepted
payloadobjectYesScheme-specific payment data
payload.transactionstringYesBase64-encoded Solana transaction (for Solana exact scheme)
extensionsobjectNoProtocol extensions

Step 3: Verify or Settle with Kobaru#

Kobaru provides two endpoints for payment processing:
EndpointPurposeWhen to Use
POST /verifyValidates payment without executing on-chainPre-authorization, checking transaction validity
POST /settleValidates AND executes payment on-chainCapturing funds when ready to deliver content

Request Schema#

Both endpoints use the same request format:
{
  "paymentPayload": {
    "x402Version": 2,
    "resource": {
      "url": "https://api.yourcompany.com/premium-data",
      "description": "Premium data access",
      "mimeType": "application/json"
    },
    "accepted": {
      "scheme": "exact",
      "network": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
      "amount": "1000",
      "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
      "payTo": "YourSolanaWalletAddress...",
      "maxTimeoutSeconds": 60
    },
    "payload": {
      "transaction": "BASE64_ENCODED_SOLANA_TRANSACTION..."
    }
  },
  "paymentRequirements": {
    "scheme": "exact",
    "network": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
    "amount": "1000",
    "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "payTo": "YourSolanaWalletAddress...",
    "maxTimeoutSeconds": 60
  }
}

Request Fields#

FieldTypeRequiredDescription
paymentPayloadobjectYesThe payment authorization from the client (decoded from PAYMENT-SIGNATURE header)
paymentRequirementsobjectYesThe payment requirements you originally specified

Payment Requirements Fields#

FieldTypeRequiredDescription
schemestringYesMust be exact
networkstringYesCAIP-2 network identifier
amountstringYesPayment amount in atomic units
assetstringYesToken mint address
payTostringYesYour wallet address
maxTimeoutSecondsintegerNoMaximum timeout in seconds (default: 60)

POST /verify#

Validates the payment transaction structure and signatures without executing it on the blockchain. Use this when you want to pre-authorize a payment before delivering content.

cURL Example#

Success Response (200 OK)#

{
  "isValid": true,
  "payer": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
}
FieldTypeDescription
isValidbooleantrue if payment is valid
payerstringWallet address of the payer

Error Response (400 Bad Request)#

{
  "isValid": false,
  "invalidReason": "invalid_exact_solana_payload_authorization_value",
  "payer": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
}
FieldTypeDescription
isValidbooleanfalse if payment is invalid
invalidReasonstringError code explaining why the payment is invalid
payerstringWallet address of the payer (if available)

Simulation Failure Response#

When a transaction simulation fails, additional debugging information is provided:
{
  "isValid": false,
  "invalidReason": "simulation_failed",
  "simulationDetails": {
    "error": "Instruction 2: InsufficientFunds",
    "errorCode": "InsufficientFunds",
    "logs": [
      "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]",
      "Program log: Error: insufficient lamports",
      "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3452 of 200000 compute units"
    ]
  }
}
FieldTypeDescription
simulationDetailsobjectPresent only when invalidReason is simulation_failed
simulationDetails.errorstringHuman-readable error message
simulationDetails.errorCodestringSolana error code
simulationDetails.logsarrayLast 5 program log lines for debugging

POST /settle#

Validates AND executes the payment on the blockchain. Use this when you are ready to capture funds and deliver content.

cURL Example#

Success Response (200 OK)#

{
  "success": true,
  "transaction": "5wHu1qwD7q4XJJnYZcPcqL8mPwRfzAQCHQ2X4KxEaJhbNgVbPjKtqZY8jW3xLqNpMdR9vS2KuHfA8yXtEcJgWmNr",
  "network": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
  "payer": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
}
FieldTypeDescription
successbooleantrue if settlement succeeded
transactionstringSolana transaction signature (can be viewed on Solana Explorer)
networkstringCAIP-2 network identifier where the transaction was executed
payerstringWallet address of the payer

Error Response (400 Bad Request)#

{
  "success": false,
  "errorReason": "simulation_failed"
}
FieldTypeDescription
successbooleanfalse if settlement failed
errorReasonstringError code explaining why settlement failed

Step 4: Return Payment Response#

After successful verification or settlement, include the result in your response using the PAYMENT-RESPONSE header.

Success Response Format#

Constructing the Header#


Complete Node.js Example#

Here is a complete, working example using Express:

Environment Variables#


Error Codes#

General Errors#

Error CodeHTTP StatusDescriptionTroubleshooting
invalid_x402_version400x402Version is not 2Ensure x402Version: 2 in paymentPayload
invalid_payload400Missing, invalid, or malformed payloadCheck JSON structure matches the schema
invalid_payment_requirements400Missing or invalid requirementsVerify all required fields are present
invalid_network400Invalid or unsupported networkUse valid CAIP-2 format (e.g., solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp)
unsupported_scheme400Scheme not supportedOnly exact scheme is currently supported
capability_not_enabled400Client lacks this capabilityEnable the network/scheme/asset in Kobaru console
duplicate_request400Concurrent request in progressWait for the first request to complete
unexpected_verify_error500Server error during verificationRetry the request
unexpected_settle_error500Server error during settlementRetry the request

Solana-Specific Errors#

Error CodeHTTP StatusDescriptionTroubleshooting
invalid_exact_solana_payload_authorization_value400Amount does not match requirementsEnsure transaction transfers the exact amount
invalid_exact_solana_payload_recipient_mismatch400Wrong destination addressVerify payTo address matches
invalid_asset_mismatch400Wrong token mintUse correct token address (USDC mint)
invalid_fee_payer400Fee payer is not the facilitatorKobaru must be the fee payer
invalid_transaction_format400Cannot decode transactionEnsure transaction is valid base64
missing_compute_budget_limit400Missing SetComputeUnitLimit instructionAdd compute budget instructions
missing_compute_budget_price400Missing SetComputeUnitPrice instructionAdd compute budget instructions
priority_fee_exceeds_limit400Priority fee too highReduce priority fee below limit
invalid_instruction_count_topology400Wrong instruction orderFollow required instruction order
facilitator_cannot_be_payer400Facilitator wallet is the sourceUse a different source wallet
simulation_failed400Transaction simulation failedCheck payer has sufficient balance
submission_failed400Transaction broadcast failedRetry the settlement

Best Practices#

1. Validate Payment Requirements Match#

Always verify that the accepted field in the payment payload matches what you required:

2. Use Idempotency for Retries#

Kobaru's endpoints are idempotent. The same transaction will return the same result, making it safe to retry on network errors:

3. Handle Errors Gracefully#

Provide meaningful error messages to clients:

4. Test on Devnet First#

Always test your integration on Solana Devnet before going to production:
Get test USDC from spl-token-faucet.com for Devnet testing.

5. Secure Your API Key#

Never expose your API key in client-side code:
Store API keys in environment variables
Use server-side calls to Kobaru's API only
Rotate keys if they are accidentally exposed

6. Log Payment Information#

Log payment details for debugging and auditing:

HTTP Status Codes Summary#

Status CodeMeaningWhen Returned
200OKPayment verified/settled successfully
400Bad RequestInvalid payment or malformed request
402Payment RequiredNo payment provided or payment invalid
500Internal Server ErrorUnexpected server error

Related documentation#

Transparent proxy integration - Zero-code integration option
Standard SDK integration - SDK-based integration for TypeScript
Advanced SDK - Sessions, budgets, and analytics (coming soon)
POST /v1/verify API reference - Complete verify endpoint documentation
POST /v1/settle API reference - Complete settle endpoint documentation
Error codes reference - Complete list of all error codes
Modified at 2026-01-07 21:46:31
Previous
Transparent proxy integration
Next
Available Chains and Assets
Built with