Skip to main content

Decisions API

This page documents the 4 gateway endpoints tagged decisions in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.

MethodPathSummary
POST/decisionsAsk questions about an input (OpenAI Decisions format)
POST/systemoneAsk named questions about a state (System One format)
POST/v1/decisionsAsk questions about an input (OpenAI Decisions format)
POST/v1/systemoneAsk named questions about a state (System One format)

Endpoints​

POST /decisions​

Ask questions about an input (OpenAI Decisions format)

Judge an input against 1 to 128 questions and get the answers back in the same order.

Use it when your app needs a quick, scored judgement instead of free text, for example "is this a refund request, and how urgent is it". Any virtual key allowed to use the named model may call it. Nothing is stored beyond the usual request log and spend tracking, and the key's budget and rate limits apply.

Question types are predicate (yes/no with probability), choice (one of the choices, with probabilities) and score (an index into levels, with probabilities). Requests that break these rules are rejected with a 400 before any provider is called. model is any decision model in the proxy model list. System One decision models accept this format too, Spanway translates the request and the answers. Streaming is not supported.

Docs

Request body (application/json, object):

FieldTypeRequiredDescription
audioarray of string or objectNoClef-omni only. Up to 4 embedded audio clips, each a base64 data URL or {content_type, base64}
inputstring or array of objectYesThe text being judged, or user messages whose content mixes input_text and input_image parts
modelstringYesA decision model from the proxy model_list
questionsarray of objectYesPredicate, choice and score questions. Answers come back in the same order
safety_identifierstring or nullNoA stable end-user id for OpenAI. Other providers answer 400 unless drop_params is true
videosarray of string or objectNoClef-omni only. Up to 2 embedded videos, each a base64 data URL or {content_type, base64}

Example request:

curl -X POST "http://localhost:4000/decisions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "Customer wrote: I was charged twice for order #4411 and want one charge refunded today.",
"model": "luna",
"questions": [
{
"instructions": "Is the customer asking for a refund?",
"name": "is_refund_request",
"type": "predicate"
},
{
"choices": [
{
"description": "can wait a week",
"value": "low"
},
{
"description": "needs action today",
"value": "high"
}
],
"instructions": "How urgent is this?",
"name": "urgency",
"type": "choice"
},
{
"instructions": "How frustrated is the customer?",
"levels": [
{
"label": "calm"
},
{
"label": "mildly annoyed"
},
{
"label": "angry"
}
],
"name": "frustration",
"type": "score"
}
]
}'

Responses:

StatusDescriptionBody
200One answer per question, in the order they were askedapplication/json OpenAIDecisionResponse
400The request was refused before any provider was called: the body breaks a question rule, stream is true, or the model is not in the model list. error.message says which. Docsapplication/json ProxyError
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...).application/json ProxyError
408The provider did not answer before the request timed out.application/json ProxyError
413The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docsapplication/json object
422The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an errorapplication/json ProxyError or HTTPValidationError
429Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an errorapplication/json ProxyError
500The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing.application/json ProxyError
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
answersarray of OpenAIPredicateAnswer or OpenAIChoiceAnswer or OpenAIScoreAnswer or OpenAIRefusalAnswerYesAnswers
modelstringYesModel
usageOpenAIDecisionUsageYes

POST /systemone​

Ask named questions about a state (System One format)

Judge a state against 1 to 128 named questions and get one calibrated answer per question name.

Use it when your app needs a quick, scored judgement instead of free text, for example "is this a refund request, and how urgent is it". Any virtual key allowed to use the named model may call it. Nothing is stored beyond the usual request log and spend tracking, and the key's budget and rate limits apply.

Question types are noul (probability the answer is yes), choice (one label out of criteria, with confidence and probabilities) and score (an index into the criteria levels, with confidence, legend and probabilities). Requests that break these rules are rejected with a 400 before any provider is called. model is any decision model in the proxy model list. OpenAI decision models accept this format too, Spanway translates it and keeps the answers keyed by question name. Streaming is not supported.

Docs

Request body (application/json, object):

FieldTypeRequiredDescription
audioarray of string or objectNoClef-omni only. Up to 4 embedded audio clips, each a base64 data URL or {content_type, base64}
modelstringYesA decision model from the proxy model_list
questionsobjectYesNamed noul, choice and score questions. Each key becomes a key in the answers
statestring or object or array of anyYesThe thing being judged, such as a support ticket, a document or a chat transcript
videosarray of string or objectNoClef-omni only. Up to 2 embedded videos, each a base64 data URL or {content_type, base64}

Example request:

curl -X POST "http://localhost:4000/systemone" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "jev",
"questions": {
"frustration": {
"criteria": [
"calm",
"mildly annoyed",
"angry"
],
"instructions": "How frustrated is the customer?",
"type": "score"
},
"is_refund_request": {
"instructions": "Is the customer asking for a refund?",
"type": "noul"
},
"urgency": {
"criteria": {
"high": "needs action today",
"low": "can wait a week"
},
"instructions": "How urgent is this?",
"type": "choice"
}
},
"state": "Customer wrote: I was charged twice for order #4411 and want one charge refunded today."
}'

Responses:

StatusDescriptionBody
200One answer per question nameapplication/json DecisionsResponse
400The request was refused before any provider was called: the body breaks a question rule, stream is true, or the model is not in the model list. error.message says which. Docsapplication/json ProxyError
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...).application/json ProxyError
408The provider did not answer before the request timed out.application/json ProxyError
413The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docsapplication/json object
422The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an errorapplication/json ProxyError or HTTPValidationError
429Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an errorapplication/json ProxyError
500The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing.application/json ProxyError
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
answersobjectYesAnswers
modelstring or nullNoModel
usageDecisionsUsage or nullNo

