What is the Facilitator?
The Facilitator is a service that:- Parses usage tokens from various API formats (OpenAI, Anthropic, Google, etc.)
- Calculates payment amounts based on token usage and pricing
- Executes Solana blockchain transactions for payments
- Automatically splits payments between treasury and recipients
Base URLs
- Production:
https://facilitator.swarms.world
Endpoints
Health Check
Check if the Facilitator service is available and healthy.GET /health
Request
No parameters required.
Response
| Field | Type | Description |
|---|---|---|
status | string | Service status (e.g., “healthy”) |
service | string | Service name |
version | string | API version |
Parse Usage Tokens
Convert usage data from any API format into a standardized format.POST /v1/settlement/parse-usage
Automatically detects and parses usage data from multiple formats, including nested structures.
Supported Formats
| Format | Token Fields |
|---|---|
| OpenAI | prompt_tokens, completion_tokens, total_tokens |
| Anthropic | input_tokens, output_tokens, total_tokens |
| Google/Gemini | promptTokenCount, candidatesTokenCount, totalTokenCount |
| Cohere | tokens, input_tokens, output_tokens |
| Nested | usage.usage, meta.usage, statistics |
| Parameter | Type | Required | Description |
|---|---|---|---|
usage_data | object | Yes | Usage data in any supported format. Can be the entire response body or just the usage portion. |
| Field | Type | Description |
|---|---|---|
input_tokens | integer | null | Number of input/prompt tokens |
output_tokens | integer | null | Number of output/completion tokens |
total_tokens | integer | null | Total number of tokens |
Calculate Payment
Calculate payment amounts without executing any transaction. Useful for previewing costs before payment.POST /v1/settlement/calculate-payment
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
usage | object | Yes | Usage data containing token counts. Supports same formats as parse-usage endpoint. |
input_cost_per_million_usd | number | Yes | Cost per million input tokens in USD |
output_cost_per_million_usd | number | Yes | Cost per million output tokens in USD |
payment_token | string | No | Token to use for payment. Must be "SOL" or "USDC". Default: "SOL" |
| Field | Type | Description |
|---|---|---|
status | string | Status: "calculated" or "skipped" (if zero cost) |
pricing | object | Pricing breakdown (see Pricing Object below) |
payment_amounts | object | null | Payment amounts in token units (null if zero cost) |
token_price_usd | number | null | Current token price in USD |
reason | string | null | Reason if calculation was skipped |
| Field | Type | Description |
|---|---|---|
usd_cost | number | Total USD cost |
source | string | Source of pricing rates |
input_cost_per_million_usd | number | Input cost rate |
output_cost_per_million_usd | number | Output cost rate |
input_cost_usd | number | Calculated input cost in USD |
output_cost_usd | number | Calculated output cost in USD |
input_tokens | integer | null | Number of input tokens |
output_tokens | integer | null | Number of output tokens |
total_tokens | integer | null | Total tokens |
| Field | Type | Description |
|---|---|---|
total_amount_units | integer | Total payment in smallest token units (lamports for SOL) |
total_amount_token | number | Total payment in token units (SOL) |
fee_amount_units | integer | Treasury fee in smallest token units |
fee_amount_token | number | Treasury fee in token units |
agent_amount_units | integer | Agent payment in smallest token units |
agent_amount_token | number | Agent payment in token units |
Execute Settlement
Execute a payment transaction on the Solana blockchain. This endpoint calculates the payment and sends it to both the treasury (fee) and recipient (agent payment).POST /v1/settlement/settle
WARNING: This endpoint requires your wallet private key. The private key is used in-memory only and never stored or logged.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
private_key | string | Yes | Solana wallet private key. JSON array format (e.g., "[1,2,3,...]") or base58 string |
usage | object | Yes | Usage data containing token counts. Supports same formats as parse-usage endpoint |
input_cost_per_million_usd | number | Yes | Cost per million input tokens in USD |
output_cost_per_million_usd | number | Yes | Cost per million output tokens in USD |
recipient_pubkey | string | Yes | Solana public key of the recipient wallet (base58). Receives net payment after fees |
payment_token | string | No | Token to use. Must be "SOL" or "USDC". Default: "SOL" |
skip_preflight | boolean | No | Skip preflight simulation. Faster but may fail. Default: false |
commitment | string | No | Solana commitment level. Options: "processed", "confirmed", "finalized". Default: "confirmed" |
| Level | Speed | Security | Description |
|---|---|---|---|
processed | Fastest (~1-2s) | Low | May be rolled back |
confirmed | Medium (~30-60s) | Medium | Confirmed by cluster (recommended) |
finalized | Slowest (~1-2min) | High | Cannot be rolled back |
| Field | Type | Description |
|---|---|---|
status | string | Status: "paid" if successful, "skipped" if zero cost |
transaction_signature | string | null | Solana transaction signature if payment executed |
pricing | object | Complete cost breakdown (same as calculate-payment) |
payment | object | null | Payment details with splits (null if skipped) |
| Field | Type | Description |
|---|---|---|
total_amount_lamports | integer | Total payment in lamports |
total_amount_sol | number | Total payment in SOL |
total_amount_usd | number | Total payment in USD |
treasury | object | Treasury payment details |
recipient | object | Recipient payment details |
| Field | Type | Description |
|---|---|---|
pubkey | string | Wallet public key |
amount_lamports | integer | Payment in lamports |
amount_sol | number | Payment in SOL |
amount_usd | number | Payment in USD |
Payment Splitting
Payments are automatically split between:- Treasury: Receives processing fee (default 5%)
- Recipient: Receives net payment (default 95%)
- Treasury fee: 0.0000625 SOL (5%)
- Recipient payment: 0.0011875 SOL (95%)
Error Handling
Error Response Format
All errors return a consistent format:Common Error Codes
| Code | Description | Common Causes |
|---|---|---|
| 400 | Bad Request | Invalid private key format, invalid pubkey, missing required fields |
| 402 | Payment Required | Insufficient wallet balance |
| 500 | Internal Server Error | Network errors, RPC issues, service errors |
Error Handling Example
Security Best Practices
- Use Dedicated Wallets: Use separate wallets for ATP payments, not your main wallet
- Monitor Balances: Keep sufficient balance for payments and transaction fees
- Verify Transactions: Always verify transaction signatures on Solana Explorer
- Test First: Use testnet or small amounts for testing
- Never Log Keys: Never log or store private keys in your code
Timeout Recommendations
Settlement operations involve blockchain transactions which take time to confirm:| Commitment | Typical Time | Recommendation |
|---|---|---|
processed | 1-2 seconds | Fast but may be rolled back |
confirmed | 30-60 seconds | Recommended for most use cases |
finalized | 1-2 minutes | Most secure, cannot be rolled back |
Common Use Cases
Use Case 1: Preview Payment Before Execution
Use Case 2: Handle Different Usage Formats
Use Case 3: Monitor Service Health
Troubleshooting
Problem: Cannot Connect to Facilitator
Solutions:- Verify the base URL is correct:
https://facilitator.swarms.world - Check your network connectivity
- Verify SSL certificates are valid
- Check if service is experiencing downtime
Problem: Transaction Failures
Solutions:- Verify wallet has sufficient balance (including transaction fees)
- Check recipient pubkey is valid Solana address
- Verify private key format is correct (JSON array or base58)
- Check Solana network status
- Try increasing timeout or using
commitment="processed"for faster confirmation
Problem: Parsing Failures
Solutions:- Verify usage data format matches supported formats
- Check for nested structures (service handles these automatically)
- Ensure token count fields are present
- Review error message for specific format issues
Problem: Timeout Errors
Solutions:- Increase request timeout (recommended: 300+ seconds)
- Use
commitment="processed"for faster confirmation (less secure) - Check blockchain network congestion
- Verify transaction on Solana explorer after timeout - payment may have succeeded
API Reference Summary
| Endpoint | Method | Description |
|---|---|---|
/health | GET | Check service health |
/v1/settlement/parse-usage | POST | Parse usage tokens from various formats |
/v1/settlement/calculate-payment | POST | Calculate payment amounts without executing |
/v1/settlement/settle | POST | Execute settlement payment on Solana |
Additional Resources
- OpenAPI Specification: https://facilitator.swarms.world/openapi.json
- Solana Explorer: https://solscan.io
- ATP Protocol Overview
- ATP Middleware Reference
- ATP Client Reference