---
title: Token Counter
description: Count GPT tokens in text.
---

# Token Counter

Count tokens for a text string using the GPT tokenizer. Useful for estimating API costs.

<Warning>
Requires an API key. Run `devv login <key>` first.
</Warning>

## Commands

```bash
devv tokens "Hello, how are you today?"
devv tokens "$(cat prompt.txt)"
cat long-prompt.txt | devv tokens
```

## Examples

```bash
# Count tokens in a prompt
devv tokens "Explain quantum computing in simple terms"

# Count tokens in a file
cat system-prompt.txt | devv tokens

# Estimate cost before sending
devv tokens "$(cat my-prompt.txt)"
```

## Output

```
Tokens: 7
Model estimates:
  GPT-4:     ~$0.0002 (input)
  GPT-3.5:   ~$0.00001 (input)
```

## Pipeline Usage

| Pipeline ID | Description |
|-------------|-------------|
| `token-counter` | Count GPT tokens |

```bash
devv pipe exec "token-counter" "Hello, how are you?"
```

### Behavior

Takes text as input, returns token count and cost estimates.
