{"_id":"llm-cost","_rev":"4109595","name":"llm-cost","description":"[![Tests](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml/badge.svg)](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml) [![npm version](https://badge.fury.io/js/llm-cost.svg)](https://www.npmjs.com/package/ll","dist-tags":{"latest":"1.0.5"},"maintainers":[{"name":"rchaves","email":""}],"time":{"modified":"2026-02-01T17:23:30.000Z","created":"2023-11-25T07:29:49.433Z","1.0.5":"2024-07-19T09:55:35.321Z","1.0.4":"2024-05-24T12:31:34.099Z","1.0.3":"2024-02-23T10:35:08.231Z","1.0.2":"2023-12-13T22:17:31.226Z","1.0.1":"2023-11-25T07:44:28.867Z","1.0.0":"2023-11-25T07:29:49.433Z"},"users":{},"author":"","versions":{"1.0.5":{"name":"llm-cost","version":"1.0.5","description":"[![Tests](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml/badge.svg)](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml) [![npm version](https://badge.fury.io/js/llm-cost.svg)](https://www.npmjs.com/package/ll","main":"dist/src/index.js","scripts":{"test":"vitest","build":"tsc","prepublish":"npm run build"},"author":"","license":"MIT","types":"dist/src/index.d.ts","devDependencies":{"vitest":"^0.5.0","@types/node":"^16.0.0","@types/debug":"^4.1.12","typescript":"^4.0.0"},"dependencies":{"tiktoken":"^1.0.11"},"_id":"llm-cost@1.0.5","gitHead":"8cecc114d643c03528e13b8b1fa4e701e039aa4b","_nodeVersion":"20.15.1","_npmVersion":"10.7.0","dist":{"shasum":"4e17c54aedde2239591693882106fe99fb0da58f","size":19137,"noattachment":false,"key":"/llm-cost/-/llm-cost-1.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/llm-cost/download/llm-cost-1.0.5.tgz"},"_npmUser":{"name":"rchaves","email":"rogeriocfj+npm@gmail.com"},"directories":{},"maintainers":[{"name":"rchaves","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/llm-cost_1.0.5_1721382935029_0.3746569251310672"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-07-19T09:55:35.321Z","publish_time":1721382935321,"_source_registry_name":"default","_cnpm_publish_time":1721382935321},"1.0.4":{"name":"llm-cost","version":"1.0.4","description":"[![Tests](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml/badge.svg)](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml) [![npm version](https://badge.fury.io/js/llm-cost.svg)](https://www.npmjs.com/package/ll","main":"dist/src/index.js","scripts":{"test":"vitest","build":"tsc","prepublish":"npm run build"},"author":"","license":"MIT","types":"dist/src/index.d.ts","devDependencies":{"vitest":"^0.5.0","@types/node":"^16.0.0","@types/debug":"^4.1.12","typescript":"^4.0.0"},"dependencies":{"tiktoken":"^1.0.11"},"_id":"llm-cost@1.0.4","gitHead":"1a5baf1622f7e0a9024ac087e63d2e55a7d36e3c","_nodeVersion":"20.13.1","_npmVersion":"10.5.2","dist":{"shasum":"23f2dcf7c8041a69d05a6f2c35305217df602d69","size":16553,"noattachment":false,"key":"/llm-cost/-/llm-cost-1.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/llm-cost/download/llm-cost-1.0.4.tgz"},"_npmUser":{"name":"rchaves","email":"rogeriocfj+npm@gmail.com"},"directories":{},"maintainers":[{"name":"rchaves","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/llm-cost_1.0.4_1716553893896_0.44369187115899633"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-05-24T12:31:34.099Z","publish_time":1716553894099,"_source_registry_name":"default","_cnpm_publish_time":1716553894099},"1.0.3":{"name":"llm-cost","version":"1.0.3","description":"[![Tests](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml/badge.svg)](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml) [![npm version](https://badge.fury.io/js/llm-cost.svg)](https://www.npmjs.com/package/ll","main":"dist/src/index.js","scripts":{"test":"vitest","build":"tsc","prepublish":"npm run build"},"author":"","license":"MIT","types":"dist/src/index.d.ts","devDependencies":{"vitest":"^0.5.0","@types/node":"^16.0.0","@types/debug":"^4.1.12","typescript":"^4.0.0"},"dependencies":{"tiktoken":"^1.0.11"},"_id":"llm-cost@1.0.3","gitHead":"289b608a0fd82c84a23f176e8093848bc0097d1e","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"shasum":"deb9df902c400bba034b3bfce9ab35dbc55ec8eb","size":11041,"noattachment":false,"key":"/llm-cost/-/llm-cost-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/llm-cost/download/llm-cost-1.0.3.tgz"},"_npmUser":{"name":"rchaves","email":"rogeriocfj+npm@gmail.com"},"directories":{},"maintainers":[{"name":"rchaves","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/llm-cost_1.0.3_1708684508039_0.1585498446491631"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-02-23T10:35:08.231Z","publish_time":1708684508231,"_source_registry_name":"default","_cnpm_publish_time":1708684508231},"1.0.2":{"name":"llm-cost","version":"1.0.2","description":"[![Tests](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml/badge.svg)](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml) [![npm version](https://badge.fury.io/js/llm-cost.svg)](https://www.npmjs.com/package/ll","main":"dist/src/index.js","scripts":{"test":"vitest","build":"tsc","prepublish":"npm run build"},"author":"","license":"MIT","types":"dist/src/index.d.ts","devDependencies":{"vitest":"^0.5.0","@types/node":"^16.0.0","@types/debug":"^4.1.12","typescript":"^4.0.0"},"dependencies":{"tiktoken":"^1.0.11"},"_id":"llm-cost@1.0.2","gitHead":"1c6127b26cbd592f18a7577f4448a23542b24d9e","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"shasum":"ad5d57fc2ffa3e3c32871313933b252438b8849f","size":6865,"noattachment":false,"key":"/llm-cost/-/llm-cost-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/llm-cost/download/llm-cost-1.0.2.tgz"},"_npmUser":{"name":"rchaves","email":"rogeriocfj+npm@gmail.com"},"directories":{},"maintainers":[{"name":"rchaves","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/llm-cost_1.0.2_1702505851054_0.23969633327371165"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-12-13T22:17:31.226Z","publish_time":1702505851226,"_source_registry_name":"default","_cnpm_publish_time":1702505851226},"1.0.1":{"name":"llm-cost","version":"1.0.1","description":"[![Tests](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml/badge.svg)](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml) [![npm version](https://badge.fury.io/js/llm-cost.svg)](https://www.npmjs.com/package/ll","main":"dist/src/index.js","scripts":{"test":"vitest","build":"tsc","prepublish":"npm run build"},"author":"","license":"MIT","types":"dist/src/index.d.ts","devDependencies":{"vitest":"^0.5.0","@types/node":"^16.0.0","@types/debug":"^4.1.12","typescript":"^4.0.0"},"dependencies":{"tiktoken":"^1.0.11"},"_id":"llm-cost@1.0.1","gitHead":"f76eca3f9902067b756ea554c8ab538590985d94","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"shasum":"c9a621c445735e99a79e4f9d1377370b826c4e06","size":6796,"noattachment":false,"key":"/llm-cost/-/llm-cost-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/llm-cost/download/llm-cost-1.0.1.tgz"},"_npmUser":{"name":"rchaves","email":"rogeriocfj+npm@gmail.com"},"directories":{},"maintainers":[{"name":"rchaves","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/llm-cost_1.0.1_1700898268696_0.4065514325792867"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-25T07:44:28.867Z","publish_time":1700898268867,"_source_registry_name":"default","_cnpm_publish_time":1700898268867},"1.0.0":{"name":"llm-cost","version":"1.0.0","description":"`llm-cost` is a utility library for counting tokens and estimating the cost of LLMs from various providers such as OpenAI, Anthropic, Cohere, and more.","main":"dist/src/index.js","scripts":{"test":"vitest","build":"tsc","prepublish":"npm run build"},"author":"","license":"MIT","types":"dist/index.d.ts","devDependencies":{"vitest":"^0.5.0","@types/node":"^16.0.0","@types/debug":"^4.1.12","typescript":"^4.0.0"},"dependencies":{"tiktoken":"^1.0.11"},"_id":"llm-cost@1.0.0","gitHead":"9491afcd049103738594d8eda8d77f612da60c9d","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"shasum":"8339c49d2c2e4e3beec1d18be7393d4445d8a19b","size":6706,"noattachment":false,"key":"/llm-cost/-/llm-cost-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/llm-cost/download/llm-cost-1.0.0.tgz"},"_npmUser":{"name":"rchaves","email":"rogeriocfj+npm@gmail.com"},"directories":{},"maintainers":[{"name":"rchaves","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/llm-cost_1.0.0_1700897389225_0.34975680911305673"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-25T07:29:49.433Z","publish_time":1700897389433,"_source_registry_name":"default","_cnpm_publish_time":1700897389433}},"readme":"# llm-cost\n\n[![Tests](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml/badge.svg)](https://github.com/rogeriochaves/llm-cost/actions/workflows/node.js.yml)\n[![npm version](https://badge.fury.io/js/llm-cost.svg)](https://www.npmjs.com/package/llm-cost)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rogeriochaves/llm-cost/blob/master/LICENSE)\n\n`llm-cost` is a utility library for counting tokens and estimating the cost of LLMs from various providers such as OpenAI, Anthropic, Cohere, and more.\n\n## Features\n\n- **Token Counting**: Accurately count the number of tokens for a given input or output text.\n- **Cost Estimation**: Estimate the cost of using an LLM based on the token count and the specific model's pricing.\n\n## Installation\n\n```bash\nnpm install llm-cost\n```\n\n## Usage\n\n### `tokenizeAndEstimateCost`\n\nThis function takes the model name, input text, and output text. It returns a promise that resolves to an object with the number of input tokens, output tokens, and the estimated cost.\nPlease note that when calling `tokenizeAndEstimateCost` for the first time with a specific model, it will load the tokenizer for that model and cache it in memory. This means that the first call may be slower, but subsequent calls will be faster due to the tokenizer being cached.\n\n```typescript\nimport { tokenizeAndEstimateCost } from \"llm-cost\";\n\nasync function main() {\n  const result = await tokenizeAndEstimateCost({\n    model: \"gpt-4\",\n    input: \"Hello, world!\",\n    output: \"Hi there, how are you?\",\n  });\n\n  console.log(result);\n  // Output: { inputTokens: 4, outputTokens: 7, cost: 0.00054 }\n}\n\nmain();\n```\n\n### `estimateCost`\n\nThis function estimates the cost of using an LLM based on the number of input and output tokens, if you already have them. It takes an object with the model name, input token count, and output token count, returning the estimated cost.\n\n```typescript\nimport { estimateCost } from \"llm-cost\";\n\nconst cost = estimateCost({\n  model: \"gpt-4\",\n  inputTokens: 3000,\n  outputTokens: 2100,\n});\n\nconsole.log(cost);\n// Output: 0.216\n```\n\n## Contributing\n\nWe are actively seeking contributions to expand the tokenizer support for various LLM providers. Currently, the library supports tokenizers for OpenAI models. If you have expertise in other LLMs tokenizers please submit a pull-request!\n\nFor any bugs or suggestions to the library, please open an issue at [llm-cost issues](https://github.com/rogeriochaves/llm-cost/issues/new).\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","_attachments":{},"license":"MIT"}