# LlamaIndex (/docs/integrations/llamaindex)



## Python [#python]

Install the `llamaindex` extra and init as usual — see [init parameters](/docs/sdk/init). The
per-provider LlamaIndex LLMs are metered, and tool calls get their own steps in the trace.

```bash
pip install "token-police[llamaindex]"
```

## Node [#node]

LlamaIndex works on the base install with CommonJS. On **native ESM**, import order can leave the
per-provider LlamaIndex modules un-instrumented — pass them explicitly under
`instrumentModules.llamaIndex`:

```typescript
import * as tp from "token-police";
import * as openaiModule from "@llamaindex/openai";
import * as anthropicModule from "@llamaindex/anthropic";

tp.init({
  /* … see init parameters … */
  instrumentModules: {
    llamaIndex: { openaiModule, anthropicModule },
  },
});
```

Pass only the provider modules you use — `openaiModule`, `anthropicModule`, `geminiModule`. Each
one is a namespace import.

<Callout type="info">
  On CommonJS (`require`) you don't need `instrumentModules` at all. See
  [Node & ESM](/docs/sdk/node-esm) for when import order matters.
</Callout>

<Callout type="info" title="A startup line you can ignore">
  Node apps that have `@llamaindex/*` installed may print `llamaindex was already imported. This
    breaks constructor checks and will lead to issues!` once when `init()` runs. Token Police prepares
  both module formats of each LlamaIndex provider package so it can instrument whichever one your
  app uses, and LlamaIndex flags the second load. Your app only ever runs through its own copy, so
  nothing is affected: metering, tool steps and blocking are unchanged.
</Callout>

<Callout type="warn" title="Reroute does not switch the model on LlamaIndex">
  A Reroute rule does not switch the model on LlamaIndex — those calls still run on the original
  model. Metering and blocking work normally. See [Actions](/docs/rules/actions#reroute).
</Callout>

## Next [#next]

<Cards>
  <Card title="Node & ESM" href="/docs/sdk/node-esm" description="Import order and instrumentModules." />

  <Card title="Support matrix" href="/docs/integrations/matrix" description="Every provider and framework at a glance." />
</Cards>
