from openai_document_analyzer import DocumentAnalyzerLoads UTF-8 TXT or Markdown content, or extracts text from a PDF. Leading and trailing whitespace is removed.
Raises:
FileNotFoundErrorDocumentReadErrorDocumentTooLargeErrorEmptyDocumentError
Extracts nonempty PDF pages locally and separates them with a blank line.
Image-only PDFs return EmptyDocumentError; run OCR before calling the package.
Sends text and an analysis request through the Responses API. The model
argument overrides the configured default for one call.
Raises:
ConfigurationErrorfor an empty prompt;DocumentTooLargeErrororEmptyDocumentErrorfor invalid text;AnalysisErrorwhen the OpenAI SDK raises an API error;EmptyResponseErrorwhen the API provides no output text.
Combines load_text() and analyze_text().
Uses one example request and response as answer-shape guidance. Examples are not treated as evidence about the document. Both example values are required.
This method exists for version 1 migration. Prefer a direct, explicit prompt when an example is unnecessary.
The package default: gpt-5.6-sol.
Documented Sol, Terra, and Luna model IDs with their intended tradeoff. It is not an allowlist.
DocumentAnalyzerError
├── ConfigurationError
├── DocumentReadError
├── DocumentTooLargeError
├── EmptyDocumentError
└── AnalysisError
└── EmptyResponseError
Catch the narrowest exception that the application can handle:
from openai_document_analyzer import (
AnalysisError,
DocumentAnalyzer,
DocumentReadError,
)
analyzer = DocumentAnalyzer()
try:
result = analyzer.analyze_document("report.pdf")
except DocumentReadError as exc:
print(f"Document problem: {exc}")
except AnalysisError as exc:
print(f"API problem: {exc}")Programming errors and unexpected failures are intentionally not converted to plausible analysis text.
from openai import OpenAI
from openai_document_analyzer import DocumentAnalyzer
client = OpenAI(timeout=45.0, max_retries=4)
analyzer = DocumentAnalyzer(client=client)The injected object must provide client.responses.create(...) and return an
object with output_text.
Version 2 is synchronous. Applications requiring async execution should place
the synchronous call in an appropriate worker or implement a dedicated
AsyncOpenAI integration with equivalent request, privacy, and error behavior.