Skip to main content

Official Python SDK for the OpenTrain API — human verification, evaluation, and labeling for AI teams.

Project description

opentrain-ai

Official Python SDK for the OpenTrain API — human verification, evaluation, and labeling for AI teams.

Push model outputs — synthetic rows, eval responses, RL episodes — and get human verdicts back. Use verify.reward as a human reward function inside a training loop.

pip install opentrain-ai   # imports as `opentrain`
  • Python ≥ 3.10, fully typed (py.typed), Pydantic v2 models, httpx transport
  • Sync (OpenTrain) and async (AsyncOpenTrain) clients with the same surface
  • Apache-2.0

Quickstart

Create an API token at app.opentrain.ai → Settings → Developer, then:

from opentrain import OpenTrain

client = OpenTrain()  # reads OPENTRAIN_API_TOKEN

# Push a batch of model outputs for human verification
created = client.verify.batches.create(
    items=[
        {"prompt": "What is 2+2?", "response": "4"},
        {"prompt": "Capital of France?", "response": "Lyon"},
    ],
)
print(created.batch.batch_id, created.batch.status)

# Read verdicts back (ACCEPT / FIX / REJECT per item)
results = client.verify.batches.results(created.batch.batch_id)
print(results.summary)

Human reward function

# Synchronous LLM-judge scoring (bring your own OpenRouter key in Quality settings)
scored = client.verify.reward.judge_now(
    items=[{"prompt": "2+2?", "response": "4"}],
    rubric=["The response is factually correct."],
)
print(scored.rewards[0].score)  # 0..1

# Asynchronous human scoring — poll or subscribe to verify.reward.completed
queued = client.verify.reward.human_async(
    items=[{"prompt": "2+2?", "response": "5"}],
    rubric=["The response is factually correct."],
    training_run_id="run_...",  # optional: links verdicts to your training run
)
rewards = client.verify.reward.get(queued.batch_id)

Async

import asyncio
from opentrain import AsyncOpenTrain

async def main() -> None:
    async with AsyncOpenTrain() as client:
        created = await client.verify.batches.create(
            items=[{"prompt": "p", "response": "r"}]
        )
        print(created.batch.batch_id)

asyncio.run(main())

Webhooks

from opentrain import verify_webhook_signature

ok = verify_webhook_signature(
    secret="whsec_...",                      # returned once at webhook creation
    raw_body=request_body_text,              # verify BEFORE parsing JSON
    signature_header=headers["X-OpenTrain-Signature"],
)

Other surfaces

client.label.launch(...), client.evaluate.launch(...), client.synthetic_runs.create(...) / .push_rows(...), client.training_runs.register_external(...), client.benchmarks.list(), client.webhooks.create(...). These return dict payloads matching the OpenAPI document at /api/public/v1/openapi.

Errors

Non-2xx responses raise OpenTrainAPIError with status, code (e.g. PAYMENT_REQUIRED), request_id, and details.

Development

scripts/test.sh   # venv + mypy --strict + pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opentrain_ai-0.1.0.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opentrain_ai-0.1.0-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file opentrain_ai-0.1.0.tar.gz.

File metadata

  • Download URL: opentrain_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for opentrain_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 31b69feeb990e67cc6f638a421a516aecde5e55c24baecc573cfeac559a2b9d6
MD5 6cc42b40506a9aceb6d8aa89ba8a4f10
BLAKE2b-256 bada2c2645d865d9bd14d96042fde707f6c70c4f3b4a7c13932343787f702890

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentrain_ai-0.1.0.tar.gz:

Publisher: pypi-publish.yml on OpenTrain-AI/OpenTrain-Platform-Monorepo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opentrain_ai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: opentrain_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for opentrain_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bc92370a8f01f9ab61e3ea29ed98d554ca8a9e3772e101a71987ff031b1007e
MD5 688e5dd32ec145230f0c19821b92998b
BLAKE2b-256 623ce78bde235b38846141b5f9655620200e131d97815bc99ea8f59ac46fa468

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentrain_ai-0.1.0-py3-none-any.whl:

Publisher: pypi-publish.yml on OpenTrain-AI/OpenTrain-Platform-Monorepo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page