VeritellAccount

Developers

Use your API key to call the streaming evaluation endpoint and read NDJSON events line-by-line.

Get API keyAPI overview

Python (requests) - NDJSON stream

import os
import json
import requests

# Define the API endpoint URL
API_BASE_URL = "https://veritell.ai"

API_KEY = os.environ.get("VERITELL_API_KEY", "")
if not API_KEY:
    raise RuntimeError("VERITELL_API_KEY is not set")

EVALUATE_API = f"{API_BASE_URL}/api/evaluate/stream"

payload = {
    "prompt": "Explain the benefits of using renewable energy sources.",
    "primary_model": "gpt-4o",
    "judges": ["gpt-4o-mini", "grok-3-latest"],
    # Optional: if you want to skip primary generation and evaluate a provided output:
    # "model_output": "..."
}

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
    "Accept": "application/x-ndjson",
}

try:
    response = requests.post(
        EVALUATE_API,
        headers=headers,
        json=payload,
        stream=True,
        timeout=60,
    )

    print("POST:", EVALUATE_API)
    print("status:", response.status_code)
    print("content-type:", response.headers.get("content-type", ""))

    # If the server returns an error, print the body for diagnostics.
    if response.status_code >= 400:
        body_preview = response.text[:4000]
        print("error body (first 4000 chars):")
        print(body_preview)
        response.raise_for_status()

    print("Streaming response:")
    for line in response.iter_lines(decode_unicode=True):
        if not line:
            continue
        try:
            data = json.loads(line)
            print(json.dumps(data, indent=2))
        except json.JSONDecodeError:
            print(line)

except requests.exceptions.RequestException as e:
    print(f"Error: {e}")

Set VERITELL_API_KEY in your environment, then run the script to stream evaluation events.

Node.js (fetch) - NDJSON stream

/**
 * Node.js (fetch) - NDJSON stream
 * Requires Node 18+ (built-in fetch), or bring your own fetch polyfill.
 */
const API_BASE_URL = process.env.VERITELL_API_BASE_URL || "https://veritell.ai";
const API_KEY = process.env.VERITELL_API_KEY;

if (!API_KEY) {
  throw new Error("VERITELL_API_KEY is not set");
}

const url = `${API_BASE_URL}/api/evaluate/stream`;

const payload = {
  prompt: "Explain the benefits of using renewable energy sources.",
  primary_model: "gpt-4o",
  judges: ["gpt-4o-mini", "grok-3-latest"],
  // Optional:
  // model_output: "..."
};

const res = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
    Accept: "application/x-ndjson",
  },
  body: JSON.stringify(payload),
});

console.log("POST:", url);
console.log("status:", res.status);
console.log("content-type:", res.headers.get("content-type") || "");

if (!res.ok) {
  const text = await res.text();
  console.log("error body (first 4000 chars):");
  console.log(text.slice(0, 4000));
  process.exit(1);
}

if (!res.body) {
  throw new Error("No response body");
}

const decoder = new TextDecoder();
let buffer = "";

for await (const chunk of res.body) {
  buffer += decoder.decode(chunk, { stream: true });

  let idx;
  while ((idx = buffer.indexOf("\n")) !== -1) {
    const line = buffer.slice(0, idx).trim();
    buffer = buffer.slice(idx + 1);

    if (!line) continue;

    try {
      const event = JSON.parse(line);
      console.log(JSON.stringify(event, null, 2));
    } catch {
      console.log(line);
    }
  }
}

Requires Node 18+. Set VERITELL_API_KEY and optionally VERITELL_API_BASE_URL.

cURL - NDJSON stream

# cURL - NDJSON stream
# macOS/Linux:
export VERITELL_API_KEY="YOUR_API_KEY"

# Windows PowerShell:
# $env:VERITELL_API_KEY="YOUR_API_KEY"

curl -N -X POST https://veritell.ai/api/evaluate/stream \
  -H "Authorization: Bearer $VERITELL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/x-ndjson" \
  -d '{
    "prompt": "Explain the benefits of using renewable energy sources.",
    "primary_model": "gpt-4o",
    "judges": ["gpt-4o-mini", "grok-3-latest"]
  }'

Use -N to disable buffering so events print as they arrive.