APIs and capabilities

TypeSafe API Guide

Use the Jev System One API for decisions, classification, scoring, image recognition and Box localization, with cURL, Python and Node.js examples.

Jev evaluates text, structured data and images for moderation, ticket classification, scoring and object localization. Put your content in state and your questions in questions to receive structured answers.

Gateway endpoint: POST https://api.zhenapi.ai/v1/systemone. Send a nonstreaming JSON request and receive a complete JSON response. No messages, prompt or stream parameter is needed.

1. Create a key and choose a model

Open the API Keys page and create or select a key in a TypeSafe group. Set the following environment variable in the terminal running your script. Keep real keys out of Git and browser-side code.

macOS / Linux / WSL · Bash
1export TYPESAFE_API_KEY="YOUR_TYPESAFE_GROUP_API_KEY"
Windows · PowerShell
1$env:TYPESAFE_API_KEY="YOUR_TYPESAFE_GROUP_API_KEY"
Model IDGateway recommendationImages / Box
jev-latestCurrently maps to jev-1.14.0 on this gateway; the mapping may change.Depends on the currently mapped model.
jev-1.14.0Use for a fixed version or Box support.Images and Box supported.
jev-1.13.0Keep the older model behavior, with long context support.Images supported; Box not supported.

Model aliases follow gateway settings and may differ from the official service. For reproducibility, use a full model version and record the returned model. Examples use English questions and criteria. Validate behavior against your own data.

Image input and long context are enabled by default. You can use the examples below without extra configuration.

Request fields and four question types

model, state, questions are required. state can be a string, object or array. questions must be a nonempty object with one key per question. Write the actual question in instructions; question IDs only identify results. For images, include top-level assets.

typePurposecriteria formatReading the result
noulYes/no decisions, moderation and content checksOptional; true / false entries can describe the decision criteria.noul is a probability from 0 to 1, not a boolean. A value near 0.5 indicates uncertainty.
choiceClassification, routing and selecting one optionObject mapping option IDs to descriptions; 1–255 options.choice is the selected option ID. The response also includes confidence and probabilities for all options.
scoreRating, ranking and prioritizationOrdered array with 1–10 levels, indexed from 0.score is the probability-weighted average of the levels and may be fractional. The response also includes confidence, legend and probabilities.
boxLocate one specified object in an imageNo criteria required. Describe the target and image in instructions. Supported only by 1.14.0.box contains left / top / right / bottom. confidence may be null. Each question returns one box.

Multiple questions can share the same state in one request. If a later step needs an earlier answer, issue a new request from your application. Confidence and probability are different metrics; validate your own decision thresholds.

2. Text: decisions, classification and scoring in one request

The example asks three questions about one refund message. Keys in questions are your result IDs; answers uses the same keys. Questions are evaluated independently and cannot reference answers to other questions in the same request.

1curl --fail-with-body --max-time 120 "https://api.zhenapi.ai/v1/systemone" \
2 -H "Authorization: Bearer $TYPESAFE_API_KEY" \
3 -H "Content-Type: application/json" \
4 --data-binary '{
5 "model": "jev-latest",
6 "state": {
7 "message": "I was charged twice. Please refund the duplicate charge today."
8 },
9 "questions": {
10 "needs_refund": {
11 "type": "noul",
12 "instructions": "Is the customer requesting a refund?",
13 "criteria": {
14 "true": "Requests a refund.",
15 "false": "Does not request a refund."
16 }
17 },
18 "department": {
19 "type": "choice",
20 "instructions": "Which team should handle this message?",
21 "criteria": {
22 "billing": "Payment and refund issues.",
23 "technical": "Product faults and technical issues.",
24 "other": "Other requests."
25 }
26 },
27 "urgency": {
28 "type": "score",
29 "instructions": "How urgently does the customer need help?",
30 "criteria": [
31 "No urgency expressed.",
32 "Wants help soon.",
33 "Needs help today."
34 ]
35 }
36 }
37}'

The cURL example uses Bash / WSL. The Python 3 example uses only the standard library: save it as typesafe.py and run python3 typesafe.py (or py typesafe.py on Windows). Node.js 18+ needs no extra packages. Set the environment variable above, then run examples in the same terminal.

3. Image input and Box localization

Place an image.png containing a red rectangle in the working directory. The example encodes it as Base64, references it in state.photo with a random UUID, and asks both whether the object exists and where it is. Both models support image input; the Box example uses jev-1.14.0.

1import json
2import os
3import urllib.error
4import urllib.request
5 
6API_URL = "https://api.zhenapi.ai/v1/systemone"
7 
8def evaluate(body):
9 request = urllib.request.Request(
10 API_URL,
11 data=json.dumps(body, ensure_ascii=False).encode("utf-8"),
12 headers={
13 "Authorization": "Bearer " + os.environ["TYPESAFE_API_KEY"],
14 "Content-Type": "application/json",
15 },
16 method="POST",
17 )
18 try:
19 with urllib.request.urlopen(request, timeout=120) as response:
20 result = json.load(response)
21 except urllib.error.HTTPError as error:
22 print("HTTP", error.code, error.read().decode("utf-8", errors="replace"))
23 raise
24 print(json.dumps(result, ensure_ascii=False, indent=2))
25 return result
26 
27import base64
28import uuid
29from pathlib import Path
30 
31image_ref = str(uuid.uuid4())
32body = {
33 "model": "jev-1.14.0",
34 "state": {"photo": image_ref},
35 "assets": {
36 image_ref: {
37 "type": "image",
38 "format": "png",
39 "data_base64": base64.b64encode(Path("image.png").read_bytes()).decode("ascii"),
40 }
41 },
42 "questions": {
43 "present": {"type": "noul", "instructions": "Is there a red rectangle in the image?"},
44 "target": {"type": "box", "instructions": "Locate the red rectangle in the image."},
45 },
46}
47result = evaluate(body)
48if result["answers"]["present"]["noul"] >= 0.8:
49 target = result["answers"]["target"]
50 print("Normalized coordinates:", target["box"])
51 print("Localization confidence (may be None):", target["confidence"])
52else:
53 print("Object presence probability is too low; ignore the Box coordinates.")

