Skip to main content

Overview

This guide will walk you through integrating Raily into your application. By the end, you’ll have:
  • Connected your content to Raily
  • Created your first access policy
  • Made your first API call
  • Viewed analytics in the dashboard
Prerequisites: You’ll need a Raily account to follow this guide. Sign up here if you haven’t already.

Step 1: Get Your API Keys

After signing up, navigate to the API Keys section in your dashboard.
1

Access the Dashboard

Log in to your Raily dashboard at dashboard.raily.ai
2

Generate API Keys

Click Create API Key and give it a descriptive name like “Development” or “Production”
3

Copy Your Keys

You’ll receive two keys:
  • Public Key: Safe to use in client-side code
  • Secret Key: Keep this secure, use only in server-side code
Never expose your secret key in client-side code, public repositories, or logs. Treat it like a password.

Step 2: Install the SDK

Choose your preferred language:
npm install @raily/sdk

Step 3: Initialize the Client

import Raily from '@raily/sdk';

const raily = new Raily({
  apiKey: process.env.RAILY_SECRET_KEY,
});

Step 4: Add Your First Content

Let’s register some content with Raily. This creates a reference that AI systems can request access to.
const content = await raily.content.create({
  externalId: "article-123",
  title: "Understanding AI Content Licensing",
  type: "article",
  source: "https://example.com/articles/ai-licensing",
  metadata: {
    author: "Jane Smith",
    publishedAt: "2024-01-15",
    category: "Technology",
    wordCount: 2500
  }
});

console.log(`Content registered: ${content.id}`);
// Output: Content registered: cnt_abc123xyz
Use externalId to link Raily content to your existing content management system. This makes it easy to sync and manage content across platforms.

Step 5: Create an Access Policy

Policies control how AI systems can access your content. Let’s create a simple policy that allows access to licensed partners.
const policy = await raily.policies.create({
  name: "Licensed Partners Only",
  description: "Allow access to partners with valid licenses",
  rules: [
    {
      action: "allow",
      conditions: {
        hasValidLicense: true,
        licenseType: ["enterprise", "professional"]
      },
      rateLimit: {
        requests: 1000,
        period: "hour"
      }
    },
    {
      action: "deny",
      conditions: { default: true },
      message: "A valid license is required to access this content"
    }
  ]
});

// Apply the policy to your content
await raily.content.update(content.id, {
  policyId: policy.id
});

Step 6: Test Content Access

Now let’s simulate an AI system requesting access to your content:
// Simulate a request from an AI partner
const accessRequest = await raily.access.check({
  contentId: content.id,
  requesterId: "partner_openai",
  context: {
    purpose: "training",
    model: "gpt-4"
  }
});

if (accessRequest.allowed) {
  console.log("Access granted!");
  console.log(`Content URL: ${accessRequest.contentUrl}`);
  console.log(`Expires: ${accessRequest.expiresAt}`);
} else {
  console.log(`Access denied: ${accessRequest.reason}`);
}

Step 7: View Analytics

Check your dashboard to see real-time analytics, or fetch them programmatically:
const analytics = await raily.analytics.usage({
  contentId: content.id,
  period: "7d"
});

console.log(`Total requests: ${analytics.totalRequests}`);
console.log(`Allowed: ${analytics.allowed}`);
console.log(`Denied: ${analytics.denied}`);
console.log(`Top requesters:`, analytics.topRequesters);

// Example output:
// Total requests: 1,247
// Allowed: 1,102
// Denied: 145
// Top requesters: [
//   { id: "partner_openai", requests: 823 },
//   { id: "partner_anthropic", requests: 279 }
// ]

Complete Example

Here’s a complete example bringing everything together:
JavaScript
import Raily from '@raily/sdk';

const raily = new Raily({
  apiKey: process.env.RAILY_SECRET_KEY,
});

async function setupContentMonetization() {
  // 1. Register content
  const content = await raily.content.create({
    externalId: "premium-report-2024",
    title: "2024 AI Industry Report",
    type: "report",
    source: "https://example.com/reports/ai-2024",
    metadata: {
      price: 499,
      pages: 150,
      category: "Research"
    }
  });

  // 2. Create tiered access policy
  const policy = await raily.policies.create({
    name: "Tiered Access",
    rules: [
      {
        action: "allow",
        priority: 1,
        conditions: { licenseType: "enterprise" },
        permissions: ["full_access", "commercial_use"]
      },
      {
        action: "allow",
        priority: 2,
        conditions: { licenseType: "professional" },
        permissions: ["full_access"],
        rateLimit: { requests: 500, period: "day" }
      },
      {
        action: "allow",
        priority: 3,
        conditions: { licenseType: "basic" },
        permissions: ["preview_only"],
        rateLimit: { requests: 50, period: "day" }
      },
      {
        action: "deny",
        conditions: { default: true }
      }
    ]
  });

  // 3. Apply policy
  await raily.content.update(content.id, { policyId: policy.id });

  // 4. Set up webhook for access events
  await raily.webhooks.create({
    url: "https://api.example.com/raily/events",
    events: ["access.granted", "access.denied", "content.accessed"]
  });

  console.log("Content monetization setup complete!");
  return { content, policy };
}

setupContentMonetization();

Next Steps

Congratulations! You’ve successfully integrated Raily. Your content is now protected, tracked, and ready to generate revenue from AI applications.