Skip to main content
Glama

cost_estimate

Estimate token usage and execution time for AI tasks to help plan resources before running complex operations.

Instructions

预估任务执行成本(Token 用量、预计耗时)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
taskYes要预估的任务描述

Implementation Reference

  • The handler for the 'cost_estimate' tool. It takes a task description, estimates token input/output based on task length and complexity keywords, calculates approximate costs using GPT-4o pricing, estimates execution time using average stats, and returns a formatted Markdown report with the estimates.
            case 'cost_estimate': {
              const { task } = args as { task: string };
              
              // 简单的 token 估算(基于任务描述长度和复杂度)
              const taskTokens = Math.ceil(task.length / 4); // 粗略估算输入 tokens
              const isComplex = task.includes('优化') || task.includes('架构') || task.includes('重构') || task.includes('安全');
              const estimatedExperts = isComplex ? 3 : 2;
              const tokensPerExpert = isComplex ? 4000 : 2000;
              
              const estimatedInputTokens = taskTokens + (estimatedExperts * 500); // 系统提示词
              const estimatedOutputTokens = estimatedExperts * tokensPerExpert;
              const totalTokens = estimatedInputTokens + estimatedOutputTokens;
              
              // 费用估算(基于 GPT-4o 价格:$5/1M input, $15/1M output)
              const inputCost = (estimatedInputTokens / 1000000) * 5;
              const outputCost = (estimatedOutputTokens / 1000000) * 15;
              const totalCost = inputCost + outputCost;
              
              // 耗时估算
              const avgDuration = globalStats.getGlobalStats().avgDuration || 5000;
              const estimatedTime = (avgDuration * estimatedExperts) / 1000;
              
              const estimate = `# 💰 成本预估
    
    ## 任务分析
    - **任务描述**: ${task.slice(0, 100)}${task.length > 100 ? '...' : ''}
    - **复杂度**: ${isComplex ? '高' : '中'}
    - **预计专家数**: ${estimatedExperts} 个
    
    ## Token 预估
    | 类型 | 数量 |
    |------|------|
    | 输入 Tokens | ~${estimatedInputTokens.toLocaleString()} |
    | 输出 Tokens | ~${estimatedOutputTokens.toLocaleString()} |
    | **总计** | **~${totalTokens.toLocaleString()}** |
    
    ## 费用预估 (基于 GPT-4o)
    - 输入: $${inputCost.toFixed(4)}
    - 输出: $${outputCost.toFixed(4)}
    - **总计**: **$${totalCost.toFixed(4)}**
    
    ## 时间预估
    - 预计耗时: ~${estimatedTime.toFixed(0)} 秒
    
    > ⚠️ 这是粗略估算,实际费用取决于模型选择和任务复杂度`;
    
              return {
                content: [{ type: 'text', text: estimate }],
              };
            }
  • src/server.ts:275-288 (registration)
    The tool registration entry in the listTools handler, defining the name, description, and input schema (requiring a 'task' string).
    {
      name: 'cost_estimate',
      description: '预估任务执行成本(Token 用量、预计耗时)',
      inputSchema: {
        type: 'object',
        properties: {
          task: {
            type: 'string',
            description: '要预估的任务描述',
          },
        },
        required: ['task'],
      },
    },
  • The input schema definition for the 'cost_estimate' tool, specifying an object with a required 'task' string property.
    inputSchema: {
      type: 'object',
      properties: {
        task: {
          type: 'string',
          description: '要预估的任务描述',
        },
      },
      required: ['task'],
    },

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/7836246/claude-team-mcp'

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