Extract Hashtags API: The Complete Guide

Need to extract hashtags from text? This guide covers everything you need to know about hashtag extraction via API, including handling different formats and social media analysis.

What is Hashtag Extraction?

Hashtag extraction identifies and extracts all hashtags (#tags) from text content. This is essential for social media analysis, content categorization, and trend tracking. Proper extraction handles Unicode characters, numbers, and edge cases.

Example: "Love this #sunset #photography #nature" extracts ["#sunset", "#photography", "#nature"]

Hashtag Format Considerations

Hashtags can contain various characters:

  • Letters: #hello, #World
  • Numbers: #2024, #web3
  • Mixed: #Covid19, #React18
  • Unicode: #cafe, #tokyo (with special chars)
Note: Most social platforms don't allow special characters or spaces in hashtags. #hello-world is typically just #hello.

Using the Extract Hashtags API

TinyFn provides a simple endpoint to extract hashtags:

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

{
  "text": "Beautiful day! #sunset #photography #nature #weekend",
  "include_hash": true
}
Response
{
  "hashtags": ["#sunset", "#photography", "#nature", "#weekend"],
  "count": 4,
  "without_hash": ["sunset", "photography", "nature", "weekend"]
}

Parameters

Parameter Type Description
text string The text to extract hashtags from (required)
include_hash boolean Include # symbol in results (default: true)
lowercase boolean Convert hashtags to lowercase (default: false)
unique_only boolean Return only unique hashtags (default: true)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/text/extract-hashtags',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      text: 'Beautiful day! #sunset #photography',
      include_hash: true
    })
  }
);
const result = await response.json();
console.log(result.hashtags); // ["#sunset", "#photography"]

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/text/extract-hashtags',
    headers={'X-API-Key': 'your-api-key'},
    json={'text': 'Beautiful day! #sunset #photography'}
)
result = response.json()
print(result['hashtags'])  # ["#sunset", "#photography"]

cURL

curl -X POST "https://api.tinyfn.io/v1/text/extract-hashtags" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "Beautiful day! #sunset #photography"}'

Common Use Cases

  • Social Media Analysis: Track hashtag usage and trends
  • Content Categorization: Auto-tag content based on hashtags
  • Brand Monitoring: Track brand-related hashtags
  • Trend Detection: Identify trending topics
  • Influencer Analysis: Analyze hashtag strategies

Best Practices

  1. Normalize case: Convert to lowercase for comparison
  2. Deduplicate: Remove duplicate hashtags from lists
  3. Filter noise: Ignore very short or numeric-only hashtags
  4. Track frequency: Count occurrences for trend analysis

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 Hashtags API

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

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key