{
  "schemaVersion": 1,
  "slug": "ai-token-cost-calculator",
  "category": "productivity",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "87869105ca876b8776d3ce03f2e51f17ad10e8761d0997d48b29e7737503b120",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/ai-token-cost-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "C = (t_i × p_i + t_o × p_o) ÷ 1000000 × n",
    "vars": [
      [
        "C",
        "total cost"
      ],
      [
        "t_i",
        "input tokens"
      ],
      [
        "p_i",
        "input price per 1M tokens"
      ],
      [
        "t_o",
        "output tokens"
      ],
      [
        "p_o",
        "output price per 1M tokens"
      ],
      [
        "n",
        "number of requests"
      ]
    ],
    "note": "Prices are quoted per 1,000,000 tokens; n is floored to whole requests."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const it = Math.max(0, Number(inputTokens));\nconst ot = Math.max(0, Number(outputTokens));\nconst ip = Math.max(0, Number(inputPrice));\nconst op = Math.max(0, Number(outputPrice));\nconst n = Math.max(0, Math.floor(Number(requests)));\nconst perRequest = (it * ip + ot * op) / 1000000;\nreturn {\n  costPerRequest: perRequest,\n  totalCost: perRequest * n,\n  totalTokens: (it + ot) * n,\n};",
    "inputs": [
      {
        "name": "inputTokens",
        "type": "number",
        "default": 1500,
        "min": 0,
        "step": 1
      },
      {
        "name": "outputTokens",
        "type": "number",
        "default": 500,
        "min": 0,
        "step": 1
      },
      {
        "name": "inputPrice",
        "type": "number",
        "default": 3,
        "min": 0,
        "step": 0.01
      },
      {
        "name": "outputPrice",
        "type": "number",
        "default": 15,
        "min": 0,
        "step": 0.01
      },
      {
        "name": "requests",
        "type": "number",
        "default": 1000,
        "min": 0,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "costPerRequest",
        "precision": 6,
        "unit": "$"
      },
      {
        "name": "totalCost",
        "precision": 4,
        "unit": "$"
      },
      {
        "name": "totalTokens",
        "precision": 0,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
