Quick Start

1️⃣ Initialize RankFlow

Get started by initializing RankFlow with your API key. You can obtain an API key from the RankFlow dashboard.

import { RankFlow } from "@rankflow/sdk";

// Initialize RankFlow with API Key
const rankflow = new RankFlow({
  apiKey: "rf_test_1234567890abcdef",
});

2️⃣ Creating an AI Agent with Monetization

Here's how to create an AI agent that automatically retrieves and embeds relevant ads into its responses:

import OpenAI from "openai";
import { RankFlow } from "@rankflow/sdk";

// Initialize AI Model & RankFlow
const openai = new OpenAI({ apiKey: "YOUR_OPENAI_API_KEY" });
const rankflow = new RankFlow({ apiKey: "rf_test_1234567890abcdef" });

// User Query Input
const userQuery = "How do I stake Ethereum?";

// Retrieve Context-Aware Ads for the Query
const adResponse = await rankflow.getAds({
      query: userQuery,
      relevanceWeight: 0.3,
      engagementWeight: 0.1,
      numberOfAds: 3,
    });

// Generate AI Response with Embedded Ads
const completion = await openai.chat.completions.create({
  model: "gpt-4",
  messages: [
    { role: "system", content: "You are a helpful AI assistant." },
    { role: "user", content: userQuery },
   
  ],
});



console.log("AI Response:", completion.choices[0].message.content);
console.log("Tokens Earned:", adResponse.tokensEarned);

Next Steps

Now that you have RankFlow integrated, explore these topics to make the most of the platform: