Overview
Surfa provides two main APIs:- Ingest API - Track events from your MCP server
- MCP Query API - Query analytics with natural language
Ingest API
POST /api/v1/ingest/events
Track events from your MCP server or application. Endpoint:| Field | Type | Required | Description |
|---|---|---|---|
session_id | string | ✅ | Unique identifier for this session (e.g., live_session_abc123) |
events | array | ✅ | Array of event objects to track |
execution_id | string | ❌ | Execution ID (returned from first request, reuse for subsequent requests) |
runtime | object | ❌ | Runtime metadata (provider, model, mode) |
| Field | Type | Required | Description |
|---|---|---|---|
kind | string | ✅ | Event category: tool, session, runtime, error, etc. |
subtype | string | ✅ | Event type: call_started, call_completed, error, etc. |
| Additional fields | any | ❌ | Any custom fields (tool_name, status, latency_ms, etc.) |
| Code | Meaning |
|---|---|
200 | Success - events tracked |
401 | Unauthorized - invalid or missing API key |
403 | Forbidden - API key revoked |
422 | Validation error - invalid payload |
429 | Rate limit exceeded |
500 | Server error |
Example Requests
Track a Tool Call
Track Multiple Events
Track with Runtime Info
Event Types
Tool Events
Track MCP tool calls:Session Events
Track session lifecycle:Error Events
Track errors:Custom Events
Track anything:MCP Query API
Used by the Surfa MCP Server to query analytics. You typically don’t call these directly - use the MCP server instead.GET /api/v1/mcp/analytics/metrics
Get high-level analytics metrics. Headers:GET /api/v1/mcp/analytics/events
Query events with filters. Query Parameters:| Parameter | Type | Description |
|---|---|---|
status | string | Filter by status: success, error |
tool_name | string | Filter by tool name |
limit | number | Max results (default: 100) |
GET /api/v1/mcp/analytics/sessions/:sessionId
Get all events for a specific session. Response:Rate Limits
Ingest API
The Ingest API has rate limiting to prevent abuse:- Limit: 1,000 events per minute per API key
- Window: 60 seconds (sliding window)
- Response:
429 Too Many Requestswhen exceeded
MCP Query API
The MCP Query API currently has no rate limits. Use responsibly.Error Handling
Authentication Errors (401, 403)
Validation Errors (422)
Rate Limit Errors (429)
Server Errors (500, 502, 503, 504)
SDK vs Direct API
Using the SDK (Recommended)
- ✅ Automatic retries
- ✅ Buffering and batching
- ✅ Session management
- ✅ Error handling
- ✅ Runtime metadata
Direct API Calls
Use direct API calls if:- You’re not using Python
- You need custom behavior
- You’re building your own SDK