POST /v1/decisions​

Ask questions about an input (OpenAI Decisions format)

Judge an input against 1 to 128 questions and get the answers back in the same order.

Use it when your app needs a quick, scored judgement instead of free text, for example "is this a refund request, and how urgent is it". Any virtual key allowed to use the named model may call it. Nothing is stored beyond the usual request log and spend tracking, and the key's budget and rate limits apply.

Question types are predicate (yes/no with probability), choice (one of the choices, with probabilities) and score (an index into levels, with probabilities). Requests that break these rules are rejected with a 400 before any provider is called. model is any decision model in the proxy model list. System One decision models accept this format too, Spanway translates the request and the answers. Streaming is not supported.

Docs

Request body (application/json, object):

FieldTypeRequiredDescription
audioarray of string or objectNoClef-omni only. Up to 4 embedded audio clips, each a base64 data URL or {content_type, base64}
inputstring or array of objectYesThe text being judged, or user messages whose content mixes input_text and input_image parts
modelstringYesA decision model from the proxy model_list
questionsarray of objectYesPredicate, choice and score questions. Answers come back in the same order
safety_identifierstring or nullNoA stable end-user id for OpenAI. Other providers answer 400 unless drop_params is true
videosarray of string or objectNoClef-omni only. Up to 2 embedded videos, each a base64 data URL or {content_type, base64}

Example request:

curl -X POST "http://localhost:4000/v1/decisions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "Customer wrote: I was charged twice for order #4411 and want one charge refunded today.",
"model": "luna",
"questions": [
{
"instructions": "Is the customer asking for a refund?",
"name": "is_refund_request",
"type": "predicate"
},
{
"choices": [
{
"description": "can wait a week",
"value": "low"
},
{
"description": "needs action today",
"value": "high"
}
],
"instructions": "How urgent is this?",
"name": "urgency",
"type": "choice"
},
{
"instructions": "How frustrated is the customer?",
"levels": [
{
"label": "calm"
},
{
"label": "mildly annoyed"
},
{
"label": "angry"
}
],
"name": "frustration",
"type": "score"
}
]
}'

Responses:

StatusDescriptionBody
200One answer per question, in the order they were askedapplication/json OpenAIDecisionResponse
400The request was refused before any provider was called: the body breaks a question rule, stream is true, or the model is not in the model list. error.message says which. Docsapplication/json ProxyError
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...).application/json ProxyError
408The provider did not answer before the request timed out.application/json ProxyError
413The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docsapplication/json object
422The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an errorapplication/json ProxyError or HTTPValidationError
429Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an errorapplication/json ProxyError
500The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing.application/json ProxyError
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
answersarray of OpenAIPredicateAnswer or OpenAIChoiceAnswer or OpenAIScoreAnswer or OpenAIRefusalAnswerYesAnswers
modelstringYesModel
usageOpenAIDecisionUsageYes

POST /v1/systemone​

Ask named questions about a state (System One format)

Judge a state against 1 to 128 named questions and get one calibrated answer per question name.

Use it when your app needs a quick, scored judgement instead of free text, for example "is this a refund request, and how urgent is it". Any virtual key allowed to use the named model may call it. Nothing is stored beyond the usual request log and spend tracking, and the key's budget and rate limits apply.

Question types are noul (probability the answer is yes), choice (one label out of criteria, with confidence and probabilities) and score (an index into the criteria levels, with confidence, legend and probabilities). Requests that break these rules are rejected with a 400 before any provider is called. model is any decision model in the proxy model list. OpenAI decision models accept this format too, Spanway translates it and keeps the answers keyed by question name. Streaming is not supported.

Docs

Request body (application/json, object):

FieldTypeRequiredDescription
audioarray of string or objectNoClef-omni only. Up to 4 embedded audio clips, each a base64 data URL or {content_type, base64}
modelstringYesA decision model from the proxy model_list
questionsobjectYesNamed noul, choice and score questions. Each key becomes a key in the answers
statestring or object or array of anyYesThe thing being judged, such as a support ticket, a document or a chat transcript
videosarray of string or objectNoClef-omni only. Up to 2 embedded videos, each a base64 data URL or {content_type, base64}

Example request:

curl -X POST "http://localhost:4000/v1/systemone" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "jev",
"questions": {
"frustration": {
"criteria": [
"calm",
"mildly annoyed",
"angry"
],
"instructions": "How frustrated is the customer?",
"type": "score"
},
"is_refund_request": {
"instructions": "Is the customer asking for a refund?",
"type": "noul"
},
"urgency": {
"criteria": {
"high": "needs action today",
"low": "can wait a week"
},
"instructions": "How urgent is this?",
"type": "choice"
}
},
"state": "Customer wrote: I was charged twice for order #4411 and want one charge refunded today."
}'

Responses:

StatusDescriptionBody
200One answer per question nameapplication/json DecisionsResponse
400The request was refused before any provider was called: the body breaks a question rule, stream is true, or the model is not in the model list. error.message says which. Docsapplication/json ProxyError
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...).application/json ProxyError
408The provider did not answer before the request timed out.application/json ProxyError
413The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docsapplication/json object
422The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an errorapplication/json ProxyError or HTTPValidationError
429Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an errorapplication/json ProxyError
500The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing.application/json ProxyError
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
answersobjectYesAnswers
modelstring or nullNoModel
usageDecisionsUsage or nullNo