Developers

API documentation

Submit content for expert panel evaluation programmatically. Get scores, improvement suggestions, and optimized variants via a simple REST API.

On this page

Authentication

All API requests require an API key passed in the Authorization header. Generate API keys from your API keys settings.

Authorization header

Authorization: Bearer rfnd_live_YOUR_KEY
Security notes:
  • API keys are shown once at creation — save them securely
  • Only pass keys via the Authorization header, never in URLs
  • Revoked keys are rejected immediately
Back to contents

Credit costs

Credits are charged upfront when you submit an evaluation. If an evaluation fails, you only pay for rounds that produced results; the rest is refunded automatically, and creditsRefunded tells you whether any came back.

Credits per evaluation, by mode and panel size
Mode10 experts20 experts30 experts
Quick Pulse153045
Expert Review306090
Deep Review3570105

More than one round: multiply by the number of rounds, then add 50 credits.

Back to contents

Endpoints

POST/api/v1/evaluate

Submit content for evaluation. Returns a testRunId for polling.

Request body

Request body (JSON)

{
  "content": "10 Morning Habits That Changed My Life",
  "contentType": "youtube",
  "mode": "expert_review",
  "panelSize": 20,
  "rounds": 1,
  "targetScore": 8.0,
  "context": {
    "targetAudience": "25–35 year old professionals",
    "niche": "productivity",
    "tone": "authentic",
    "goal": "maximize CTR"
  },
  "webhookUrl": "https://example.com/refynd-webhook"
}
Request fields
FieldTakes
contentRequired. The text to test.
contentTypeOptional, default "youtube". One of: youtube, instagram, twitter, linkedin, ad_copy.
modeOptional, default "expert_review". One of: quick_pulse, expert_review, deep_simulation.
panelSizeOptional, default 20. One of: 10, 20, 30.
roundsOptional, default 1. From 1 to 5.
targetScoreOptional. From 1 to 10: stop early once a version reaches it.
contextOptional. targetAudience, niche, tone and goal, each a short string.
webhookUrlOptional. An HTTPS URL that receives the results.

Response

200 OK

{
  "data": {
    "testRunId": "k57abc123def456",
    "status": "queued",
    "creditsCharged": 60,
    "estimatedDuration": "about 2–3 min"
  }
}

GET/api/v1/results/:testRunId

Poll for evaluation results. Returns progress while evaluating, full results when complete.

While evaluating

While evaluating

{
  "data": {
    "testRunId": "k57abc123def456",
    "status": "evaluating",
    "progress": { "completed": 12, "total": 20 }
  }
}

When complete

When complete

{
  "data": {
    "testRunId": "k57abc123def456",
    "status": "complete",
    "content": { "text": "...", "type": "youtube" },
    "scores": {
      "overall": 6.8,
      "clickRate": 0.55,
      "dimensions": [
        { "name": "Dimension 1", "score": 7.2 },
        { "name": "Dimension 2", "score": 6.5 }
      ]
    },
    "suggestions": [{
      "priority": 1,
      "dimension": "Area of improvement",
      "suggestion": "Specific actionable advice...",
      "rationale": "Why this matters for your content...",
      "impact": "high"
    }],
    "improvedVariants": [{
      "text": "An optimized version of your content...",
      "rank": 1,
      "predictedScore": 8.2,
      "principles": ["Principle 1", "Principle 2"]
    }],
    "panelSize": 20,
    "mode": "expert_review",
    "creditsCharged": 60,
    "completedAt": 1711324800000
  }
}

Tests with more than one round

When rounds > 1, the response includes an iterations object: each round's result and the best version.

With more than one round

"iterations": {
  "totalRounds": 3,
  "completedRounds": 2,
  "bestRound": 2,
  "earlyStopped": true,
  "chain": [
    { "round": 1, "content": "...", "overall": 6.8, "clickRate": 0.55 },
    { "round": 2, "content": "...", "overall": 8.6, "clickRate": 0.77 }
  ],
  "bestContent": "I Tried 10 Morning Habits...",
  "bestScore": 8.6,
  "bestClickRate": 0.77,
  "improvement": { "scoreChange": 1.8, "clickRateChange": 0.22 }
}

GET/api/v1/balance

Check your credit balance.

200 OK

{
  "data": {
    "credits": 1500
  }
}
Back to contents

Webhooks

