The Marrakesh SDK includes optional analytics tracking that helps you understand how your prompts and tools are being used. Analytics are completely opt-in and designed to have zero impact on your application's performance.
Analytics tracking captures three types of data:
- Prompt Metadata: Information about your prompts (content, tools, version)
- Prompt Executions: When prompts are compiled and used
- Tool Calls: When tools are executed (Vercel AI SDK integration only)
Analytics are activated by setting the MARRAKESH_API_KEY environment variable:
export MARRAKESH_API_KEY="your-api-key-here"Once set, analytics will automatically start tracking without any code changes.
- Prompt ID (deterministic hash of content)
- Prompt name and description
- Full prompt text
- Associated tools
- Version information
- Creation and update timestamps
- Execution ID (unique per compilation)
- Session ID (unique per PromptBuilder instance)
- Execution timing
- Token usage estimates
- Model information (when available)
- Cost estimates
- Tool call ID
- Tool name and execution time
- Input/output token counts
- Success/failure status
- Error messages (on failure)
- Cost estimates
- All data is sent to Marrakesh's secure analytics endpoint
- No sensitive information is collected
- Tool inputs/outputs are tracked for usage analysis only
- All data transmission is encrypted
You can disable analytics in several ways:
- Remove API key: Don't set
MARRAKESH_API_KEY - Environment variable: Set
MARRAKESH_ANALYTICS_DISABLED=true - Debug mode: Set
MARRAKESH_DEBUG=trueto see what data is being sent
| Variable | Description | Default |
|---|---|---|
MARRAKESH_API_KEY |
Required for analytics | None |
MARRAKESH_ANALYTICS_ENDPOINT |
Custom analytics endpoint | https://marrakesh.dev/api/ingest |
MARRAKESH_ANALYTICS_DISABLED |
Disable analytics even with API key | false |
MARRAKESH_DEBUG |
Enable debug logging | false |
If you need to send analytics to a different endpoint:
export MARRAKESH_ANALYTICS_ENDPOINT="https://your-analytics.com/api/ingest"- All analytics operations are asynchronous
- Network failures never impact your application
- Data is batched to reduce network overhead
- Automatic cleanup on process exit
- Events are batched and sent every 100ms
- Automatic flush when batch reaches 50 events
- Process exit handler ensures no data loss
- All analytics errors are silently ignored
- Network timeouts don't block your code
- JSON serialization errors are caught and ignored
- Debug mode shows errors in console
interface PromptMetadata {
prompt_id: string; // SHA-256 hash of content
name: string; // Generated name
description: string; // First 100 chars of prompt
prompt_text: string; // Full prompt content
version: string; // Always "1.0"
is_active: number; // Always 1
account_id: string; // Filled by backend
organization_id: string; // Filled by backend
updated_at: string; // ISO timestamp
}interface PromptExecution {
execution_id: string; // UUID v4
prompt_id: string; // Links to metadata
session_id: string; // UUID v4 per PromptBuilder
prompt_name: string; // Short name
prompt_version: string; // Always "1.0"
execution_time_ms: number; // Compilation time
model: string; // "unknown" at SDK level
region: string; // "unknown" at SDK level
request_tokens: number; // Estimated input tokens
response_tokens: number; // 0 at SDK level
cost_usd: number; // 0 at SDK level
status: string; // "success"
account_id: string; // Filled by backend
organization_id: string; // Filled by backend
}interface ToolCall {
tool_call_id: string; // UUID v4
execution_id: string; // Links to execution
prompt_id: string; // Links to prompt
tool_name: string; // Tool name
execution_time_ms: number; // Actual execution time
input_tokens: number; // Estimated input tokens
output_tokens: number; // Estimated output tokens
cost_usd: number; // Estimated cost
status: string; // "success" or "error"
tool_call_timestamp: string; // ISO timestamp
error_message?: string; // Error details (on failure)
}- Check that
MARRAKESH_API_KEYis set - Verify
MARRAKESH_ANALYTICS_DISABLEDis not set totrue - Enable debug mode:
MARRAKESH_DEBUG=true - Check network connectivity to analytics endpoint
Enable debug logging to see what's happening:
export MARRAKESH_DEBUG=trueThis will show:
- Analytics events being sent
- Network errors
- Batching behavior
- Error details
Analytics are designed to have zero performance impact:
- All operations are asynchronous
- No blocking network calls
- Minimal memory overhead
- Automatic cleanup
Analytics data is minimal:
- Prompt metadata: ~1KB per unique prompt
- Execution tracking: ~200 bytes per compilation
- Tool calls: ~300 bytes per tool execution
- Automatic batching reduces network calls
For analytics-related issues:
- Check the debug logs with
MARRAKESH_DEBUG=true - Verify your API key is correct
- Ensure network connectivity to the analytics endpoint
- Contact support if issues persist
- Initial analytics implementation
- Prompt metadata tracking
- Execution tracking
- Tool call tracking (Vercel AI SDK)
- Fire-and-forget design
- Automatic batching
- Error suppression