# Compute Levenshtein distance from an AI agent

You need the Levenshtein distance between two strings: the smallest number of single-character insertions, deletions and substitutions that turns one into the other.

Use `text-levenshtein-distance@1.0.0`. It is free and needs no key or sign-up. Compute bounded Levenshtein distance over code points or deterministic grapheme tokens.

## Why call a tool for this

Counting edits in a model response is unreliable once the strings differ in several places. The tool fills the full edit table and returns the distance with the token count of each string.

## Call it over HTTP

```sh
curl -X POST https://computefirst.net/v1/tools/text-levenshtein-distance/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"source":"kitten","target":"sitting"}'
```

Response:

```json
{
  "result": {
    "distance": 3,
    "source_tokens": 6,
    "target_tokens": 7
  }
}
```

## Call it over MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "text-levenshtein-distance",
  "version": "1.0.0",
  "input": {
    "source": "kitten",
    "target": "sitting"
  }
}
```

## Check the result

Each string can have at most 128 characters and 2048 UTF-8 bytes. Strings are compared exactly: no case folding and no Unicode normalization. Use token_mode grapheme if an accented letter written with a combining mark should count as one character.

Full contract, limits and unsupported cases: [Text levenshtein distance](/tools/text-levenshtein-distance).

## Related tools

- [Text damerau distance](/tools/text-damerau-distance)
- [Text weighted edit distance](/tools/text-weighted-edit-distance)
- [Text edit alignment](/tools/text-edit-alignment)
