Skip to main content
Glama

reset_usage_limit_entity

Destructive

Reset accumulated usage for a specific entity within a usage limit policy. Use list_usage_limit_entities to confirm the target first.

Instructions

Reset tracked usage for one entity under a usage limit. This changes accumulated usage for that entity only; use list_usage_limit_entities to confirm the target first.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limit_idYesUsage limit policy ID
entity_idYesEntity ID to reset usage for

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYesWhether the tool call succeeded and returned structured data
dataNoStructured success payload when ok is true
errorNoStructured error payload when ok is false

Implementation Reference

  • Service method that executes the reset logic. Validates inputs and sends POST request to /policies/usage-limits/{limitId}/entities/reset with entity_id in the body.
    async resetUsageLimitEntity(
    	limitId: string,
    	entityId: string,
    ): Promise<{ success: boolean }> {
    	if (!limitId?.trim()) {
    		throw new Error("Usage limit ID is required");
    	}
    	if (!entityId?.trim()) {
    		throw new Error("Entity ID is required");
    	}
    	return this.post<{ success: boolean }>(
    		`/policies/usage-limits/${this.encodePathSegment(limitId)}/entities/reset`,
    		{ entity_id: entityId },
    	);
    }
  • Zod schema for reset_usage_limit_entity tool input: requires limit_id and entity_id strings.
    resetUsageLimitEntity: {
    	limit_id: z.string().describe("Usage limit policy ID"),
    	entity_id: z.string().describe("Entity ID to reset usage for"),
    },
  • Tool registration using server.tool() with name 'reset_usage_limit_entity', description, schema, and handler that calls the service method and returns a success message.
    server.tool(
    	"reset_usage_limit_entity",
    	"Reset tracked usage for one entity under a usage limit. This changes accumulated usage for that entity only; use list_usage_limit_entities to confirm the target first.",
    	LIMITS_TOOL_SCHEMAS.resetUsageLimitEntity,
    	async (params) => {
    		await service.limits.resetUsageLimitEntity(
    			params.limit_id,
    			params.entity_id,
    		);
    		return {
    			content: [
    				{
    					type: "text",
    					text: JSON.stringify(
    						{
    							message: `Successfully reset usage for entity "${params.entity_id}" on limit "${params.limit_id}"`,
    							success: true,
    						},
    						null,
    						2,
    					),
    				},
    			],
    		};
    	},
    );
  • BaseService class providing get/post/put/delete HTTP methods, authentication, URL building, error handling, and logging used by LimitsService.
    export class BaseService {
    	protected readonly apiKey: string;
    	protected readonly baseUrl: string;
    	protected readonly timeout = 30000;
    
    	constructor(apiKeyOverride?: string) {
    		// Use provided API key or fall back to environment variable
    		const apiKey = apiKeyOverride ?? process.env.PORTKEY_API_KEY;
    		if (!apiKey) {
    			throw new Error("PORTKEY_API_KEY environment variable is not set");
    		}
    		this.apiKey = apiKey;
    
    		// Configurable base URL with validation
    		const baseUrl = process.env.PORTKEY_BASE_URL ?? DEFAULT_BASE_URL;
    		validateUrl(baseUrl);
    		this.baseUrl = baseUrl;
    	}
    
    	protected encodePathSegment(value: string): string {
    		return encodeURIComponent(value);
    	}
    
    	private buildUrl(path: string, params?: object): string {
    		return `${this.baseUrl}${path}${buildQueryString(params)}`;
    	}
    
    	private buildHeaders(method: HttpMethod): Record<string, string> {
    		const headers: Record<string, string> = {
    			"x-portkey-api-key": this.apiKey,
    			Accept: "application/json",
    		};
    
    		if (method === "POST" || method === "PUT") {
    			headers["Content-Type"] = "application/json";
    		}
    
    		return headers;
    	}
    
    	private serializeBody(body: unknown): string | undefined {
    		return body ? JSON.stringify(body) : undefined;
    	}
    
    	private async executeRequest<T>(
    		method: HttpMethod,
    		path: string,
    		options: ExecuteRequestOptions = {},
    	): Promise<T> {
    		const requestId = crypto.randomUUID();
    		const url = this.buildUrl(path, options.params);
    		const startTime = Date.now();
    
    		Logger.debug("HTTP request started", {
    			requestId,
    			method,
    			path,
    			metadata: { url },
    		});
    
    		try {
    			const response = await fetchWithTimeout(url, {
    				method,
    				headers: this.buildHeaders(method),
    				body: this.serializeBody(options.body),
    				timeout: this.timeout,
    			});
    
    			const duration_ms = Date.now() - startTime;
    
    			if (!response.ok) {
    				const apiError = await parseErrorResponse(response);
    				Logger.error("HTTP request failed", {
    					requestId,
    					method,
    					path,
    					statusCode: response.status,
    					duration_ms,
    					error: apiError.message,
    				});
    				throw new FetchError(apiError.message, response.status, apiError);
    			}
    
    			Logger.info("HTTP request completed", {
    				requestId,
    				method,
    				path,
    				statusCode: response.status,
    				duration_ms,
    			});
    
    			if (options.allowNoContent && response.status === 204) {
    				return {} as T;
    			}
    
    			return response.json() as Promise<T>;
    		} catch (error) {
    			const duration_ms = Date.now() - startTime;
    			// Only log network/system errors (TypeError, AbortError, etc.)
    			// FetchError from HTTP failures is already logged above
    			if (!(error instanceof FetchError)) {
    				Logger.error("HTTP request error", {
    					requestId,
    					method,
    					path,
    					duration_ms,
    					error: error instanceof Error ? error.message : String(error),
    				});
    			}
    			throw error;
    		}
    	}
    
    	protected async get<T>(path: string, params?: object): Promise<T> {
    		return this.executeRequest<T>("GET", path, { params });
    	}
    
    	protected async post<T>(path: string, body?: unknown): Promise<T> {
    		return this.executeRequest<T>("POST", path, { body });
    	}
    
    	protected async put<T>(path: string, body?: unknown): Promise<T> {
    		return this.executeRequest<T>("PUT", path, { body });
    	}
    
    	protected async delete<T>(path: string): Promise<T> {
    		return this.executeRequest<T>("DELETE", path, { allowNoContent: true });
    	}
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already mark destructiveHint=true and readOnlyHint=false; the description adds that only that entity's usage is changed, which is transparent and consistent. No contradiction.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, no wasted words, front-loaded with the main action followed by a crucial usage hint. Excellent conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Sufficiently explains the effect and prerequisite action; does not detail what 'reset' means numerically or reversibility, but output schema likely covers return values. Adequate for complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with brief descriptions; the description does not add extra meaning to the parameters beyond the schema. Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action 'Reset tracked usage for one entity under a usage limit', specifying it changes accumulated usage for that entity only, distinguishing it from sibling tools like list_usage_limit_entities and update_usage_limit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly guides to use list_usage_limit_entities first to confirm the target, providing clear context for use. Does not mention when not to use, but the guidance is helpful.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/s-b-e-n-s-o-n/portkey-admin-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server