GUIDES

Text classification in Python: labels, requests and review

A Python script calls a classification endpoint the way it calls any JSON API. What decides the quality is not the HTTP client but the labels you send, the threshold you set, and what you do with a row the model was unsure about.

JEV / DECISION LABYOUR RULES. YOUR LABELS.
Remove passwords, payment details, and unnecessary personal information. 85%
OUTPUT / JSON

Your decision

Run a decision or open the labeled sample to see the result here.

A high score is not a guarantee. Keep a person in control of consequential actions.

View API example →
Label a held-out set, compare model decisions with it, and review errors before changing a workflow.
Label a held-out set, compare model decisions with it, and review errors before changing a workflow.

Run a complete Python example

Install the HTTP client with python -m pip install requests. In your server environment, set JEV_API_KEY to an account API key and make sure the account holds decision credits. Set JEV_IDEMPOTENCY_KEY once for this logical request: generate a UUID with python -c "import uuid; print(uuid.uuid4())" and keep that value for retries. Neither value belongs in browser code or a public repository.

Save the example as classify.py and run python classify.py. The text and labels are defined, HTTP errors stop execution before parsing a success response, and the output prints the proposed classification and review flag. It does not route a ticket or modify another system. Use a new saved request key when you deliberately change the input; keep the old key and exact payload when a network outcome is unknown.

import json
import os
import requests

api_key = os.environ["JEV_API_KEY"].strip()
request_key = os.environ["JEV_IDEMPOTENCY_KEY"].strip()
if not api_key:
    raise ValueError("JEV_API_KEY must not be empty")
if not 8 <= len(request_key) <= 100:
    raise ValueError("JEV_IDEMPOTENCY_KEY must be 8-100 characters")

payload = {
    "text": "I was charged twice for the same order.",
    "instructions": "Choose the team responsible for this request.",
    "labels": ["Billing", "Support", "Access"],
    "threshold": 0.85,
}
response = requests.post(
    "https://jevapi.pro/api/v1/decisions",
    headers={
        "Authorization": "Bearer " + api_key,
        "Idempotency-Key": request_key,
    },
    json=payload,
    timeout=(5, 30),
)
response.raise_for_status()
answer = response.json()
print(json.dumps({
    "id": answer["id"],
    "choice": answer["choice"],
    "needsReview": answer["needsReview"],
}, ensure_ascii=False, indent=2))

Request contract, field by field

Read the answer as evidence, not as a verdict

A new decision answers 201 with id, choice, confidence, probabilities, needsReview, model and latencyMs, and an account request also returns the credits left. confidence is null when the model omits it, and needsReview is true in that case and whenever the reported confidence falls below your threshold.

probabilities is checked for domain and bounds only. Nothing promises that its values sum to one or that the largest one matches the returned label, so read choice instead of sorting a dictionary to guess the answer, and treat a label outside your list as a refusal rather than a fallback.

Confidence and review thresholds

Process a file without duplicate charges

For a CSV, send rows sequentially and retain each logical request key alongside a stable source record ID, the exact payload and its outcome. Do not use the row number as identity: inserting a row in a later export changes the positions. A changed rule or changed input is a new logical request, not a retry.

A timeout, disconnected connection or generic gateway 502/503 does not prove that nothing was charged. Stop automatic routing and retry the same payload with the same key to recover a completed result. A 409 request_running keeps that key; an authoritative 409 request_failed confirms the recorded failure and allows a new key after fixing the cause. Do not replace the key merely because a proxy returned an error.

A 402 means insufficient credits. A 401 can mean a missing, revoked or expired-access API key; check account access before retrying. A 429 means a rate or allowance limit: respect Retry-After when present and use a bounded backoff, not an endless loop. This example intentionally sends once and raises errors so your job runner can decide what to retry. If you do not need a script, the batch workspace already preserves row states and exports results without including source text.

Batch classification and exports · Open the batch workspace · Error codes and recovery

Choose an API or a model you host

A scikit-learn or transformer model can be economical when labels are stable, you have suitable training data, and you can operate inference. It is not free per row: compute, maintenance, evaluation and human review still cost money. Compare measured total cost and latency on your own workload rather than assuming either option is always cheaper.

An API fits when you want to supply a task and labels without serving a model yourself. Its tradeoffs include network dependency, provider processing of submitted text and usage charges. A local model may better fit an offline or strict data-residency requirement. Neither option turns a confidence score into a guarantee.

Before automating, compare the same held-out examples, including ambiguous messages, against labels people reviewed. Start by recording suggestions. Route only the cases your evaluation supports, and keep needsReview results in an existing human queue.

Evaluate a classification rule

Try a decision ↗

Continue your workflow

Ask about plans & usage

Find a product answer

Answers come from the published product guide. For account-specific questions, contact support.

Contact
DAILY BONUS

2 free credits, every day

Claim 2 free credits each UTC day — 14 across seven claims. No purchase needed. Credits do not expire.

    Resets at 00:00 UTC. No streak required.

    Try a decision →

    Take the next decision into your workspace.

    1 anonymous attempt per day · 20 signup credits · No card for the trial

    Sign in ↗

    Tell us what you need

    Describe the workflow you want to classify, the volume you expect, and the outcome you need. We reply by email.

    10–2,000 characters. Never include passwords, API keys, or payment details.