Skip to main content

caesura-io-openai

CaesuraO recommendations for OpenAI Python 2.x and 3.x. Supports Chat Completions and Responses through create(), including streaming, with sync and async clients.

pip install caesura-io-openai openai

Set OPENAI_API_KEY and CAESURA_API_KEY, then create a conversation once:

from openai import OpenAI
from caesura_core import AnalysisContext, AnalyzeMessage, CustomerTurn
from caesura_openai import CaesuraOpenAIOptions, create_caesura

with create_caesura(OpenAI(), CaesuraOpenAIOptions(mode="sync")) as client:
    conversation_id = client.create_conversation(name="Support conversation")
    response = client.responses.create(
        model="gpt-5.4-mini",
        input="Can you help me?",
        caesura_conversation_id=conversation_id,
        caesura_stateless=conversation_id is None,
        caesura_context=AnalysisContext(
            turn=CustomerTurn("customer-message-1", AnalyzeMessage("user", "Can you help me?")),
        ),
    )
    print(response.output_text)

Save a successfully returned conversation ID and reuse it on later calls. With continue policy, creation failure returns None; caesura_stateless=True explicitly permits a one-shot call without saved conversation state. Fallback respects mode; choose "sync" for same-call guidance. Use a distinct customer message ID for each new turn and reuse it on retries. The SDK does not fetch history.

For async applications, use create_async_caesura(AsyncOpenAI(), options) and await creation/model calls. For Chat Completions, use client.chat.completions.create() with messages and the same caesura_conversation_id / caesura_context options.

Behavior and options

Option Behavior
mode="async" (default) Analyze in the background; guidance is available to later calls
mode="sync" Await analysis before the current model call
persist=True (default) Save customer messages, completed agent replies, and analyses to CaesuraO
failure_policy="continue" (default) Report hosted-storage errors and try stateless analysis; analysis errors still allow the model call
failure_policy="raise" Fail required foreground work before invoking the model
speaker_names=SpeakerNames(agent="Agent", customer="Customer") Participant labels; default indices are agent 0 and customer 1

Analysis mode is independent of Python's sync/async client type. An authoritative conversation ID is required for stateful calls even with persist=False. Completed customer messages and agent replies are saved by default. Use persist_transcript for an additional application-owned archive, including partial output.

New customer turns trigger analysis. Earlier assistant dialogue provides background; tool/RAG content should be excluded with explicit CustomerTurn selection. Keep your application dialogue separate from SDK-injected requests.

Use stream=True and consume or close streams to finalize usage and persistence. The wrapper preserves native chunks but returns a delegating stream proxy. Convenience .stream() and raw-response helpers bypass the analysis wrapper; use create().

on_credit_usage=create_credit_meter().record collects credit usage. on_provider_request captures the finalized model request; on_provider_outcome reports responses, stream completion, errors, and available usage.

See application integration for guidance placement, stores, cancellation, and audit contracts; migration for breaking changes; and runnable applications for local examples.

Licensed under Apache-2.0.

Metadata

Release files for caesura-io-openai 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for caesura-io-openai 4.0.0
File Size Uploaded
caesura_io_openai-4.0.0.tar.gz 53.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for caesura-io-openai 4.0.0
File Interpreter ABI Platform
caesura_io_openai-4.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 69.6 kB

Release files / caesura_io_openai-4.0.0.tar.gz

Download URL caesura_io_openai-4.0.0.tar.gz
Size 53.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f4c2a33a5e91bb7fe35be511e4581b09edfd0ed39c7d941f10ae01e18ce917ca
BLAKE2b-256 checksum
How to use checksums
979516cd10c619bbcfb92d0b9da9727fa57d100436cf37cd5d067b1792da06b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / caesura_io_openai-4.0.0-py3-none-any.whl

Download URL caesura_io_openai-4.0.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8789d17defbf8b57db0680bd7472d54402d8818d3b5d6b35bcab5e269a1bd577
BLAKE2b-256 checksum
How to use checksums
4da4a2aa7aebd968c0d5d77cf0fa5b685f6b3128f8403ed0920b703cb36222eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

4.0.0 This release

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page