Types
There’s no SDK yet, so copy these into your code.
Built and tested, not yet deployed. Early access.
On this page
TypeScript
export type QuestionType = "predicate" | "choice" | "score"; export type DecisionId = | "restricted_merchant" | "spend_type" | "receipt_match" | "refund_pairing" | "return_window" | "support_route" | "signal_baseline" | "member_route" | "document_complete"; export type CustomQuestion = | { type: "predicate"; instructions: string } | { type: "choice"; instructions: string; options: string[] | Record<string, string> } | { type: "score"; instructions: string; levels: string[] }; export type Input = Record<string, unknown>; export type UnderstandRequest = | { decision: DecisionId; input: Input; abstainBelow?: number } | { question: CustomQuestion; input: Input | string; abstainBelow?: number }; export interface UnderstandAnswer { decision: DecisionId | null; /** A 400, 401, 402, 409, 413, 422, 429, 500, 502 or 503. `field` names the part of the body at fault, when one can be named; `code` is set on errors a program should tell apart ("sensitive_data", "invalid_idempotency_key", "idempotency_in_progress", "idempotency_key_reuse"). */ export interface UnderstandError { error: { message: string; field?: string; code?: string }; }
Python
from typing import Literal, NotRequired, TypedDict, Union QuestionType = Literal["predicate", "choice", "score"] DecisionId = Literal["restricted_merchant", "spend_type", "receipt_match", "refund_pairing", "return_window", "support_route", "signal_baseline", "member_route", "document_complete"] class PredicateQuestion(TypedDict): type: Literal["predicate"] instructions: str class ChoiceQuestion(TypedDict): type: Literal["choice"] instructions: str options: Union[list[str], dict[str, str]] class ScoreQuestion(TypedDict): type: Literal["score"] instructions: str levels: list[str] CustomQuestion = Union[PredicateQuestion, ChoiceQuestion, ScoreQuestion] class DecisionRequest(TypedDict): decision: DecisionId input: dict abstainBelow: NotRequired[float] class QuestionRequest(TypedDict): question: CustomQuestion input: Union[dict, str] abstainBelow: NotRequired[float] UnderstandRequest = Union[DecisionRequest, QuestionRequest] class UnderstandAnswer(TypedDict): decision: Union[DecisionId, None] type: QuestionType answer: Union[bool, str, int, None] probability: Union[float, None] reasons: list[str] abstain: bool class ErrorBody(TypedDict): message: str field: NotRequired[str] code: NotRequired[str] class UnderstandError(TypedDict): error: ErrorBody
# Types
There’s no SDK yet, so copy these into your code.
Built and tested, not yet deployed. Early access.
## TypeScript
```
export type QuestionType = "predicate" | "choice" | "score";
export type DecisionId =
| "restricted_merchant"
| "spend_type"
| "receipt_match"
| "refund_pairing"
| "return_window"
| "support_route"
| "signal_baseline"
| "member_route"
| "document_complete";
export type CustomQuestion =
| { type: "predicate"; instructions: string }
| { type: "choice"; instructions: string; options: string[] | Record<string, string> }
| { type: "score"; instructions: string; levels: string[] };
export type Input = Record<string, unknown>;
export type UnderstandRequest =
| { decision: DecisionId; input: Input; abstainBelow?: number }
| { question: CustomQuestion; input: Input | string; abstainBelow?: number };
export interface UnderstandAnswer {
decision: DecisionId | null;
/** A 400, 401, 402, 409, 413, 422, 429, 500, 502 or 503. `field` names the part of the body at fault, when one can be named; `code` is set on errors a program should tell apart ("sensitive_data", "invalid_idempotency_key", "idempotency_in_progress", "idempotency_key_reuse"). */
export interface UnderstandError {
error: { message: string; field?: string; code?: string };
}
```
## Python
```
from typing import Literal, NotRequired, TypedDict, Union
QuestionType = Literal["predicate", "choice", "score"]
DecisionId = Literal["restricted_merchant", "spend_type", "receipt_match", "refund_pairing", "return_window", "support_route", "signal_baseline", "member_route", "document_complete"]
class PredicateQuestion(TypedDict):
type: Literal["predicate"]
instructions: str
class ChoiceQuestion(TypedDict):
type: Literal["choice"]
instructions: str
options: Union[list[str], dict[str, str]]
class ScoreQuestion(TypedDict):
type: Literal["score"]
instructions: str
levels: list[str]
CustomQuestion = Union[PredicateQuestion, ChoiceQuestion, ScoreQuestion]
class DecisionRequest(TypedDict):
decision: DecisionId
input: dict
abstainBelow: NotRequired[float]
class QuestionRequest(TypedDict):
question: CustomQuestion
input: Union[dict, str]
abstainBelow: NotRequired[float]
UnderstandRequest = Union[DecisionRequest, QuestionRequest]
class UnderstandAnswer(TypedDict):
decision: Union[DecisionId, None]
type: QuestionType
answer: Union[bool, str, int, None]
probability: Union[float, None]
reasons: list[str]
abstain: bool
class ErrorBody(TypedDict):
message: str
field: NotRequired[str]
code: NotRequired[str]
class UnderstandError(TypedDict):
error: ErrorBody
```
Source: /api/docs/types