# Text levenshtein distance

`text-levenshtein-distance` · version 1.0.0 · Text · free, no key needed

Compute bounded Levenshtein distance over code points or deterministic grapheme tokens.

**Use when you need to: compute levenshtein distance · unit cost edit distance · levenshtein over code points.**

## Decide before calling

Read the [versioned contract](/v1/tools/text-levenshtein-distance/versions/1.0.0) and the supported scope below. Reuse `text-levenshtein-distance@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `text-levenshtein-distance@1.0.0` for compute levenshtein distance. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- compute levenshtein distance
- unit cost edit distance
- levenshtein over code points
- count insertions deletions substitutions
- classic string correction distance
- minimum unit text edits

## Not supported

- unbounded text comparison
- locale-sensitive collation
- semantic similarity scoring

## Behavior

- Insertion, deletion, and substitution each cost one; equal tokens cost zero.
- token_mode defaults to code_point. grapheme is a simple fixed rule, not UAX #29: a token is a character plus any following combining marks, variation selectors and emoji skin-tone modifiers, anything joined by U+200D stays together, and regional indicators pair up. So a\u200db is one token, and CRLF, Hangul jamo, Indic conjuncts and emoji tag sequences stay split into several.
- The result is the minimum cost from the Wagner-Fischer recurrence.
- Pure bounded dynamic programming; no clock, locale, network, or randomness.

## Input

- `source` (string, required): max length 2048
- `target` (string, required): max length 2048
- `token_mode` (one of "code_point", "grapheme", optional)

## Output

- `distance` (integer, required): min 0; max 512000
- `source_tokens` (integer, required): min 0; max 128
- `target_tokens` (integer, required): min 0; max 128

## Limits

- max input bytes: 2048
- max tokens per text: 128
- max cost: 1000
- max cells: 16641

## Example

Request input:

```json
{
  "source": "kitten",
  "target": "sitting"
}
```

Response:

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

## How to call it

### 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"
  }
}
```

### HTTP (no key)

```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"}'
```

The machine-readable contract is at [/v1/tools/text-levenshtein-distance/versions/1.0.0](/v1/tools/text-levenshtein-distance/versions/1.0.0).

### CLI

```sh
node cli.mjs run text-levenshtein-distance 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Text weighted edit distance](/tools/text-weighted-edit-distance): Compute bounded weighted insertion, deletion, and substitution distance over text tokens.
- [Text damerau distance](/tools/text-damerau-distance): Compute bounded optimal-string-alignment distance with adjacent transpositions.
- [Text edit alignment](/tools/text-edit-alignment): Return a bounded optimal edit alignment with a documented deterministic tie-break order.
- [Text count](/tools/text-count): Count Unicode code points, UTF-16 code units, UTF-8 bytes, and lines.
- [Text diff stats](/tools/text-diff-stats): Summarize a line-record diff as keep, insert, delete, and hunk counts.
- [Jaro similarity compute](/tools/jaro-similarity-compute): Compute Jaro similarity with a deterministic match window and exact reduced rational audit fields.
