get_usage_limit
Retrieve a usage limit by ID to view its full budget, threshold, grouping, and reset details. Useful after listing limits to inspect a specific policy.
Instructions
Get one usage limit by id and return its full budget, threshold, grouping, and reset details. Use list_usage_limits to discover ids or compare policies first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The unique identifier of the usage limit |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | Whether the tool call succeeded and returned structured data | |
| data | No | Structured success payload when ok is true | |
| error | No | Structured error payload when ok is false |
Implementation Reference
- src/services/limits.service.ts:169-176 (handler)The service-layer handler for get_usage_limit - makes a GET request to /policies/usage-limits/{id} and returns a UsageLimit object. Validates that the ID is non-empty before making the API call.
async getUsageLimit(id: string): Promise<UsageLimit> { if (!id?.trim()) { throw new Error("Usage limit ID is required"); } return this.get<UsageLimit>( `/policies/usage-limits/${this.encodePathSegment(id)}`, ); } - src/tools/limits.tools.ts:399-415 (registration)Registers the 'get_usage_limit' tool on the MCP server with its schema, description, and handler that calls the service layer and formats the result.
// Get usage limit server.tool( "get_usage_limit", "Get one usage limit by id and return its full budget, threshold, grouping, and reset details. Use list_usage_limits to discover ids or compare policies first.", LIMITS_TOOL_SCHEMAS.getUsageLimit, async (params) => { const result = await service.limits.getUsageLimit(params.id); return { content: [ { type: "text", text: JSON.stringify(formatUsageLimit(result), null, 2), }, ], }; }, ); - src/tools/limits.tools.ts:90-92 (schema)Zod schema for the get_usage_limit tool input - requires a single 'id' field (string) as the unique identifier of the usage limit.
getUsageLimit: { id: z.string().describe("The unique identifier of the usage limit"), }, - src/tools/limits.tools.ts:192-222 (helper)Helper function that formats a UsageLimit object into a clean JSON-serializable shape for the tool response, extracting only the relevant fields.
function formatUsageLimit(limit: UsageLimit): { id: string; name?: string; type: "cost" | "tokens"; credit_limit: number; alert_threshold?: number; periodic_reset?: "monthly" | "weekly"; status: string; conditions: UsageLimit["conditions"]; group_by: string[]; workspace_id?: string; organisation_id?: string; created_at: string; last_updated_at: string; } { return { id: limit.id, name: limit.name, type: limit.type, credit_limit: limit.credit_limit, alert_threshold: limit.alert_threshold, periodic_reset: limit.periodic_reset, status: limit.status, conditions: limit.conditions, group_by: limit.group_by, workspace_id: limit.workspace_id, organisation_id: limit.organisation_id, created_at: limit.created_at, last_updated_at: limit.last_updated_at, }; } - src/services/index.ts:151-163 (registration)The PortkeyService facade that exposes service.limits.getUsageLimit() via the 'limits' property, which is an instance of LimitsService.
} export function getSharedPortkeyService(apiKey?: string): PortkeyService { const cacheKey = getSharedServiceCacheKey(apiKey); const cached = sharedPortkeyServices.get(cacheKey); if (cached) { return cached; } const service = new PortkeyService(apiKey); sharedPortkeyServices.set(cacheKey, service); return service; }