Decisions
Send text or images to the hosted API and ask predicate, choice, or score questions. The API returns results and associated probabilities for each question. For video, extract frames first and submit them as image inputs.
POST /v1/decisions
Quick request
Install requests in the client environment to run the Python example, or switch to cURL.
- Python
- cURL
import requests
response = requests.post(
"https://api.valen-team.workers.dev/v1/decisions",
headers={"Origin": "https://valen-team.github.io"},
json={
"model": "valen-2b",
"input": "A cat is sitting on the sofa.",
"questions": [
{
"name": "q0",
"type": "choice",
"instructions": "Which animal is present?",
"choices": [
{
"value": "cat",
"description": "A cat"
},
{
"value": "dog",
"description": "A dog"
}
]
}
],
"temperature": 1
},
timeout=120,
)
response.raise_for_status()
body = response.json()
answer = body["answers"][0]
print(answer["choice"], answer["confidence"])
for entry in answer["probabilities"]:
print(entry["value"], entry["probability"])
print("Model ID:", body.get("model_id"))
curl --request POST \
https://api.valen-team.workers.dev/v1/decisions \
--header 'Content-Type: application/json' \
--header 'Origin: https://valen-team.github.io' \
--data '{
"model": "valen-2b",
"input": "A cat is sitting on the sofa.",
"questions": [
{
"name": "q0",
"type": "choice",
"instructions": "Which animal is present?",
"choices": [
{
"value": "cat",
"description": "A cat"
},
{
"value": "dog",
"description": "A dog"
}
]
}
],
"temperature": 1
}'
Headers
| Field | Description |
|---|---|
Content-Type | Required: application/json |
Origin | Optional; sent automatically by browsers. |
Authorization | Required on the keyed endpoint: Bearer $VALEN_API_KEY |
Body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Hosted model ID, such as valen-2b; see List Models. |
input | string / messages[] | Yes | Shared evidence for all questions. |
questions | object[] | Yes | Question list; each item has name, type, and instructions. |
temperature | number | No | Valen calibration extension; finite and positive, defaults to 1.0. |
Instructions must be nonempty text. The upstream API validates requests.
Question types
- predicate
- choice
- score
Return the probability, from 0 to 1, that a condition holds.
Request:
{
"model": "valen-2b",
"temperature": 1.0,
"input": "A cat is on the sofa.",
"questions": [
{
"name": "q0",
"type": "predicate",
"instructions": "The cat is on the sofa."
}
]
}
Example answer:
{
"answers": [
{
"type": "predicate",
"name": "q0",
"probability": 0.98
}
]
}
Select a candidate value and return the candidate distribution.
Request:
{
"model": "valen-2b",
"temperature": 1.0,
"input": "A cat is on the sofa.",
"questions": [
{
"name": "q0",
"type": "choice",
"instructions": "Which animal is present?",
"choices": [
{
"value": "cat",
"description": "A cat"
},
{
"value": "dog",
"description": "A dog"
}
]
}
]
}
Example answer:
{
"answers": [
{
"type": "choice",
"name": "q0",
"choice": "cat",
"probabilities": [
{
"value": "cat",
"probability": 0.9
},
{
"value": "dog",
"probability": 0.1
}
],
"confidence": 0.8
}
]
}
Rate against ordered levels. score is the probability-weighted average of zero-based level indices; three levels span 0–2.
Request:
{
"model": "valen-2b",
"temperature": 1.0,
"input": "A cat is on the sofa.",
"questions": [
{
"name": "q0",
"type": "score",
"instructions": "How clearly is the animal identified?",
"levels": [
{
"label": "0",
"description": "Unclear"
},
{
"label": "1",
"description": "Partially clear"
},
{
"label": "2",
"description": "Clear"
}
]
}
]
}
Example answer:
{
"answers": [
{
"type": "score",
"name": "q0",
"score": 1.5,
"probabilities": [
{
"label": "0",
"value": 0,
"probability": 0.1
},
{
"label": "1",
"value": 1,
"probability": 0.3
},
{
"label": "2",
"value": 2,
"probability": 0.6
}
],
"confidence": 0.25
}
]
}
Response
Successful requests return HTTP 200 with a JSON response body.
| Field | Type | Description |
|---|---|---|
model | string | Model that answered the request. |
answers | object[] | Answers in request order, echoing each question name. |
usage | object | input_tokens and output_tokens. |
confidence is separate from the maximum candidate probability. Responses may also include model_id, revision, internal_usage, timing, and images.
Images
This example encodes a local PNG, JPEG, or WebP image and sends the request. Replace image.png with your file; its MIME type is inferred from the filename. Images are sent as input_image content parts.
- Python
- cURL
import requests
import base64
import mimetypes
from pathlib import Path
image_path = Path("image.png")
mime_type = mimetypes.guess_type(image_path.name)[0]
image_url = f"data:{mime_type};base64," + base64.b64encode(
image_path.read_bytes()
).decode("ascii")
response = requests.post(
"https://api.valen-team.workers.dev/v1/decisions",
headers={"Origin": "https://valen-team.github.io"},
json={
"model": "valen-2b",
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Answer using only the visible image."
},
{
"type": "input_image",
"image_url": image_url
}
]
}
],
"questions": [
{
"name": "q0",
"type": "choice",
"instructions": "Which animal is present?",
"choices": [
{
"value": "cat",
"description": "A cat"
},
{
"value": "dog",
"description": "A dog"
}
]
}
],
"temperature": 1
},
timeout=120,
)
response.raise_for_status()
body = response.json()
answer = body["answers"][0]
print(answer["choice"], answer["confidence"])
for entry in answer["probabilities"]:
print(entry["value"], entry["probability"])
print("Model ID:", body.get("model_id"))
# Run in the folder containing your selected image.
python3 - <<'PY' > request.json
import json, sys
import base64
import mimetypes
from pathlib import Path
image_path = Path("image.png")
mime_type = mimetypes.guess_type(image_path.name)[0]
image_url = f"data:{mime_type};base64," + base64.b64encode(
image_path.read_bytes()
).decode("ascii")
payload = {
"model": "valen-2b",
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Answer using only the visible image."
},
{
"type": "input_image",
"image_url": image_url
}
]
}
],
"questions": [
{
"name": "q0",
"type": "choice",
"instructions": "Which animal is present?",
"choices": [
{
"value": "cat",
"description": "A cat"
},
{
"value": "dog",
"description": "A dog"
}
]
}
],
"temperature": 1
}
json.dump(payload, sys.stdout)
PY
curl --request POST \
https://api.valen-team.workers.dev/v1/decisions \
--header 'Content-Type: application/json' \
--header 'Origin: https://valen-team.github.io' \
--data @request.json
Errors
| Status | Description |
|---|---|
400 | Request rejected by the upstream API. |
429 | Rate limit exceeded; retry later. |
Protocol reference: OpenAI Decisions.