Extract Mentions API: The Complete Guide

Need to extract @mentions from text? This guide covers everything you need to know about mention extraction via API, including handling social media formats and user tagging analysis.

What is Mention Extraction?

Mention extraction identifies and extracts all @mentions (user tags) from text content. This is essential for social media monitoring, notification systems, and user engagement analysis. Proper extraction handles various username formats across platforms.

Example: "Thanks @john and @jane_doe for the help!" extracts ["@john", "@jane_doe"]

Mention Format Considerations

Usernames vary by platform:

  • Twitter/X: @username (letters, numbers, underscores)
  • Instagram: @user.name (allows periods)
  • GitHub: @user-name (allows hyphens)
  • Discord: @Username#1234 (with discriminator)
Tip: Different platforms have different username rules. Choose extraction settings based on your target platform.

Using the Extract Mentions API

TinyFn provides a simple endpoint to extract mentions:

API Request
POST https://api.tinyfn.io/v1/text/extract-mentions
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "text": "Shoutout to @alice and @bob_smith for the amazing work!",
  "include_at": true
}
Response
{
  "mentions": ["@alice", "@bob_smith"],
  "count": 2,
  "without_at": ["alice", "bob_smith"]
}

Parameters

Parameter Type Description
text string The text to extract mentions from (required)
include_at boolean Include @ symbol in results (default: true)
lowercase boolean Convert usernames to lowercase (default: false)
unique_only boolean Return only unique mentions (default: true)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/text/extract-mentions',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      text: 'Thanks @alice and @bob for the help!',
      include_at: true
    })
  }
);
const result = await response.json();
console.log(result.mentions); // ["@alice", "@bob"]

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/text/extract-mentions',
    headers={'X-API-Key': 'your-api-key'},
    json={'text': 'Thanks @alice and @bob for the help!'}
)
result = response.json()
print(result['mentions'])  # ["@alice", "@bob"]

cURL

curl -X POST "https://api.tinyfn.io/v1/text/extract-mentions" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "Thanks @alice and @bob for the help!"}'

Common Use Cases

  • Notification Systems: Trigger notifications for mentioned users
  • Social Monitoring: Track brand or user mentions
  • Engagement Analysis: Measure user tagging patterns
  • Influencer Detection: Find frequently mentioned accounts
  • Content Moderation: Identify user interactions

Best Practices

  1. Normalize usernames: Consider lowercase for comparison
  2. Validate users: Verify extracted usernames exist
  3. Handle edge cases: Email addresses contain @ but aren't mentions
  4. Platform-specific rules: Adjust extraction for target platform

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 Extract Mentions API

Get your free API key and start extracting mentions in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key