API tutorials

Python example

Use Python requests for paginated manifests, individual claims, and BenchDX or RobustDX response submission.

Copy these blocks into one Python file in order. Install requests, then supply a target function that accepts prompt text and returns answer text. Both evaluation types share the manifest and claim steps. Use the account buttons above to select the request configuration before copying the code.

Choose the account context

Environment variablePersonal accountOrganization account
AIDX_PATPAT created in Personal accountPAT created in the selected organization
AIDX_TENANT_IDNot needed; the Personal account example ignores this variableRequired: the selected organization's tenant ID
AIDX_WORKSPACE_IDThe evaluation's personal workspace IDThe evaluation's organization workspace ID
AIDX_EVALUATION_IDThe Personal evaluation's positive integer IDThe organization evaluation's positive integer ID

Configure requests and check errors

Request configuration and response validation · Personal accountPython
import os
from urllib.parse import urlsplit

import requests

BASE_URL = os.environ.get("AIDX_BASE_URL", "https://trial.aidx.pro").rstrip("/")
EVALUATION_ID = int(os.environ["AIDX_EVALUATION_ID"])
if not 0 < EVALUATION_ID <= 2147483647:
    raise ValueError("AIDX_EVALUATION_ID must be a positive 32-bit integer")

session = requests.Session()
session.headers.update({
    "Authorization": f"Bearer {os.environ['AIDX_PAT']}",
    "X-Workspace-Id": os.environ["AIDX_WORKSPACE_ID"],
})


def api_request(method, url, **kwargs):
    # Never forward the PAT to another origin via pagination or redirects.
    if urlsplit(url)[:2] != urlsplit(BASE_URL)[:2]:
        raise ValueError("Unexpected API origin")
    response = session.request(
        method, url, timeout=30, allow_redirects=False, **kwargs
    )
    request_id = response.headers.get("X-Request-Id", "unknown")
    try:
        result = response.json()
    except ValueError:
        raise RuntimeError(
            f"HTTP {response.status_code}; request={request_id}; non-JSON response"
        ) from None
    if not isinstance(result, dict):
        raise RuntimeError(f"Invalid API envelope; request={request_id}")
    request_id = result.get("code") or request_id
    if not 200 <= response.status_code < 300 or result.get("success") is not True:
        error_type = response.headers.get("X-AIDX-Error-Type", "unknown")
        raise RuntimeError(
            f"HTTP {response.status_code}; type={error_type}; "
            f"request={request_id}; {result.get('message', 'Request failed')}"
        )
    return result["data"]

Read every manifest page

iter_tracesPython
def iter_traces(evaluation_id):
    url = f"{BASE_URL}/api/evaluation/trace-manifests/{evaluation_id}"
    while url:
        page = api_request("GET", url)
        yield from page["items"]
        # Follow the server's URL unchanged; no page-number calculation.
        url = page.get("nextLink")

This yields trace metadata. Prompt text is retrieved separately. The request helper refuses another origin and disables redirects so pagination cannot forward your PAT to another server.

Claim a frozen prompt

claim_tracePython
def claim_trace(evaluation_id, trace_id):
    return api_request(
        "POST",
        f"{BASE_URL}/api/evaluation/trace-claims",
        json={"evaluationId": evaluation_id, "traceId": trace_id},
    )

Submit an answer as form data

submit_responsePython
def submit_response(evaluation_id, trace_id, model_response, adversarial=False):
    if not isinstance(model_response, str) or not model_response.strip():
        raise ValueError("The target model must return non-empty text")
    endpoint = "adv-response" if adversarial else "response"
    response_field = "advResponse" if adversarial else "llmResponse"
    api_request(
        "POST",
        f"{BASE_URL}/api/evaluation/{endpoint}",
        data={
            "evaluationId": evaluation_id,
            "traceId": trace_id,
            response_field: model_response,
        },
    )
EvaluationResponse endpointForm field
BenchDX/api/evaluation/responsellmResponse
RobustDX/api/evaluation/adv-responseadvResponse

json= is used for claims; data= is used for response forms. Do not interchange them.

Connect your target function

Sequential execution for unclaimed tracesPython
def run_evaluation(call_target_model, adversarial=False):
    for trace in iter_traces(EVALUATION_ID):
        if trace["status"] != "PROCESSING":
            continue
        claim = claim_trace(EVALUATION_ID, trace["traceId"])
        if claim["alreadyClaimed"]:
            continue
        model_response = call_target_model(claim["prompt"])
        submit_response(
            EVALUATION_ID, trace["traceId"], model_response, adversarial
        )


# Supply a function that accepts a prompt and returns your model's text.
# BenchDX: run_evaluation(call_target_model)
# RobustDX: run_evaluation(call_target_model, adversarial=True)

Pass your target integration to run_evaluation(call_target_model) for BenchDX, or set adversarial=True for RobustDX. Keep target credentials inside that integration.