{"slug": "catch-runaway-ai-agent-costs-before-merge-with-a-github-action", "title": "Catch runaway AI agent costs before merge with a GitHub Action", "summary": "A developer released AICostFence, an open-source GitHub Action that scans JavaScript/TypeScript projects using the Vercel AI SDK for missing output-token ceilings and unbounded tool loops before a pull request is merged. The tool estimates monthly cost per call site from repository-stored traffic assumptions and can fail a check when configured cost or unbounded-tool guards are violated, running locally on the GitHub runner without calling an AI model or sending source code to a provider.", "body_md": "AI cost control usually begins after deployment: a provider dashboard reports what has already been spent. But several expensive failure modes are visible in code before a pull request is merged.\n\nConsider a tool-using Vercel AI SDK call:\n\n```\nreturn streamText({\n  model: openai(\"gpt-5.4-mini\"),\n  prompt: question,\n  tools: { search }\n});\n```\n\nTwo limits are missing. There is no output-token ceiling, and the tool loop has no stopping condition. Even if the prompt looks harmless, neither the worst-case response size nor the maximum number of steps is explicit.\n\nA bounded version makes both decisions reviewable:\n\n```\nreturn streamText({\n  model: openai(\"gpt-5.4-mini\"),\n  prompt: question,\n  maxOutputTokens: 800,\n  stopWhen: stepCountIs(5),\n  tools: { search }\n});\n```\n\nCode alone cannot predict a bill. A useful estimate also needs traffic assumptions. Keep those assumptions in the repository so reviewers can challenge them:\n\n```\n{\n  \"monthlyCallsPerSite\": 10000,\n  \"assumedInputTokens\": 1000,\n  \"assumedOutputTokens\": 1000,\n  \"warnMonthlyCost\": 50,\n  \"failMonthlyCost\": 250,\n  \"failOnUnboundedTools\": true\n}\n```\n\nThen estimate each call site with a deliberately simple formula:\n\n```\nmonthly cost = monthly calls ×\n  ((input tokens × input price) + (maximum output tokens × output price))\n```\n\nThe estimate is not an invoice prediction. It is a consistent review signal. A changed model, increased output ceiling, or new call site produces a visible change before production.\n\nI built an open-source Action called AICostFence to automate this check:\n\n```\nname: AI cost check\non: pull_request\n\npermissions:\n  contents: read\n  pull-requests: write\n\njobs:\n  cost-check:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: ronnie0297-stack/aicostfence@v0.1.0\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n```\n\nIt scans locally on the GitHub runner, posts one updated pull-request report, and can fail the check when a configured guard is violated. It does not call an AI model or send source code to a model provider.\n\nThe current release intentionally supports a narrow surface: JavaScript/TypeScript projects using the Vercel AI SDK's `generateText`, `streamText`, `generateObject`, or `streamObject` calls. That makes the analysis deterministic while the early workflow is validated.\n\nRepository: [https://github.com/ronnie0297-stack/aicostfence](https://github.com/ronnie0297-stack/aicostfence)\n\nMarketplace: [https://github.com/marketplace/actions/aicostfence](https://github.com/marketplace/actions/aicostfence)\n\nnpm: [https://www.npmjs.com/package/aicostfence](https://www.npmjs.com/package/aicostfence)\n\nWhat cost control would be most useful in your pull requests: model-swap deltas, provider-specific checks, or organization-wide policies?", "url": "https://wpnews.pro/news/catch-runaway-ai-agent-costs-before-merge-with-a-github-action", "canonical_source": "https://dev.to/ronnie0297-stack/catch-runaway-ai-agent-costs-before-merge-with-a-github-action-3h1k", "published_at": "2026-09-21 15:10:20+00:00", "updated_at": "2026-09-21 15:25:36.566949+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools", "mlops"], "entities": ["AICostFence", "GitHub", "Vercel AI SDK", "OpenAI", "npm", "GitHub Marketplace"], "alternates": {"html": "https://wpnews.pro/news/catch-runaway-ai-agent-costs-before-merge-with-a-github-action", "markdown": "https://wpnews.pro/news/catch-runaway-ai-agent-costs-before-merge-with-a-github-action.md", "text": "https://wpnews.pro/news/catch-runaway-ai-agent-costs-before-merge-with-a-github-action.txt", "jsonld": "https://wpnews.pro/news/catch-runaway-ai-agent-costs-before-merge-with-a-github-action.jsonld"}}