OpenAI Decisions API integration.
A discriminated union of answers returned by OpenAIDecisions.
A discriminated union of question types accepted by OpenAIDecisions.
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.
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.
Probability that a Predicate condition is true.
The model declined to answer a question.
Expected Score value with its levels, distribution, and confidence.
Token usage reported for a Decisions request.
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)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()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.1Input accepted by OpenAIDecisions.
The Decisions API natively accepts a string or user messages containing text and
base64 images. Strings and HumanMessage objects (alone or in a sequence) are sent
natively. Any other state, such as conversations with system or AI messages, or JSON
objects, is sent as JSON text in a single user message, with base64 images kept in
place as image parts.
Question and response types for the OpenAI Decisions API.
LangChain runnable for the OpenAI Decisions API.