Skip to main content
Glama

get_usage

Retrieve current month's usage statistics including operations count, tier information, remaining quota, and fees for AI agent wallet infrastructure.

Instructions

Get the current month's usage statistics. Returns operations count, tier info, remaining quota, and fees.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function for get_usage tool that makes an API call to /usage endpoint and returns usage statistics (operations count, tier info, remaining quota, and fees)
    async () => {
      const data = await api('/usage');
      return jsonResponse(data);
    },
  • Input schema for get_usage tool - empty object indicating no parameters required
    {},
  • src/index.ts:1133-1142 (registration)
    Registration of get_usage tool with the MCP server, including tool name, description, schema, and handler
    server.tool(
      'get_usage',
      'Get the current month\'s usage statistics. ' +
        'Returns operations count, tier info, remaining quota, and fees.',
      {},
      async () => {
        const data = await api('/usage');
        return jsonResponse(data);
      },
    );
  • API helper function used by get_usage to make authenticated HTTP requests to the AgentWallet REST API
    async function api(path: string, method = 'GET', body?: Record<string, unknown>, extraHeaders?: Record<string, string>): Promise<unknown> {
      const url = `${API_BASE}${path}`;
      const headers: Record<string, string> = {
        'Content-Type': 'application/json',
        ...extraHeaders,
      };
    
      if (API_USER && API_PASS) {
        headers['Authorization'] = 'Basic ' + Buffer.from(`${API_USER}:${API_PASS}`).toString('base64');
      }
    
      const options: RequestInit = { method, headers };
      if (body && method !== 'GET') {
        options.body = JSON.stringify(body);
      }
    
      const res = await fetch(url, options);
      const data = await res.json();
    
      // Handle 402 Payment Required — auto-pay if wallet configured
      if (res.status === 402 && X402_WALLET_ID && !extraHeaders?.['X-PAYMENT']) {
        return handleX402Payment(data as X402Response, path, method, body);
      }
    
      if (!res.ok) {
        const error = (data as { error?: string }).error || `HTTP ${res.status}`;
        throw new Error(error);
      }
    
      return data;
    }
  • Helper function used by get_usage to format API responses as MCP tool responses
    function jsonResponse(data: unknown) {
      return { content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }] };
    }

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/hifriendbot/agentwallet-mcp'

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