For image decisions or classification only, remove the target Box question and use jev-1.13.0 if desired. For JPEG, update both the filename and format to jpg / jpeg. The 0.8 threshold is illustrative; validate a threshold against your own samples.

Preparing and sending images

  • Only static PNG / JPEG images are supported. Width and height must each be 280–1568 pixels. Resize or pad images as needed, and correct their orientation before encoding.
  • The official limits are 16 MiB per image file and 32 MiB per request body. Processed images and expanded references have additional limits. The gateway may enforce a smaller limit.
  • data_base64 must be plain Base64 without a data:image/... prefix or line breaks. format must be lowercase png, jpg or jpeg.
  • Give each image a unique UUID in assets and reference it from a value in state, instructions or criteria. An unreferenced asset fails validation. Repeated references increase expanded input size. Put a shared image reference in state only once.
  • This gateway uses JSON + Base64. Official multipart uploads, automatic SDK image uploads and compressed bodies cannot be used directly. Image URLs are not downloaded automatically; read the image bytes first.

Using Box coordinates

Coordinates range from 0 to 1, with the origin at the top-left corner. For a submitted image of width W and height H: x1 = left × W, y1 = top × H, x2 = right × W, y2 = bottom × H. Round and clamp coordinates to the image bounds before cropping. If you resized or cropped the input, convert the coordinates back to the original image.

Box may return coordinates even when the object is absent; it has no separate not-found result. The example checks presence with noul before accepting a box. confidence can be null, which does not mean zero. Use separate, specific Box questions for multiple targets. Images and Box are currently marked experimental by the provider.

4. Long context: read a local file

Save UTF-8 text as document.txt. This example uses jev-1.13.0 to check whether a contract allows early termination; jev-1.14.0 also works. The file contents are sent as state. The model does not automatically read a URL or local path.

1import json
2import os
3import urllib.error
4import urllib.request
5 
6API_URL = "https://api.zhenapi.ai/v1/systemone"
7 
8def evaluate(body):
9 request = urllib.request.Request(
10 API_URL,
11 data=json.dumps(body, ensure_ascii=False).encode("utf-8"),
12 headers={
13 "Authorization": "Bearer " + os.environ["TYPESAFE_API_KEY"],
14 "Content-Type": "application/json",
15 },
16 method="POST",
17 )
18 try:
19 with urllib.request.urlopen(request, timeout=120) as response:
20 result = json.load(response)
21 except urllib.error.HTTPError as error:
22 print("HTTP", error.code, error.read().decode("utf-8", errors="replace"))
23 raise
24 print(json.dumps(result, ensure_ascii=False, indent=2))
25 return result
26 
27from pathlib import Path
28 
29body = {
30 "model": "jev-1.13.0",
31 "state": Path("document.txt").read_text(encoding="utf-8"),
32 "questions": {
33 "early_termination": {
34 "type": "noul",
35 "instructions": "Does this contract allow either party to terminate it early?",
36 }
37 },
38}
39result = evaluate(body)
40print("Input tokens:", result["usage"]["input_tokens"])

Long context is enabled by default: both the whole request and state plus one question are limited to 262K tokens, with unchanged pricing for both models. A local gateway test succeeded with 130,331 input tokens on 1.13.0; the full 262K limit has not been tested. Input includes state, questions and images, not just file characters. Split oversized input into multiple requests.

5. Usage and billing

The response field usage.input_tokens includes input usage for text, questions and images; usage.output_tokens reports output usage. Billing is currently based on input tokens, with free output. Images have no separate surcharge, and long context does not increase the per-token rate.

Cost is input tokens divided by 1,000,000, multiplied by the effective input rate for your group. See TypeSafe on the pricing page for rates and multipliers, and your usage records for actual charges. Do not use rounded display prices for precise billing reconciliation.

6. Troubleshooting

SymptomWhat to check
401 / 403Use a valid, complete ZhenAPI key assigned to a TypeSafe group. A key from the official TypeSafe console cannot replace your gateway key.
404 / unsupported protocolUse /v1/systemone. These models do not use /v1/chat/completions, /v1/responses or /v1/messages. The OpenAI mode of a chat client is not a direct substitute.
400 / 422Check model, state, questions and criteria against the returned error. Use lowercase field names and a nonempty questions object; do not set stream=true. For images, also check format, dimensions, Base64 encoding and references.
max_tokens_exceededText, questions and images exceed the context limit. Use fewer images or repeated references, shorten questions, or split the text across requests.
413The body or image is too large. Base64 is typically about one third larger than the original image. Resize images, reduce repeated references or split requests. The lower of the gateway and upstream limits applies.
429 / 503 / model_not_foundReduce concurrency and retry with backoff, following Retry-After when present. For unavailable models or channels, check the full model ID and group. Contact support if failures persist.

Official references

Based on the official TypeSafe documentation and this gateway integration. Last checked: 2026-10-17.