A standalone local HTTP server that simulates the X API v2 for testing and development without consuming API credits.
- Complete API compatibility with X API v2 endpoints
- Stateful operations with in-memory state management
- Optional file-based state persistence across server restarts
- Interactive web UI for exploring and testing endpoints
- Usage tracking - Track API usage
- Request validation against OpenAPI specifications
- Error responses matching real API formats
- Configurable rate limiting simulation
- Streaming support
- CORS support for web applications
- OpenAPI-driven endpoint discovery and handling
- Go 1.21 or later - Download Go
# Clone the repository
git clone https://github.com/xdevplatform/playground.git
cd playground
# Build the binary
go build -o playground ./cmd/playground
# Make it executable (optional)
chmod +x playground
# Move to PATH (optional, for global access)
sudo mv playground /usr/local/bin/go install github.com/xdevplatform/playground/cmd/playground@latestThis will install the playground binary to $GOPATH/bin (or $HOME/go/bin by default).
Make sure $GOPATH/bin is in your PATH:
export PATH=$PATH:$(go env GOPATH)/binCheck the Releases page for pre-built binaries for your platform.
playground --helpYou should see the playground command help output.
-
Start the server:
playground start
-
Access the Web UI: Open http://localhost:8080/playground in your browser
-
Make API requests:
curl -H "Authorization: Bearer test_token" http://localhost:8080/2/users/me
playground start- Start the playground server- Flags:
--port/-p(default: 8080) - Port to run the server on--host(default: localhost) - Host to bind the server to--refresh- Force refresh of OpenAPI spec cache
- Flags:
playground status- Check if a server is runningplayground refresh- Refresh OpenAPI spec cache
Start on custom port:
playground start --port 3000 --host 0.0.0.0Start with OpenAPI cache refresh:
playground start --refreshConfiguration files are stored in ~/.playground/:
config.json- Playground configuration (optional, uses embedded defaults if not present)state.json- Persistent state (if persistence enabled)examples/- Custom example responses (optional).playground-openapi-cache.json- Cached OpenAPI spec
The playground provides several management endpoints (not part of X API):
GET /health- Server health and statisticsGET /rate-limits- Rate limit configuration and statusGET /config- View current configurationPUT /config/update- Update configuration (temporary, lost on restart)POST /config/save- Save configuration to filePOST /state/reset- Reset state to initial seed dataGET /state/export- Export state as JSONPOST /state/import- Import state from JSONPOST /state/save- Manually save state (if persistence enabled)DELETE /state- Delete all stateGET /endpoints- List all available endpoints
The playground tracks API usage and provides cost estimation endpoints. These endpoints provide the same data shown in the Usage tab of the web UI:
GET /api/credits/pricing- Get pricing configuration for event types and request typesGET /api/accounts/{account_id}/usage- Get usage data (query params:interval,groupBy)GET /api/accounts/{account_id}/cost- Get detailed cost breakdown with billing cycle data and time series
Getting Usage Data Programmatically:
The account_id is your developer account ID, automatically derived from your authentication token. The default token "test" maps to account "0".
# Get complete cost breakdown (same data as Usage tab)
curl http://localhost:8080/api/accounts/0/cost | jq
# Get event type usage breakdown
curl "http://localhost:8080/api/accounts/0/usage?interval=30days&groupBy=eventType" | jq
# Get request type usage breakdown
curl "http://localhost:8080/api/accounts/0/usage?interval=30days&groupBy=requestType" | jq
# Get pricing configuration
curl http://localhost:8080/api/credits/pricing | jqNote: The /api/accounts/{account_id}/cost endpoint returns all the data shown in the Usage tab, including:
- Total cost and billing cycle information
- Cost breakdowns by event type and request type
- Daily time series data for charts
- Usage statistics
See DOCUMENTATION.md for detailed API documentation.
For detailed documentation, see DOCUMENTATION.md.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT