npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@rosid/threads-api

v1.1.0

Published

Standalone Threads API library for fetching user data and threads

Downloads

44

Readme

Threads API

A standalone library for fetching data from Threads (threads.net).

Installation

npm install @rosid/threads-api

or

bun add @rosid/threads-api

Usage

import { extractTokens, getUserId, fetchThreadsData, searchPosts } from '@rosid/threads-api';

// Extract LSD token
const { lsd } = await extractTokens('zuck');

// Get user ID (cached)
const userId = await getUserId('zuck');

// Fetch threads from a user's profile
const threads = await fetchThreadsData('zuck');

// Search for posts (with LSD token to avoid rate limits)
const { lsd } = await extractTokens('zuck');
const results = await searchPosts('threads', { lsd });

API

extractTokens(user: string)

Extract LSD token from a Threads profile page.

Returns: Promise<{ lsd: string }>

const { lsd } = await extractTokens('zuck');
// { lsd: "token_value_here" }

getUserId(user: string)

Get user ID from a Threads profile. Results are cached for 1 hour.

Returns: Promise<string>

const userId = await getUserId('zuck');
// "1234567890"

fetchThreadsData(user: string)

Fetch thread items from a user's profile page.

Returns: Promise<ThreadItem[]>

ThreadItem Structure:

interface ThreadItem {
  post: {
    user?: {
      username: string;
      profile_pic_url: string;
    };
    taken_at: number;           // Unix timestamp
    code: string;               // Post code/ID
    caption?: {
      text: string;             // Post text content
    };
    text_post_app_info?: {
      share_info?: {
        quoted_post?: any;      // Quoted post data
        reposted_post?: any;    // Reposted post data
      };
      reply_to_author?: any;   // Reply information
    };
    image_versions2?: any;      // Image media data
    carousel_media?: any;       // Carousel/multiple images
    video_versions?: any;       // Video media data
  };
}

Example:

const threads = await fetchThreadsData('zuck');
// [
//   {
//     post: {
//       user: {
//         username: "zuck",
//         profile_pic_url: "https://..."
//       },
//       taken_at: 1699123456,
//       code: "C1234567890",
//       caption: {
//         text: "Post content here..."
//       },
//       image_versions2: { ... },
//       // ... other media fields
//     }
//   },
//   // ... more threads
// ]

searchPosts(query: string, options?: SearchOptions)

Search for posts on Threads by keyword.

Parameters:

  • query: string - Search query/keyword
  • options?: SearchOptions - Optional search parameters
    • serp_type?: string - Search result type (e.g., "default")
    • filter?: 'recent' | 'profiles' - Filter results by type
    • lsd?: string - LSD token (recommended to avoid rate limits)

Returns: Promise<ThreadItem[]> (same structure as fetchThreadsData)

Examples:

// Basic search
const results = await searchPosts('threads');

// Search with serp_type
const results = await searchPosts('threads', { serp_type: 'default' });

// Search with filter
const recentResults = await searchPosts('threads', { filter: 'recent' });
const profileResults = await searchPosts('threads', { filter: 'profiles' });

// Search with both parameters
const results = await searchPosts('threads', { 
  serp_type: 'default', 
  filter: 'recent' 
});

// Search with LSD token (recommended to avoid rate limits)
const { lsd } = await extractTokens('zuck');
const results = await searchPosts('threads', { lsd });

// Search with all parameters including LSD token
const results = await searchPosts('threads', { 
  serp_type: 'default', 
  filter: 'recent',
  lsd 
});

License

MIT