OpenAI Decisions API integration.
Ask typed questions about text or images with the OpenAI Decisions API.
A single request can combine Predicate probabilities, Choice selections, and
Score ratings over shared input. The response preserves probabilities,
confidence, and token usage so application code can decide whether to act,
route, or request human review.
Sync and async OpenAI clients are created on first use of invoke or ainvoke
respectively.
Ask typed questions about text, messages, or images with OpenAI Decisions.
A single request can combine Noul probabilities, Choice selections, and
Score ratings over shared state. The response preserves probabilities,
confidence, and token usage so application code can decide whether to act,
route, or request human review.
Messages are sent as native Decisions API input items, so tool calls and tool results keep their roles. Other structured state is sent as JSON.
This is a best-effort integration with the TypeSafe-compatible
BaseDecisionModel interface. For an integration with the native OpenAI
Decisions API, use OpenAIDecisions.
Box questions raise ValueError.Choice needs at least two labels.predicate question has no outcome descriptions, so Noul
criteria are appended to the instructions as text.invoke raises ModelRefusalError and the other answers are discarded.safety_identifier, and cache breakpoints are
not exposed.http(s) URLs; files and audio raise ValueError.Select one value from a fixed, unordered set of options.
from langchain_openai.decisions import Choice, OpenAIDecisions
decisions = OpenAIDecisions(model="gpt-6-luna")
response = decisions.invoke(
{
"input": "I was charged twice for my order.",
"questions": {
"department": Choice(
instructions="Which department should handle this?",
choices={
"billing": "Payments, invoices, and refunds.",
"technical": "Problems using the product.",
"other": "Requests outside these categories.",
},
),
},
}
)
department = response.choices["department"]
if department.confidence >= 0.7:
route_to(department.choice)Selected Choice value with its probability distribution and confidence.
Complete input for one OpenAIDecisions invocation.
Keeping the input and questions together in the Runnable input ensures both participate in composition, batching, and tracing.
Typed answers and metadata returned from one Decisions request.
Access every answer through answers, or use predicates, choices, scores,
and refusals for views filtered by answer type. Each mapping is keyed by the
question names supplied in DecisionRequest.questions.
One level of a Score rubric.
Estimate the probability that a condition is true.
from langchain_openai.decisions import OpenAIDecisions, Predicate
decisions = OpenAIDecisions(model="gpt-6-luna")
response = decisions.invoke(
{
"input": "Production is down. Please help immediately.",
"questions": {
"urgent": Predicate(instructions="Is this request urgent?"),
},
}
)
if response.predicates["urgent"].probability >= 0.8:
page_on_call_engineer()Probability that a Predicate condition is true.
The model declined to answer a question.
Rate the input against ordered levels.
Levels are indexed from 0 in the order supplied. The returned score is the
probability-weighted average of those indices, so it may fall between levels.
from langchain_openai.decisions import Level, OpenAIDecisions, Score
decisions = OpenAIDecisions(model="gpt-6-luna")
response = decisions.invoke(
{
"input": "Export fails in Safari but works in Chrome.",
"questions": {
"severity": Score(
instructions="How severe is this issue?",
levels=[
Level(label="Cosmetic", description="No lost function."),
Level(label="Workaround", description="Another way works."),
Level(label="Blocked", description="No workaround."),
],
),
},
}
)
print(response.scores["severity"].score) # May be fractional, e.g. 1.1Expected Score value with its levels, distribution, and confidence.
Token usage reported for a Decisions request.