{"_id":"@calcis/llamaindex","_rev":"4-bb6d46bb531c5226ae0e624b7a75eb2c","name":"@calcis/llamaindex","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0":{"name":"@calcis/llamaindex","version":"1.0.0","keywords":["calcis","llamaindex","llm","cost","estimation"],"license":"MIT","_id":"@calcis/llamaindex@1.0.0","maintainers":[{"name":"calcis","email":"calcis.dev@gmail.com"}],"homepage":"https://www.calcis.dev","bugs":{"url":"https://github.com/rc397/Calcis/issues"},"dist":{"shasum":"dc46eb4517afc6785a503dcf16d2bda08ee6aed6","tarball":"https://registry.npmjs.org/@calcis/llamaindex/-/llamaindex-1.0.0.tgz","fileCount":7,"integrity":"sha512-06dsD+ODwDteqOEUvbZ/q9CRLCmIMA5dqQ46XNSYtO0Kwnha0LUlJUToUoO2M6c9fq8SNrq0TaE/+9NxGSnBfg==","signatures":[{"sig":"MEUCIA8c+Z3L79whRA0VttJlaSD5zDRqR0MmWbZ3VQQZwsV4AiEAyK0fC3nZxF6HTi7CkbblYkTT2P/AjEZ3SW1j3wDtA+4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14959},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"ef75cec281a791905f837f7167fde6606d93c92f","scripts":{"build":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"calcis","email":"calcis.dev@gmail.com"},"repository":{"url":"git+https://github.com/rc397/Calcis.git","type":"git"},"_npmVersion":"11.4.2","description":"Calcis cost estimation callback for LlamaIndex","directories":{},"_nodeVersion":"24.4.1","_hasShrinkwrap":false,"devDependencies":{"llamaindex":"^0.8.0","typescript":"^5.0.0","@types/node":"^20.0.0"},"peerDependencies":{"llamaindex":">=0.5.0"},"_npmOperationalInternal":{"tmp":"tmp/llamaindex_1.0.0_1776596525501_0.8543397706960472","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@calcis/llamaindex","version":"1.0.1","keywords":["calcis","llamaindex","llm","cost","estimation"],"license":"MIT","_id":"@calcis/llamaindex@1.0.1","maintainers":[{"name":"calcis","email":"calcis.dev@gmail.com"}],"homepage":"https://www.calcis.dev","bugs":{"url":"https://github.com/rc397/Calcis/issues"},"dist":{"shasum":"a9f5b7bf05101662dc76a87693df4268feb0bf16","tarball":"https://registry.npmjs.org/@calcis/llamaindex/-/llamaindex-1.0.1.tgz","fileCount":7,"integrity":"sha512-6/r/69WoYC6Vxc3fzupYQ3exQ3e7OSJdVPRzENwt536Fyd+JtvMbDAbEX1r4IT3zszCWow/IqKW2fe139zAT5w==","signatures":[{"sig":"MEUCIQC/cU7Yh6XFeFN0mzATGqmpSmFbLV7TCYmOGZFmQPX+0wIgEoSYha4U13U0SFBneZVNgl6dHw7y8FsT69vit5fJnus=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15565},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"2ac0279a067083da14424b97edaf969cbc69b3c8","scripts":{"build":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"calcis","email":"calcis.dev@gmail.com"},"repository":{"url":"git+https://github.com/rc397/Calcis.git","type":"git"},"_npmVersion":"11.4.2","description":"Calcis cost estimation callback for LlamaIndex","directories":{},"_nodeVersion":"24.4.1","_hasShrinkwrap":false,"devDependencies":{"llamaindex":"^0.8.0","typescript":"^5.0.0","@types/node":"^20.0.0"},"peerDependencies":{"llamaindex":">=0.5.0"},"_npmOperationalInternal":{"tmp":"tmp/llamaindex_1.0.1_1776940147437_0.6468287949641427","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@calcis/llamaindex","version":"1.0.2","keywords":["calcis","llamaindex","llm","cost","estimation"],"license":"MIT","_id":"@calcis/llamaindex@1.0.2","maintainers":[{"name":"calcis","email":"calcis.dev@gmail.com"}],"homepage":"https://www.calcis.dev","bugs":{"url":"https://github.com/rc397/Calcis/issues"},"dist":{"shasum":"a280e4e38148658801b37c3ad1a497bfd7e98e6b","tarball":"https://registry.npmjs.org/@calcis/llamaindex/-/llamaindex-1.0.2.tgz","fileCount":7,"integrity":"sha512-zJfaDkl/Y7xj2yIp46qnwgq64bRsTSczPIG4N7sgFOr1sfp93fqo68h2qIW9OFh8OpLJbE/bW4fwT75IwHD3dw==","signatures":[{"sig":"MEYCIQCz2lYmuUSN+7ko1c8VBuu7p4nthSfrJBl9Kaxvxw4Q8QIhAPk7y21VjsjqVCMHN1oBThe5O1G++8WFkGpvBlrLzjPK","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15895},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"2ac0279a067083da14424b97edaf969cbc69b3c8","scripts":{"build":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"calcis","email":"calcis.dev@gmail.com"},"repository":{"url":"git+https://github.com/rc397/Calcis.git","type":"git"},"_npmVersion":"11.4.2","description":"Calcis cost estimation callback for LlamaIndex","directories":{},"_nodeVersion":"24.4.1","_hasShrinkwrap":false,"devDependencies":{"llamaindex":"^0.8.0","typescript":"^5.0.0","@types/node":"^20.0.0"},"peerDependencies":{"llamaindex":">=0.5.0"},"_npmOperationalInternal":{"tmp":"tmp/llamaindex_1.0.2_1776941440970_0.44454903326771844","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@calcis/llamaindex","version":"1.0.4","description":"Calcis cost estimation callback for LlamaIndex","license":"MIT","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","prepublishOnly":"npm run build"},"keywords":["calcis","llamaindex","llm","cost","estimation"],"peerDependencies":{"llamaindex":">=0.5.0"},"devDependencies":{"llamaindex":"^0.8.0","typescript":"^5.0.0","@types/node":"^20.0.0"},"repository":{"type":"git","url":"git+https://github.com/rc397/Calcis.git"},"homepage":"https://www.calcis.dev","_id":"@calcis/llamaindex@1.0.4","gitHead":"862b57a8fc4e016ca36906c9c0ddea082f4c38b9","bugs":{"url":"https://github.com/rc397/Calcis/issues"},"_nodeVersion":"24.4.1","_npmVersion":"11.4.2","dist":{"integrity":"sha512-IY4hi0hklo9pMRekcekuqjUwrc2L9LbzmmBbum3h+zgYkxz8SyY3Q/Cn6TIY/KhihICEdgTMO9ISRcSauK8w2A==","shasum":"7b70a1cc3cf3f44151f61ef67265b34a754badf3","tarball":"https://registry.npmjs.org/@calcis/llamaindex/-/llamaindex-1.0.4.tgz","fileCount":7,"unpackedSize":15860,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD+kNyZH4o9CyYN9aX7nPmNuhy1yo9GcMp8PcgcseCF0QIgL2OUtcov6/U6uGZxqAh1UW9mkGQopnmvnKTQgc/jlkw="}]},"_npmUser":{"name":"calcis","email":"calcis.dev@gmail.com"},"directories":{},"maintainers":[{"name":"calcis","email":"calcis.dev@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/llamaindex_1.0.4_1777117464689_0.09055578408099363"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-19T11:02:05.383Z","modified":"2026-04-25T11:44:24.955Z","1.0.0":"2026-04-19T11:02:05.673Z","1.0.1":"2026-04-23T10:29:07.581Z","1.0.2":"2026-04-23T10:50:41.105Z","1.0.4":"2026-04-25T11:44:24.850Z"},"bugs":{"url":"https://github.com/rc397/Calcis/issues"},"license":"MIT","homepage":"https://www.calcis.dev","keywords":["calcis","llamaindex","llm","cost","estimation"],"repository":{"type":"git","url":"git+https://github.com/rc397/Calcis.git"},"description":"Calcis cost estimation callback for LlamaIndex","maintainers":[{"name":"calcis","email":"calcis.dev@gmail.com"}],"readme":"# @calcis/llamaindex\r\n\r\nCalcis cost-estimation callback for [LlamaIndex](https://ts.llamaindex.ai).\r\n\r\n> **Live pricing for 25+ models, side-by-side comparisons, and a web estimator: https://calcis.dev**\r\n>\r\n> - Full price index: https://calcis.dev/models\r\n> - Compare models: https://calcis.dev/compare\r\n> - API reference: https://calcis.dev/api-docs\r\n\r\nSubscribe the handler to LlamaIndex's `CallbackManager` and get a\r\none-line cost estimate for every LLM call, plus a rolling session\r\ntotal.\r\n\r\n## Install\r\n\r\n```bash\r\nnpm install @calcis/llamaindex llamaindex\r\n```\r\n\r\nYou also need a Calcis API key (Pro tier or above). Get one at\r\n[calcis.dev/dashboard](https://calcis.dev/dashboard). Browse every\r\nsupported model at [calcis.dev/models](https://calcis.dev/models).\r\n\r\n## Usage\r\n\r\n### Global (simplest)\r\n\r\nAttach once to `Settings.callbackManager` and every downstream chat\r\nengine, query engine, or agent inherits cost reporting.\r\n\r\n```ts\r\nimport { Settings, SimpleChatEngine, Anthropic } from \"llamaindex\";\r\nimport { CalcisLlamaIndexHandler } from \"@calcis/llamaindex\";\r\n\r\nSettings.llm = new Anthropic({ model: \"claude-sonnet-4-6\" });\r\n\r\nconst calcis = new CalcisLlamaIndexHandler({\r\n  apiKey: process.env.CALCIS_API_KEY!,\r\n});\r\ncalcis.attach(Settings.callbackManager);\r\n\r\nconst chatEngine = new SimpleChatEngine();\r\nawait chatEngine.chat({ message: \"Explain quantum computing\" });\r\n\r\nconsole.log(`Session total: $${calcis.getSessionTotal().toFixed(4)}`);\r\n```\r\n\r\nEvery LLM call now emits:\r\n\r\n```\r\n[calcis] claude-sonnet-4-6 · 243 in · 650 out · $0.0105 · session: $0.0105 (1 calls)\r\n```\r\n\r\n### Scoped\r\n\r\nIf you only want cost reporting inside a specific block:\r\n\r\n```ts\r\nimport { Settings, CallbackManager } from \"llamaindex\";\r\nimport { CalcisLlamaIndexHandler } from \"@calcis/llamaindex\";\r\n\r\nconst cm = new CallbackManager();\r\nconst calcis = new CalcisLlamaIndexHandler({\r\n  apiKey: process.env.CALCIS_API_KEY!,\r\n  model: \"claude-sonnet-4-6\",\r\n});\r\ncalcis.attach(cm);\r\n\r\nawait Settings.withCallbackManager(cm, async () => {\r\n  // ...LLM calls inside here are metered\r\n});\r\n\r\ncalcis.detach(cm);\r\n```\r\n\r\n## Config\r\n\r\n```ts\r\nnew CalcisLlamaIndexHandler({\r\n  apiKey: string,                   // required: calc_… key\r\n  model?: string,                   // Calcis model ID override\r\n  verbose?: boolean,                // default true: logs per-call summary\r\n  onEstimate?: (e) => void,         // optional structured sink\r\n});\r\n```\r\n\r\n`model` defaults to `Settings.llm.metadata.model` when you attach to\r\nthe global `Settings.callbackManager`. Pass it explicitly when\r\nattaching to a scoped CallbackManager that doesn't live under\r\n`Settings.withCallbackManager`.\r\n\r\n## Session helpers\r\n\r\n```ts\r\ncalcis.getSessionTotal(); // cumulative cost across calls\r\ncalcis.getCallCount();    // number of LLM calls so far\r\ncalcis.resetSession();    // zero the counters (e.g. per request)\r\n```\r\n\r\n## Failure mode\r\n\r\nThis handler never throws. If the Calcis API is unreachable, returns\r\nan error, or the response is malformed, the handler silently skips\r\nthe estimate for that call: the underlying LlamaIndex pipeline keeps\r\nrunning. Cost estimation is a nice-to-have; your product is not.\r\n\r\n## Compatibility\r\n\r\nTested against **llamaindex 0.8.x**. The event map (`llm-start` /\r\n`llm-end`) and payload shape (`{ id, messages }` / `{ id, response }`)\r\nhave been stable since 0.5, so earlier patch versions in that range\r\nshould also work. If LlamaIndex ships a breaking callback change in a\r\nfuture release, open an issue: this package will be updated in lock\r\nstep.\r\n\r\n## Links\r\n\r\n- [Web App](https://www.calcis.dev)\r\n- [API Docs](https://www.calcis.dev/api-docs)\r\n- [CLI (`calcis`)](https://www.npmjs.com/package/calcis)\r\n- [Pricing dataset (`@calcis/pricing`)](https://www.npmjs.com/package/@calcis/pricing)\r\n- [LangChain integration (`@calcis/langchain`)](https://www.npmjs.com/package/@calcis/langchain)\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}