Instead of polling, provide a webhookUrl when submitting an evaluation. Refynd will POST results to your URL when complete. The URL must be HTTPS on the standard port (443) and reach a public server; redirects aren't followed.

Headers

Webhook headers

X-Refynd-Signature: sha256=<hex>
X-Refynd-Timestamp: <unix_ms>
X-Refynd-Event: evaluation.complete
HMAC secret: Webhooks are signed with the SHA-256 hash of your API key. To verify, hash your raw API key with SHA-256 and use that as the HMAC secret:apiKeyHash = SHA256("rfnd_live_YOUR_KEY")

Signature verification (Node.js)

Node.js

const crypto = require("crypto");

// Compute this once from your raw API key:
// const apiKeyHash = crypto.createHash("sha256")
//   .update("rfnd_live_YOUR_KEY").digest("hex");

function verifyWebhook(body, signature, apiKeyHash) {
  const expected = crypto
    .createHmac("sha256", apiKeyHash)
    .update(body)
    .digest("hex");

  const received = signature.replace("sha256=", "");

  if (expected.length !== received.length || !crypto.timingSafeEqual(
    Buffer.from(expected), Buffer.from(received)
  )) {
    throw new Error("Invalid webhook signature");
  }

  // Check freshness with the signed timestamp inside the body
  // (the X-Refynd-Timestamp header is not covered by the signature)
  const payload = JSON.parse(body);
  if (Date.now() - payload.timestamp > 5 * 60 * 1000) {
    throw new Error("Webhook timestamp too old");
  }

  return payload;
}

Signature verification (Python)

Python

import hmac, hashlib, json, time

# Compute once from your raw API key:
# api_key_hash = hashlib.sha256(b"rfnd_live_YOUR_KEY").hexdigest()

def verify_webhook(body: bytes, signature: str,
                   api_key_hash: str) -> dict:
    expected = hmac.HMAC(
        api_key_hash.encode(), body, hashlib.sha256
    ).hexdigest()
    received = signature.replace("sha256=", "")

    if not hmac.compare_digest(expected, received):
        raise ValueError("Invalid webhook signature")

    # Check freshness with the signed timestamp inside the body
    # (the X-Refynd-Timestamp header is not covered by the signature)
    payload = json.loads(body)
    if time.time() * 1000 - payload["timestamp"] > 5 * 60 * 1000:
        raise ValueError("Webhook timestamp too old")

    return payload
Delivery: 3 attempts with backoff (+30s, +5min). Webhooks must respond within 10 seconds with a 2xx status.
Back to contents

Error codes

All errors return a consistent JSON format:

Error format

{
  "error": {
    "code": "insufficient_credits",
    "message": "Insufficient credits for this evaluation",
    "details": { "required": 300, "balance": 150 }
  }
}
API error codes
HTTPCodeWhen
400invalid_requestMalformed JSON or missing required fields
401unauthorizedMissing, invalid, or revoked API key
402insufficient_creditsNot enough credits for this evaluation
404not_foundTest run not found or not owned by you
422validation_errorInvalid parameters (contentType, panelSize, etc.)
429too_many_requestsMore than 10 evaluations a minute, or 100 running at once
500internal_errorUnexpected server error
Back to contents

Full example (Python)

Python

import requests, time

API_KEY = "rfnd_live_YOUR_KEY"
BASE = "https://refynd.ca/api/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

# 1. Submit evaluation
resp = requests.post(f"{BASE}/evaluate", json={
    "content": "10 Morning Habits That Changed My Life",
    "contentType": "youtube",
    "mode": "expert_review",
    "panelSize": 20,
}, headers=HEADERS)
test_run_id = resp.json()["data"]["testRunId"]

# 2. Poll for results
while True:
    result = requests.get(
        f"{BASE}/results/{test_run_id}", headers=HEADERS
    ).json()["data"]

    if result["status"] == "complete":
        print(f"Score: {result['scores']['overall']}")
        for v in result["improvedVariants"]:
            print(f"  Variant: {v['text']} (predicted: {v['predictedScore']})")
        break
    elif result["status"] == "failed":
        print(f"Evaluation failed (credits refunded: {result['creditsRefunded']})")
        break

    print(f"Progress: {result['progress']['completed']}/{result['progress']['total']}")
    time.sleep(5)
Back to contents

Questions about the API?

Write to support@refynd.ca — a person replies.