While 'mbd focuses on providing the most advanced ML-powered personalization and moderation as a service, if you are developing a Farcaster client, Neynar offers a comprehensive range of APIs that covers all other needs for building a Farcaster client.


Our /for-you and /trending feeds are also integrated into Neynar's service through their /for_you and /trending APIs. If you need to use our service through Neynar, here is a quick guide on how to do it and things to watch out for.


Prerequesites


  1. You will need to have a Neynar API key and have the Neynar SDK setup (see the top sections of Neynar's Quickstart Guide)
  2. It is probably helpful if you first read about our /for-you and /trending APIs, as you will be passing the same filter parameters through Neynar to us, and our docs will have the most up-to-date options.

🔖 Things to Note:

  • Neynar's SDK only passes the "filters" parameter to mbd, and thus impression_count can't be supported through Neynar at the moment
  • top_k is specified through the limit parameter when calling Neynar
  • AI labels are not available through Neynar at the moment

Getting a for-you feed


You can get a for-you feed by either:

  1. using Neynar's SDK, or
  2. calling Neynar's API directly

1. Getting an 'mbd for-you feed using Neynar's SDK

'mbd for-you API filter reference: https://docs.mbd.xyz/reference/post_casts-feed-for-you

Using mbd's for-you through Neynar simply involves:

  1. Defining mbd filters in the exact same format as you would when directly calling mbd's for-you API as providerMetadata
  2. Calling Neynar SDK's fetchFeedForYou() function, specifying mbd as the provider, and passing the filter values as providerMetadata constructed in step 1

Sample code:

import { NeynarAPIClient, Configuration } from "@neynar/nodejs-sdk";
import { ForYouProvider } from "@neynar/nodejs-sdk/build/api";


const config = new Configuration({
    apiKey: process.env.NEYNAR_API_KEY // your Neynar API key
  });
const client = new NeynarAPIClient(config); 

//
// Step 1 - specify the filter parameters for /for-you
//
const metadata = encodeURIComponent(JSON.stringify({
    "filters": {
        "ai_labels": ['web3_infra', 'web3_nft', 'web3_consumer', 'business_entrepreneurs'],
        "author_ids": activeAuthorIds; // see example definition at the bottom of this page
    }
}));

async function fetchFeed(userFid: number) {
   //
   // Step 2 - call fetchFeedForYou(), specifying mbd as provider, and 
   //          passing in the filter params constructed as metadata above
   //
    const feed = await client.fetchFeedForYou({
        fid: userFid,
        provider: ForYouProvider.Mbd, // 'mbd' can work if you run into import errors
        providerMetadata: metadata       
    })

    console.log(`Feed for user ${userFid}:`, feed);
}

// fetch for-you feed for Dan Romero (fid 3) 
fetchFeed(3);




2. Getting an 'mbd for-you feed by directly calling Neynar's API

'mbd for-you API filter reference: https://docs.mbd.xyz/reference/post_casts-feed-for-you

Using mbd's for-you by directly calling Neynar's API works very similar to using Neynar, but without the need to install Neynar SDK. These are the simple steps:

  1. Defining mbd filters in the exact same format as you would when directly calling mbd's for-you API as providerMetadata
  2. Calling Neynar's for_you API's specifying mbd as the provider, and providerMetadata constructed in step 1, as part of the URL query string

const fetch = require('node-fetch');

//
// Step 1 - specify the filter parameters for /for-you
//
const provider_metadata = encodeURIComponent(JSON.stringify({
  "filters": {
    "ai_labels": ['web3_infra', 'web3_nft', 'web3_consumer', 'business_entrepreneurs'],
    "author_ids": activeAuthorIds; // see example definition at the bottom of this page
  }
}));

//
// Step 2 - set up the url to call for_you API, specifying mbd as provider, and 
//.         passing in the filter params constructed as metadata above
//
const url = `https://api.neynar.com/v2/farcaster/feed/for_you?fid=3&viewer_fid=2&provider=mbd&limit=10&provider_metadata=${provider_metadata}`;

const options = {
  method: 'GET',
  headers: {
    'accept': 'application/json',
    'api_key': process.env.NEYNAR_API_KEY // your Neynar API key
  }
};

// fetch the feed
fetch(url, options)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('error:', error));


Some sample filter values for experimentation:


//
// for channels filter param
//

const popularChannels = [
    'chain://eip155:7777777/erc721:0x4f86113fc3e9783cf3ec9a552cbb566716a57628', // Farcaster (farcaster)
    'https://superrare.com', // SuperRare (superrare)
    'https://onchainsummer.xyz', // Base (base)
    'chain://eip155:1/erc721:0xca21d4228cdcc68d4e23807e5e370c07577dd152', // Zora (zora)
    'chain://eip155:7777777/erc721:0x10a77f29a6bbeae936f3f27cd60546072dae4e41', // Warpcast (warpcast)
    'https://warpcast.com/~/channel/itookaphoto', // I Took a Photo! (itookaphoto)
    'https://warpcast.com/~/channel/replyguys', // reply guys (replyguys)
    'https://warpcast.com/~/channel/phaver', // phaver (phaver)
    'chain://eip155:1/erc721:0xec0ba367a6edf483a252c3b093f012b9b1da8b3f', // Food (food)
    'https://ethereum.org', // Ethereum (ethereum)
    'https://warpcast.com/~/channel/base-builds', // base-builds (base-builds)
    'chain://eip155:7777777/erc721:0xf6a7d848603aff875e4f35025e5c568679ccc17c', // Nature (nature)
    'https://warpcast.com/~/channel/airstack', // Moxie Official (airstack)
    'chain://eip155:1/erc721:0x7dd4e31f1530ac682c8ea4d8016e95773e08d8b0', // dev (dev)
    'https://warpcast.com/~/channel/clankers' // Clankers (clankers)
];

//
// for author_ids filter param
//

const activeAuthors = [
    "19253",
    "448502",
    "866209",
    "306428",
    "862185",
    "491800",
    "37",
    "17524",
    "539413",
    "359814",
    "3",
    "846210",
    "845419",
    "832231",
    "840924",
    "842384",
    "3698",
    "665262",
    "842411",
    "848375",
    "344886",
    "523306",
    "850094",
    "839039",
    "3801",
    "751460",
    "816528",
    "526562",
    "599465",
    "849863"
]

// casts created by people the current user_id is following
const currentUserFollowing = ["/user/user_id/following"];

// casts created by people Dan Romeo is following
const danFollowing = ["/user/3/following"];