Overview
OpenAIDecisionsClassifier answers classifier questions through OpenAI’s Decisions API. All the questions about one state go to OpenAI in one request. The API takes only text, so structured state, instructions, and descriptions are sent as JSON.
An OpenAIDecisionsClassifier asks through an OpenAIDecisionsClient, which holds the HTTP/2 connection, adds the auth header, retries when OpenAI is busy, and counts tokens. Build the classifier with an API key to give it a client of its own, or pass an OpenAIDecisionsClient to share one connection between several classifiers.
Installation
Prerequisites
An OpenAI API key, usually set as an environment variable:Configuration
OpenAIDecisionsClassifier
str | None
default:"None"
OpenAI API key, when the classifier should have a client of its own. One of
api_key and client is required.OpenAIDecisionsClient | None
default:"None"
A client to share with other classifiers. One of
api_key and client is
required.str
default:"gpt-6-luna"
The decision model a client of its own asks.
str
default:"https://api.openai.com/v1"
Where a client of its own sends its questions.
float
default:"10.0"
Seconds a client of its own waits for an answer before raising
ClassifierError.str | None
default:"None"
Name of the classifier, as it appears in logs and metrics.
OpenAIDecisionsClient
str
required
OpenAI API key.
str
default:"https://api.openai.com/v1"
Where the API is served, such as
https://eu.api.openai.com/v1 for data
residency in Europe.str
default:"gpt-6-luna"
The decision model to ask.
float
default:"10.0"
Seconds to wait for a reply before raising
ClassifierError.int
default:"3"
How many times to retry a request OpenAI refused because it was busy (HTTP 429
or 503), with exponential backoff.
Usage
Basic Usage
VoicemailDetector or UIWorker.
Sharing a Client
Several classifiers can share oneOpenAIDecisionsClient, and with it one connection pool and one token count:
cleanup(). A shared client is left open, so close it yourself with await client.close() when every classifier using it is done.
Opening the Connection Early
setup() opens the connection to OpenAI ahead of the first question, so the first answer does not pay for the TLS handshake. Components that own a classifier, such as VoicemailDetector, call it for you. If the connection cannot be opened at setup, a warning is logged and the first question opens it instead.
OpenAIDecisionsClassifier Properties
OpenAIDecisionsClient Reference
Properties
Methods
connect
ClassifierError if OpenAI could not be reached or refused the request.
close
Metrics
After every call, anOpenAIDecisionsClassifier reports the time it took as ProcessingMetricsData and the tokens used as LLMUsageMetricsData through its on_metrics event.
Notes
- Limits: a choice question takes at most 255 options, available as
OPENAI_DECISIONS_MAX_CHOICE_OPTIONSinpipecat.classifiers.openai.decisions.classifier. A question with more raisesClassifierErrorbefore anything is sent. - Errors: a rejected request, a busy OpenAI after every retry, an unreachable server, a refusal to answer a question, or a reply missing an answer all raise
ClassifierError. - Idle connections are kept open for 240 seconds, so a gap between questions does not cost a new TLS handshake.