Back to Dice Roller

Getting Started

Learn how to install and use @rankfor/dice-roller to analyze AI response stability for your brand.

Prerequisites

  • Node.js 18.0.0 or higher
  • API key for at least one LLM provider (Gemini, OpenAI, or Grok)
  • TypeScript 5.0+ (recommended, but not required)

Installation

Install the core package from npm:

npm install @rankfor/dice-roller

Then install the LLM SDK(s) you plan to use as peer dependencies:

# For Google Gemini
npm install @google/generative-ai

# For OpenAI or Grok/xAI (both use OpenAI SDK)
npm install openai

Note: Peer dependencies are optional. Only install the SDK for the provider(s) you plan to use.

Quick Start

Single Model Analysis

Analyze how consistently a single AI model responds to your prompt:

import { analyzeStability } from '@rankfor/dice-roller';

const result = await analyzeStability({
  prompt: 'What are the best CRM tools for small businesses?',
  iterations: 5,
  model: 'gemini',
  apiKey: process.env.GEMINI_API_KEY,
  brandName: 'Salesforce', // Optional: track your brand
});

console.log(`Consistency Score: ${result.consistencyScore}%`);
console.log('Core Messages:', result.analysis.coreStableMessages);
console.log('Brand Mentions:', result.brandMentions.average);

Cross-Model Experiment

Compare responses across multiple AI providers:

import { runExperiment } from '@rankfor/dice-roller';

const result = await runExperiment({
  prompt: 'What project management tools do you recommend?',
  apiKeys: {
    geminiApiKey: process.env.GEMINI_API_KEY,
    openaiApiKey: process.env.OPENAI_API_KEY,
    grokApiKey: process.env.GROK_API_KEY,
  },
  iterations: 5,
  brandName: 'Asana',
});

// Messages ALL models agree on
console.log('Universal Messages:', result.universalCoreMessages);

// Brands mentioned by ALL models
console.log('Universal Brands:', result.universalBrands);

// Statistical analysis
console.log('Shannon Entropy:', result.statistics.shannonEntropy);
console.log('Gini Coefficients:', result.statistics.giniCoefficients);

Getting API Keys

Google Gemini

  1. Go to Google AI Studio
  2. Sign in with your Google account
  3. Click "Create API Key"
  4. Copy the key and store it securely

OpenAI

  1. Go to OpenAI Platform
  2. Sign in or create an account
  3. Navigate to API Keys in settings
  4. Click "Create new secret key"

xAI Grok

  1. Go to xAI Console
  2. Sign in with your X account
  3. Navigate to API section
  4. Generate a new API key

Environment Setup

We recommend storing API keys in environment variables:

# .env file
GEMINI_API_KEY=your_gemini_key_here
OPENAI_API_KEY=your_openai_key_here
GROK_API_KEY=your_grok_key_here

Security: Never commit API keys to version control. Add .env to your .gitignore file.

Next Steps

© 2025-2026 Rankfor.AI™ All rights reserved.

Ask AI about Rankfor.AI

Rankfor.AI sp. z o.o., Skarbowcow 23B, 53-025 Wroclaw, Poland

KRS: 0001190083 | NIP: 8993033605

We use cookies

We use essential cookies to make our site work. With your consent, we may also use analytics cookies to understand how you use our tools (like the Dice Roller) so we can improve them. Learn more