Skip to main content
Glama

budget

Manage execution budgets to control API costs, preventing unexpected charges by setting limits and monitoring usage.

Instructions

Check or set your execution budget. Without action param, returns current status. Use action='set' with budget_usd to create/update. Budget is enforced pre-execution — you get 402 (not a surprise bill) when over limit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionNoAction: 'get' to check budget, 'set' to create/update
budget_usdNoBudget amount in USD (required for set)
periodNoBudget period: daily, weekly, monthly, total (default: monthly)
hard_limitNoIf true, reject executions over budget (default: true)

Implementation Reference

  • The handleBudget function processes the 'budget' tool logic, supporting 'get' and 'set' actions by delegating to the client.
    export async function handleBudget(
      input: BudgetInput,
      client: RhumbApiClient
    ): Promise<BudgetOutput> {
      const action = input.action || "get";
    
      if (action === "set") {
        if (!input.budget_usd || input.budget_usd <= 0) {
          return {
            agent_id: "",
            budget_usd: null,
            spent_usd: null,
            remaining_usd: null,
            period: null,
            hard_limit: null,
            unlimited: false,
          };
        }
        const result = await client.setBudget(
          input.budget_usd,
          input.period,
          input.hard_limit
        );
        return result as unknown as BudgetOutput;
      }
    
      // Default: get
      const result = await client.getBudget();
      return result as unknown as BudgetOutput;
    }
  • The tool 'budget' is registered here using the server.tool method, binding the tool definition to the handleBudget handler.
    // -- budget -----------------------------------------------------------
    server.tool(
      "budget",
      "Check or set your call spending limit. Budgets are enforced BEFORE a call — you get HTTP 402 (not a surprise bill) when you'd exceed your limit. Call with no params to check current budget and remaining balance.",
      {
        action: z.string().optional().describe(BudgetInputSchema.properties.action.description),
        budget_usd: z.number().optional().describe(BudgetInputSchema.properties.budget_usd.description),
        period: z.string().optional().describe(BudgetInputSchema.properties.period.description),
        hard_limit: z.boolean().optional().describe(BudgetInputSchema.properties.hard_limit.description)
      },
      async ({ action, budget_usd, period, hard_limit }) => {
        const result = await handleBudget({ action, budget_usd, period, hard_limit }, client);
        return {
          content: [{ type: "text" as const, text: JSON.stringify(result) }]
        };
      }
    );

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/supertrained/rhumb'

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