# TokenEstimator

**Package:** `flyte.extras`

Protocol for records that can estimate their own token count.

    Implement this on your record type and the `TokenBatcher` will
    call it automatically when no explicit `estimated_tokens` is passed
    to `TokenBatcher.submit`.

    Example::

        @dataclass
        class Prompt:
            text: str

            def estimate_tokens(self) -&gt; int:
                return len(self.text) // 4 + 1
    
```python
protocol TokenEstimator()
```
## Methods

| Method | Description |
|-|-|
| [`estimate_tokens()`](#estimate_tokens) |  |

### estimate_tokens()

```python
def estimate_tokens()
```

---
**Source**: https://github.com/unionai/unionai-docs/blob/main/content/api-reference/flyte-sdk/packages/flyte.extras/tokenestimator.md
**HTML**: https://www.union.ai/docs/v2/byoc/api-reference/flyte-sdk/packages/flyte.extras/tokenestimator/
