Need to check if two strings are anagrams? This guide covers everything you need to know about anagram detection via API, including handling spaces, case sensitivity, and various use cases.
What is an Anagram?
An anagram is a word or phrase formed by rearranging the letters of another word or phrase, using all the original letters exactly once. For example, "listen" and "silent" are anagrams because they contain the same letters.
The check typically ignores spaces, punctuation, and case differences.
Anagram Examples
Famous anagram pairs:
- listen / silent
- heart / earth
- night / thing
- dormitory / dirty room
- astronomer / moon starer
Using the Anagram Checker API
TinyFn provides a simple endpoint to check anagrams:
POST https://api.tinyfn.io/v1/text/anagram
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"string1": "listen",
"string2": "silent",
"ignore_case": true
}
{
"are_anagrams": true,
"string1_sorted": "eilnst",
"string2_sorted": "eilnst",
"letter_count": 6
}
Parameters
| Parameter | Type | Description |
|---|---|---|
string1 |
string | First string to compare (required) |
string2 |
string | Second string to compare (required) |
ignore_case |
boolean | Case-insensitive check (default: true) |
ignore_spaces |
boolean | Ignore whitespace (default: true) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/text/anagram',
{
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
string1: 'listen',
string2: 'silent'
})
}
);
const result = await response.json();
console.log(result.are_anagrams); // true
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/text/anagram',
headers={'X-API-Key': 'your-api-key'},
json={'string1': 'listen', 'string2': 'silent'}
)
result = response.json()
print(result['are_anagrams']) # True
cURL
curl -X POST "https://api.tinyfn.io/v1/text/anagram" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"string1": "listen", "string2": "silent"}'
Common Use Cases
- Word Games: Validate anagram puzzles like Scrabble
- Educational Apps: Teach vocabulary and spelling
- Cryptography: Basic encryption/scrambling validation
- Creative Writing: Find anagram pairs for wordplay
- Name Generators: Create anagram-based pseudonyms
Best Practices
- Normalize input: Remove spaces and convert to same case
- Handle special characters: Decide whether to include punctuation
- Show letter breakdown: Display sorted letters for verification
- Consider partial anagrams: Check if one is subset of another
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-text": {
"url": "https://api.tinyfn.io/mcp/text/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all text analysis tools available via MCP in our Text Analysis MCP Tools for AI Agents guide.
Try the Anagram Checker API
Get your free API key and start checking anagrams in seconds.
Get Free API Key