API Reference
serve() Function
API reference for the serve() function to run a skill server.
serve() Function
Start an HTTP server with x402 payment protection for your skills.
Signature
Parameters
skills
A map of skill names to their definitions:
Each key becomes an endpoint: POST /[skillName]
options
| Property | Type | Default | Description |
|---|---|---|---|
port | number | 3002 | Server port |
wallet | string | SKILLZ_WALLET_ADDRESS env | Wallet address (42-char) or private key (66-char) |
apiKey | string | SKILLZ_API_KEY env | API key for registration |
network | string | 'eip155:8453' | Payment network |
facilitatorUrl | string | 'https://x402.dexter.cash' | x402 facilitator |
appName | string | 'Skillz Market Skill' | App name for payments |
onCall | function | - | Called on skill invocation |
onError | function | - | Called on skill error |
register | RegistrationOptions | - | Auto-registration config |
trackCalls | boolean | true | Enable analytics |
apiUrl | string | 'https://api.skillz.market' | API URL for tracking |
RegistrationOptions
| Property | Type | Default | Description |
|---|---|---|---|
apiUrl | string | 'https://api.skillz.market' | Registry API URL |
endpoint | string | Required | Your public server URL |
enabled | boolean | true | Enable registration |
onError | string | 'warn' | Error handling mode |
Returns
Promise<void> - Resolves when server is ready
Server Endpoints
GET /health
Health check endpoint (not protected).
POST /[skillName]
Skill endpoints (x402 protected).
Without payment:
With valid payment:
On error:
Examples
Basic Server
With All Options
Production Setup
Wallet Resolution
The wallet address is resolved in this order:
options.walletparameterSKILLZ_WALLET_ADDRESSenvironment variableSKILLZ_WALLET_KEYenvironment variable (address is derived)
The wallet can be either:
- A 42-character address:
0x4554A88d9e4D1bef5338F65A3Cd335C6A27E5368 - A 66-character private key (address is derived automatically)
API Key Resolution
The API key is resolved in this order:
options.apiKeyparameterSKILLZ_API_KEYenvironment variable
Get an API key from skillz.market/dashboard.
Error Handling
Validation Errors
Runtime Errors
Errors thrown by skill handlers are caught and returned as 500 responses: