Text Analysis

Levenshtein Distance

Calculates the minimum number of single-character edits (insertions, deletions, substitutions) needed to transform one string into another. Access via MCP in Cursor or Windsurf, or REST at `/v1/text/levenshtein`. Returns precise integer distance — useful for fuzzy matching, spell checking, and similarity scoring in AI workflows.

API Endpoint

GET /v1/text/levenshtein

Code Examples

curl "https://tinyfn.io/v1/text/levenshtein" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/text/levenshtein', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/text/levenshtein',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's text analysis tools:

{
  "mcpServers": {
    "tinyfn-text": {
      "url": "https://tinyfn.io/mcp/text",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

What is Levenshtein distance and how is it calculated?

Levenshtein distance counts the minimum single-character edits (insert, delete, substitute) to transform string A into string B. 'cat' to 'bat' = 1 edit (substitute c→b), 'kitten' to 'sitting' = 3 edits.

How do I use Levenshtein distance with MCP in AI coding assistants?

Import the TinyFn MCP server in Cursor, Claude Code, or Windsurf, then call the levenshtein tool with two strings as parameters. Perfect for fuzzy search implementations or data deduplication workflows.

What's the difference between Levenshtein and other string similarity metrics?

Levenshtein only allows single-character operations, while Damerau-Levenshtein adds transposition. Jaro-Winkler focuses on prefix matches. Levenshtein is stricter and better for exact similarity measurement.

Does Levenshtein distance work with Unicode and special characters?

Yes, it treats each Unicode code point as a single character. 'café' to 'cafe' = 1 edit (é→e). Emojis and accented characters are handled correctly as distinct characters.

What's the maximum Levenshtein distance between two strings?

The maximum distance equals the length of the longer string — when strings share no common characters, you need to delete all characters from one and insert all characters of the other.

Try Levenshtein Distance Now

Get your free API key and start using Levenshtein Distance in seconds.

Get Free API Key