check_usage
Check your monthly API usage and plan limits to monitor consumption and stay within allowance.
Instructions
Check your current monthly API usage and plan limits.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "check_usage"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:232-265 (handler)The 'check_usage' tool handler function. It fetches usage data from the StripFeed API at /usage, formats the response with plan name, usage count, limit, remaining calls, and reset date, and returns it as text content.
server.tool( "check_usage", "Check your current monthly API usage and plan limits.", {}, async () => { const apiKey = getApiKey(); const response = await fetch(`${BASE_URL}/usage`, { headers: { Authorization: `Bearer ${apiKey}` }, }); if (!response.ok) { const body = await response.text(); let message: string; try { message = JSON.parse(body).error; } catch { message = body; } throw new Error(`StripFeed API error ${response.status}: ${message}`); } const data = await response.json(); const lines = [ `Plan: ${data.plan}`, `Usage: ${data.usage.toLocaleString()}${data.limit ? ` / ${data.limit.toLocaleString()}` : ' (unlimited)'}`, ]; if (data.remaining !== null) lines.push(`Remaining: ${data.remaining.toLocaleString()}`); lines.push(`Resets: ${data.resetsAt}`); return { content: [{ type: "text" as const, text: lines.join("\n") }], }; } ); - src/index.ts:232-265 (registration)The tool is registered via server.tool() with the name 'check_usage', a description string, an empty schema object (no input parameters), and the handler function.
server.tool( "check_usage", "Check your current monthly API usage and plan limits.", {}, async () => { const apiKey = getApiKey(); const response = await fetch(`${BASE_URL}/usage`, { headers: { Authorization: `Bearer ${apiKey}` }, }); if (!response.ok) { const body = await response.text(); let message: string; try { message = JSON.parse(body).error; } catch { message = body; } throw new Error(`StripFeed API error ${response.status}: ${message}`); } const data = await response.json(); const lines = [ `Plan: ${data.plan}`, `Usage: ${data.usage.toLocaleString()}${data.limit ? ` / ${data.limit.toLocaleString()}` : ' (unlimited)'}`, ]; if (data.remaining !== null) lines.push(`Remaining: ${data.remaining.toLocaleString()}`); lines.push(`Resets: ${data.resetsAt}`); return { content: [{ type: "text" as const, text: lines.join("\n") }], }; } ); - src/index.ts:9-18 (helper)Supporting helper function getApiKey() which retrieves the STRIPFEED_API_KEY environment variable, used by check_usage to authenticate the API request.
function getApiKey(): string { const key = process.env.STRIPFEED_API_KEY; if (!key) { throw new Error( "STRIPFEED_API_KEY environment variable is required. " + "Get your key at https://www.stripfeed.dev/dashboard/keys" ); } return key; }