This MCP tool provides functionality to fetch and analyze OpenAI API costs for different time periods.
- Fetch OpenAI costs for week, month, or year periods
- Calculate total costs from API usage data
- Error handling and validation
- MCP-compatible tool interface
The tool can be called with the following parameters:
period: Time period to fetch costs for (default: "month")- Valid values: "week", "month", "year"
The tool returns a structured response with:
success: Boolean indicating if the operation was successfulperiod: The time period requestedtotalCost: Total cost in USDcurrency: Currency (always USD)message: Human-readable summaryerror: Error message (if success is false)
{
"success": true,
"period": "month",
"totalCost": 15.67,
"currency": "USD",
"message": "Total OpenAI costs for month: $15.67"
}dayjs: For date manipulation and Unix timestamp conversion- OpenAI API access with valid API key
The API key is currently hardcoded in the module. In production, this should be moved to environment variables or a secure configuration system.