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
- 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
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.
| Mode | 10 experts | 20 experts | 30 experts |
|---|---|---|---|
| Quick Pulse | 15 | 30 | 45 |
| Expert Review | 30 | 60 | 90 |
| Deep Review | 35 | 70 | 105 |
More than one round: multiply by the number of rounds, then add 50 credits.
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"
}| Field | Takes |
|---|---|
| content | Required. The text to test. |
| contentType | Optional, default "youtube". One of: youtube, instagram, twitter, linkedin, ad_copy. |
| mode | Optional, default "expert_review". One of: quick_pulse, expert_review, deep_simulation. |
| panelSize | Optional, default 20. One of: 10, 20, 30. |
| rounds | Optional, default 1. From 1 to 5. |
| targetScore | Optional. From 1 to 10: stop early once a version reaches it. |
| context | Optional. targetAudience, niche, tone and goal, each a short string. |
| webhookUrl | Optional. 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
}
}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
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 payloadError 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 }
}
}| HTTP | Code | When |
|---|---|---|
| 400 | invalid_request | Malformed JSON or missing required fields |
| 401 | unauthorized | Missing, invalid, or revoked API key |
| 402 | insufficient_credits | Not enough credits for this evaluation |
| 404 | not_found | Test run not found or not owned by you |
| 422 | validation_error | Invalid parameters (contentType, panelSize, etc.) |
| 429 | too_many_requests | More than 10 evaluations a minute, or 100 running at once |
| 500 | internal_error | Unexpected server error |
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)