{
  "schemaVersion": "1.0",
  "item": {
    "slug": "token-cost-estimator",
    "name": "Token Cost Estimator",
    "source": "tencent",
    "type": "skill",
    "category": "开发工具",
    "sourceUrl": "https://clawhub.ai/npfaerber/token-cost-estimator",
    "canonicalUrl": "https://clawhub.ai/npfaerber/token-cost-estimator",
    "targetPlatform": "OpenClaw"
  },
  "install": {
    "downloadMode": "redirect",
    "downloadUrl": "/downloads/token-cost-estimator",
    "sourceDownloadUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=token-cost-estimator",
    "sourcePlatform": "tencent",
    "targetPlatform": "OpenClaw",
    "installMethod": "Manual import",
    "extraction": "Extract archive",
    "prerequisites": [
      "OpenClaw"
    ],
    "packageFormat": "ZIP package",
    "includedAssets": [
      "SKILL.md"
    ],
    "primaryDoc": "SKILL.md",
    "quickSetup": [
      "Download the package from Yavira.",
      "Extract the archive and review SKILL.md first.",
      "Import or place the package into your OpenClaw setup."
    ],
    "agentAssist": {
      "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
      "steps": [
        "Download the package from Yavira.",
        "Extract it into a folder your agent can access.",
        "Paste one of the prompts below and point your agent at the extracted folder."
      ],
      "prompts": [
        {
          "label": "New install",
          "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
        },
        {
          "label": "Upgrade existing",
          "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
        }
      ]
    },
    "sourceHealth": {
      "source": "tencent",
      "status": "healthy",
      "reason": "direct_download_ok",
      "recommendedAction": "download",
      "checkedAt": "2026-05-07T17:22:31.273Z",
      "expiresAt": "2026-05-14T17:22:31.273Z",
      "httpStatus": 200,
      "finalUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=afrexai-annual-report",
      "contentType": "application/zip",
      "probeMethod": "head",
      "details": {
        "probeUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=afrexai-annual-report",
        "contentDisposition": "attachment; filename=\"afrexai-annual-report-1.0.0.zip\"",
        "redirectLocation": null,
        "bodySnippet": null
      },
      "scope": "source",
      "summary": "Source download looks usable.",
      "detail": "Yavira can redirect you to the upstream package for this source.",
      "primaryActionLabel": "Download for OpenClaw",
      "primaryActionHref": "/downloads/token-cost-estimator"
    },
    "validation": {
      "installChecklist": [
        "Use the Yavira download entry.",
        "Review SKILL.md after the package is downloaded.",
        "Confirm the extracted package contains the expected setup assets."
      ],
      "postInstallChecks": [
        "Confirm the extracted package includes the expected docs or setup files.",
        "Validate the skill or prompts are available in your target agent workspace.",
        "Capture any manual follow-up steps the agent could not complete."
      ]
    },
    "downloadPageUrl": "https://openagent3.xyz/downloads/token-cost-estimator",
    "agentPageUrl": "https://openagent3.xyz/skills/token-cost-estimator/agent",
    "manifestUrl": "https://openagent3.xyz/skills/token-cost-estimator/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/token-cost-estimator/agent.md"
  },
  "agentAssist": {
    "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
    "steps": [
      "Download the package from Yavira.",
      "Extract it into a folder your agent can access.",
      "Paste one of the prompts below and point your agent at the extracted folder."
    ],
    "prompts": [
      {
        "label": "New install",
        "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
      },
      {
        "label": "Upgrade existing",
        "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
      }
    ]
  },
  "documentation": {
    "source": "clawhub",
    "primaryDoc": "SKILL.md",
    "sections": [
      {
        "title": "Token Cost Estimator",
        "body": "Estimate real API costs from OpenClaw session transcript data."
      },
      {
        "title": "How It Works",
        "body": "OpenClaw stores session transcripts as JSONL files in ~/.openclaw/agents/<agent>/sessions/*.jsonl. Each line is a turn with role, content, and sometimes usage data."
      },
      {
        "title": "Estimation Script",
        "body": "Run this Python script to analyze all agents:\n\nimport json, glob, os\n\nAGENTS_DIR = os.path.expanduser('~/.openclaw/agents')\n# Pricing per million tokens (update as needed)\nPRICING = {\n    'opus': {'input': 15, 'output': 75, 'cache_read': 1.875},\n    'sonnet': {'input': 3, 'output': 15, 'cache_read': 0.375},\n}\n\nagent_dirs = [d for d in os.listdir(AGENTS_DIR) if os.path.isdir(os.path.join(AGENTS_DIR, d))]\ngrand_in, grand_out = 0, 0\n\nfor agent in sorted(agent_dirs):\n    sess_dir = os.path.join(AGENTS_DIR, agent, 'sessions')\n    if not os.path.isdir(sess_dir):\n        continue\n    total_in, total_out, sessions = 0, 0, 0\n    for f in glob.glob(os.path.join(sess_dir, '*.jsonl')):\n        sessions += 1\n        turns = []\n        for line in open(f):\n            try:\n                obj = json.loads(line)\n                msg = obj.get('message', {})\n                if not isinstance(msg, dict): continue\n                role = msg.get('role', '')\n                raw = json.dumps(msg)\n                turns.append((role, len(raw)))\n            except: pass\n        # Account for context re-sending\n        cumulative = 0\n        for role, chars in turns:\n            if role in ('user', 'system', 'tool'):\n                cumulative += chars\n            elif role == 'assistant':\n                total_in += cumulative // 4\n                total_out += chars // 4\n    print(f'{agent}: {sessions} sessions, ~{total_in:,} input, ~{total_out:,} output tokens')\n    grand_in += total_in\n    grand_out += total_out\n\nprint(f'\\nTotal input: ~{grand_in:,}, output: ~{grand_out:,}')\nfor tier, rates in PRICING.items():\n    for cache_pct in [0.6, 0.9]:\n        cached = int(grand_in * cache_pct)\n        uncached = grand_in - cached\n        cost = (uncached/1e6)*rates['input'] + (cached/1e6)*rates['cache_read'] + (grand_out/1e6)*rates['output']\n        print(f'{tier} ({int(cache_pct*100)}% cache): ${cost:,.2f}')"
      },
      {
        "title": "Key Concepts",
        "body": "Context re-sending: Every API call sends the full conversation history as input. A 50-turn conversation re-sends all prior turns on each new message. This is the #1 cost driver.\n\nCache hits: OpenClaw caches prompt prefixes. Typical cache hit rates: 60-90%. Cache reads cost 87.5% less than fresh input.\n\nWhat transcripts miss: System prompts, tool definitions, and internal retries aren't always logged. Real cost is typically 1.5-2x the transcript estimate."
      },
      {
        "title": "Comparing Plans",
        "body": "PlanMonthly CostBest ForAPI (Opus)VariableHeavy agentic use (>$200/mo equivalent)API (Sonnet)VariableMost agent tasks, 5x cheaper than OpusClaude Max ($100)$100 flatLight-medium use via OAuth (if allowed)Claude Max ($200)$200 flatHeavy use via OAuth (if allowed)\n\nBreak-even: If your estimated API cost exceeds your subscription price, the subscription saves money. Note: Anthropic has restricted OAuth token use in third-party tools."
      }
    ],
    "body": "Token Cost Estimator\n\nEstimate real API costs from OpenClaw session transcript data.\n\nHow It Works\n\nOpenClaw stores session transcripts as JSONL files in ~/.openclaw/agents/<agent>/sessions/*.jsonl. Each line is a turn with role, content, and sometimes usage data.\n\nEstimation Script\n\nRun this Python script to analyze all agents:\n\nimport json, glob, os\n\nAGENTS_DIR = os.path.expanduser('~/.openclaw/agents')\n# Pricing per million tokens (update as needed)\nPRICING = {\n    'opus': {'input': 15, 'output': 75, 'cache_read': 1.875},\n    'sonnet': {'input': 3, 'output': 15, 'cache_read': 0.375},\n}\n\nagent_dirs = [d for d in os.listdir(AGENTS_DIR) if os.path.isdir(os.path.join(AGENTS_DIR, d))]\ngrand_in, grand_out = 0, 0\n\nfor agent in sorted(agent_dirs):\n    sess_dir = os.path.join(AGENTS_DIR, agent, 'sessions')\n    if not os.path.isdir(sess_dir):\n        continue\n    total_in, total_out, sessions = 0, 0, 0\n    for f in glob.glob(os.path.join(sess_dir, '*.jsonl')):\n        sessions += 1\n        turns = []\n        for line in open(f):\n            try:\n                obj = json.loads(line)\n                msg = obj.get('message', {})\n                if not isinstance(msg, dict): continue\n                role = msg.get('role', '')\n                raw = json.dumps(msg)\n                turns.append((role, len(raw)))\n            except: pass\n        # Account for context re-sending\n        cumulative = 0\n        for role, chars in turns:\n            if role in ('user', 'system', 'tool'):\n                cumulative += chars\n            elif role == 'assistant':\n                total_in += cumulative // 4\n                total_out += chars // 4\n    print(f'{agent}: {sessions} sessions, ~{total_in:,} input, ~{total_out:,} output tokens')\n    grand_in += total_in\n    grand_out += total_out\n\nprint(f'\\nTotal input: ~{grand_in:,}, output: ~{grand_out:,}')\nfor tier, rates in PRICING.items():\n    for cache_pct in [0.6, 0.9]:\n        cached = int(grand_in * cache_pct)\n        uncached = grand_in - cached\n        cost = (uncached/1e6)*rates['input'] + (cached/1e6)*rates['cache_read'] + (grand_out/1e6)*rates['output']\n        print(f'{tier} ({int(cache_pct*100)}% cache): ${cost:,.2f}')\n\nKey Concepts\n\nContext re-sending: Every API call sends the full conversation history as input. A 50-turn conversation re-sends all prior turns on each new message. This is the #1 cost driver.\n\nCache hits: OpenClaw caches prompt prefixes. Typical cache hit rates: 60-90%. Cache reads cost 87.5% less than fresh input.\n\nWhat transcripts miss: System prompts, tool definitions, and internal retries aren't always logged. Real cost is typically 1.5-2x the transcript estimate.\n\nComparing Plans\nPlan\tMonthly Cost\tBest For\nAPI (Opus)\tVariable\tHeavy agentic use (>$200/mo equivalent)\nAPI (Sonnet)\tVariable\tMost agent tasks, 5x cheaper than Opus\nClaude Max ($100)\t$100 flat\tLight-medium use via OAuth (if allowed)\nClaude Max ($200)\t$200 flat\tHeavy use via OAuth (if allowed)\n\nBreak-even: If your estimated API cost exceeds your subscription price, the subscription saves money. Note: Anthropic has restricted OAuth token use in third-party tools."
  },
  "trust": {
    "sourceLabel": "tencent",
    "provenanceUrl": "https://clawhub.ai/npfaerber/token-cost-estimator",
    "publisherUrl": "https://clawhub.ai/npfaerber/token-cost-estimator",
    "owner": "npfaerber",
    "version": "1.0.1",
    "license": null,
    "verificationStatus": "Indexed source record"
  },
  "links": {
    "detailUrl": "https://openagent3.xyz/skills/token-cost-estimator",
    "downloadUrl": "https://openagent3.xyz/downloads/token-cost-estimator",
    "agentUrl": "https://openagent3.xyz/skills/token-cost-estimator/agent",
    "manifestUrl": "https://openagent3.xyz/skills/token-cost-estimator/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/token-cost-estimator/agent.md"
  }
}