{
  "schemaVersion": "1.0",
  "item": {
    "slug": "token-guard",
    "name": "Token Guard",
    "source": "tencent",
    "type": "skill",
    "category": "开发工具",
    "sourceUrl": "https://clawhub.ai/edmonddantesj/token-guard",
    "canonicalUrl": "https://clawhub.ai/edmonddantesj/token-guard",
    "targetPlatform": "OpenClaw"
  },
  "install": {
    "downloadMode": "redirect",
    "downloadUrl": "/downloads/token-guard",
    "sourceDownloadUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=token-guard",
    "sourcePlatform": "tencent",
    "targetPlatform": "OpenClaw",
    "installMethod": "Manual import",
    "extraction": "Extract archive",
    "prerequisites": [
      "OpenClaw"
    ],
    "packageFormat": "ZIP package",
    "includedAssets": [
      "SKILL.md",
      "scripts/token_guard.py"
    ],
    "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-guard"
    },
    "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-guard",
    "agentPageUrl": "https://openagent3.xyz/skills/token-guard/agent",
    "manifestUrl": "https://openagent3.xyz/skills/token-guard/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/token-guard/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": "TokenGuard — LLM API 429 Prevention Engine",
        "body": "Version: 1.5.0\nAuthor: Aoineco & Co.\nLicense: MIT\nTags: rate-limit, 429, token-management, cost-optimization, llm-guard, high-performance"
      },
      {
        "title": "Description",
        "body": "Prevents LLM API 429 (Rate Limit / Resource Exhausted) errors by intercepting requests before they're sent. Designed for users on free/low-cost API plans who need maximum intelligence per dollar.\n\nCore philosophy: \"Intelligence is measured not by how much you spend, but by how little you need.\""
      },
      {
        "title": "Problem",
        "body": "When using LLM APIs (especially Google Gemini Flash with 1M TPM limit):\n\nLarge documents (docx, PDFs) can consume the entire minute quota in one request\nFailed requests still count toward token usage\nRetry loops after 429 errors waste more tokens → death spiral\nNo built-in way to detect runaway/duplicate requests"
      },
      {
        "title": "Features",
        "body": "FeatureDescriptionPre-flight Token EstimationEstimates token count before API call (CJK-aware, no tiktoken dependency)Real-time Quota TrackingTracks per-model per-minute token usage with sliding windowSmart ThrottleAuto-waits when quota > 80%, blocks at > 95%Duplicate DetectionBlocks identical requests within 60s window (3+ = runaway)Response CachingCaches successful responses for duplicate requestsAuto Model FallbackSwitches to cheaper/available model when primary is exhausted429 Error ParserExtracts exact retry delay from Google/Anthropic error responsesBatch vs Mistake DetectionDistinguishes intentional bulk processing from error loops"
      },
      {
        "title": "Supported Models",
        "body": "Pre-configured quotas for:\n\ngemini-3-flash (1M TPM)\ngemini-3-pro (2M TPM)\nclaude-haiku (50K TPM)\nclaude-sonnet (200K TPM)\nclaude-opus (200K TPM)\ngpt-4o (800K TPM)\ndeepseek (1M TPM)\n\nCustom quotas can be added for any model."
      },
      {
        "title": "Usage",
        "body": "from token_guard import TokenGuard\n\nguard = TokenGuard()\n\n# Before every API call:\ndecision = guard.check(prompt_text, model=\"gemini-3-flash\")\n\nif decision.action == \"proceed\":\n    response = call_your_api(prompt_text)\n    guard.record_usage(decision.estimated_tokens, model=\"gemini-3-flash\")\n    guard.cache_response(prompt_text, response)\n\nelif decision.action == \"wait\":\n    time.sleep(decision.wait_seconds)\n    # retry\n\nelif decision.action == \"fallback\":\n    response = call_your_api(prompt_text, model=decision.fallback_model)\n\nelif decision.action == \"block\":\n    print(f\"Blocked: {decision.reason}\")\n\n# If you get a 429 error:\nguard.record_429(\"gemini-3-flash\", retry_delay=53.0)"
      },
      {
        "title": "Integration with OpenClaw",
        "body": "Add to your agent's config or use as a middleware:\n\nskills:\n  - token-guard\n\nThe agent can invoke TokenGuard before any LLM API call to prevent quota exhaustion."
      },
      {
        "title": "File Structure",
        "body": "token-guard/\n├── SKILL.md          # This file\n└── scripts/\n    └── token_guard.py  # Main engine (zero external dependencies)"
      },
      {
        "title": "Status Output Example",
        "body": "{\n  \"models\": {\n    \"gemini-3-flash\": {\n      \"tpm_limit\": 1000000,\n      \"used_this_minute\": 750000,\n      \"remaining\": 250000,\n      \"usage_pct\": \"75.0%\",\n      \"status\": \"🟢 OK\"\n    }\n  },\n  \"stats\": {\n    \"total_checks\": 42,\n    \"tokens_saved\": 128000,\n    \"blocks\": 3,\n    \"fallbacks\": 2\n  }\n}"
      },
      {
        "title": "Zero Dependencies",
        "body": "Pure Python 3.10+. No pip install needed. No tiktoken, no external API calls.\nDesigned for the $7 Bootstrap Protocol — every byte counts."
      }
    ],
    "body": "TokenGuard — LLM API 429 Prevention Engine\n<!-- 🌌 Aoineco-Verified | S-DNA: AOI-2026-0213-SDNA-TG01 -->\n\nVersion: 1.5.0\nAuthor: Aoineco & Co.\nLicense: MIT\nTags: rate-limit, 429, token-management, cost-optimization, llm-guard, high-performance\n\nDescription\n\nPrevents LLM API 429 (Rate Limit / Resource Exhausted) errors by intercepting requests before they're sent. Designed for users on free/low-cost API plans who need maximum intelligence per dollar.\n\nCore philosophy: \"Intelligence is measured not by how much you spend, but by how little you need.\"\n\nProblem\n\nWhen using LLM APIs (especially Google Gemini Flash with 1M TPM limit):\n\nLarge documents (docx, PDFs) can consume the entire minute quota in one request\nFailed requests still count toward token usage\nRetry loops after 429 errors waste more tokens → death spiral\nNo built-in way to detect runaway/duplicate requests\nFeatures\nFeature\tDescription\nPre-flight Token Estimation\tEstimates token count before API call (CJK-aware, no tiktoken dependency)\nReal-time Quota Tracking\tTracks per-model per-minute token usage with sliding window\nSmart Throttle\tAuto-waits when quota > 80%, blocks at > 95%\nDuplicate Detection\tBlocks identical requests within 60s window (3+ = runaway)\nResponse Caching\tCaches successful responses for duplicate requests\nAuto Model Fallback\tSwitches to cheaper/available model when primary is exhausted\n429 Error Parser\tExtracts exact retry delay from Google/Anthropic error responses\nBatch vs Mistake Detection\tDistinguishes intentional bulk processing from error loops\nSupported Models\n\nPre-configured quotas for:\n\ngemini-3-flash (1M TPM)\ngemini-3-pro (2M TPM)\nclaude-haiku (50K TPM)\nclaude-sonnet (200K TPM)\nclaude-opus (200K TPM)\ngpt-4o (800K TPM)\ndeepseek (1M TPM)\n\nCustom quotas can be added for any model.\n\nUsage\nfrom token_guard import TokenGuard\n\nguard = TokenGuard()\n\n# Before every API call:\ndecision = guard.check(prompt_text, model=\"gemini-3-flash\")\n\nif decision.action == \"proceed\":\n    response = call_your_api(prompt_text)\n    guard.record_usage(decision.estimated_tokens, model=\"gemini-3-flash\")\n    guard.cache_response(prompt_text, response)\n\nelif decision.action == \"wait\":\n    time.sleep(decision.wait_seconds)\n    # retry\n\nelif decision.action == \"fallback\":\n    response = call_your_api(prompt_text, model=decision.fallback_model)\n\nelif decision.action == \"block\":\n    print(f\"Blocked: {decision.reason}\")\n\n# If you get a 429 error:\nguard.record_429(\"gemini-3-flash\", retry_delay=53.0)\n\nIntegration with OpenClaw\n\nAdd to your agent's config or use as a middleware:\n\nskills:\n  - token-guard\n\n\nThe agent can invoke TokenGuard before any LLM API call to prevent quota exhaustion.\n\nFile Structure\ntoken-guard/\n├── SKILL.md          # This file\n└── scripts/\n    └── token_guard.py  # Main engine (zero external dependencies)\n\nStatus Output Example\n{\n  \"models\": {\n    \"gemini-3-flash\": {\n      \"tpm_limit\": 1000000,\n      \"used_this_minute\": 750000,\n      \"remaining\": 250000,\n      \"usage_pct\": \"75.0%\",\n      \"status\": \"🟢 OK\"\n    }\n  },\n  \"stats\": {\n    \"total_checks\": 42,\n    \"tokens_saved\": 128000,\n    \"blocks\": 3,\n    \"fallbacks\": 2\n  }\n}\n\nZero Dependencies\n\nPure Python 3.10+. No pip install needed. No tiktoken, no external API calls. Designed for the $7 Bootstrap Protocol — every byte counts."
  },
  "trust": {
    "sourceLabel": "tencent",
    "provenanceUrl": "https://clawhub.ai/edmonddantesj/token-guard",
    "publisherUrl": "https://clawhub.ai/edmonddantesj/token-guard",
    "owner": "edmonddantesj",
    "version": "1.5.0",
    "license": null,
    "verificationStatus": "Indexed source record"
  },
  "links": {
    "detailUrl": "https://openagent3.xyz/skills/token-guard",
    "downloadUrl": "https://openagent3.xyz/downloads/token-guard",
    "agentUrl": "https://openagent3.xyz/skills/token-guard/agent",
    "manifestUrl": "https://openagent3.xyz/skills/token-guard/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/token-guard/agent.md"
  }
}