Skip to main content

Transparent wrapper for the OpenAI Python SDK to inject Caesura recommendations.

Project description

caesura-io-openai

Asynchronous, non-blocking recommendation injection for the official OpenAI Python SDK.

Caesura listens to your agent's dialogue and pushes short, real-time recommendations ("analysis") into the model's context without blocking the conversation. It plugs in as a transparent wrapper around the OpenAI client.

Status: early development. API is not yet stable.

Install

pip install caesura-io-openai openai

Quick Start

Sync Client (Chat Completions)

 import openai
+from caesura_openai import create_caesura
 
-client = openai.OpenAI()
+client = create_caesura(openai.OpenAI(), {
+    "base_url": "https://dev.caesura.io",
+    # api_key auto-read from CAESURA_API_KEY if omitted
+})
 
 completion = client.chat.completions.create(
     model="gpt-5.4-mini",
     messages=conversation,
+    caesura_conversation_id=session_id,
 )

Async Client (Chat Completions)

 import openai
+from caesura_openai import create_async_caesura
 
-client = openai.AsyncOpenAI()
+client = create_async_caesura(openai.AsyncOpenAI(), {
+    "base_url": "https://dev.caesura.io",
+})
 
 completion = await client.chat.completions.create(
     model="gpt-5.4-mini",
     messages=conversation,
+    caesura_conversation_id=session_id,
 )

Responses API

 import openai
+from caesura_openai import create_caesura
 
-client = openai.OpenAI()
+client = create_caesura(openai.OpenAI(), {
+    "base_url": "https://dev.caesura.io",
+})
 
 response = client.responses.create(
     model="gpt-5.4-mini",
     input="Hello agent!",
+    caesura_conversation_id=session_id,
 )

Credit Usage Reporting

+from caesura_openai import create_caesura, create_credit_meter
 import openai
 
+meter = create_credit_meter()
+
-client = openai.OpenAI()
+client = create_caesura(openai.OpenAI(), {
+    "base_url": "https://dev.caesura.io",
+    "on_credit_usage": meter.record,
+})
 
+# Query credit metrics later
+print("total credits consumed:", meter.total())
+print("credits by conversation:", meter.breakdown())

Note: In async mode (default), the on_credit_usage callback fires out-of-band as soon as the asynchronous analyze call completes, decoupled from the synchronous OpenAI request resolution.

Caesura Mode vs Python Sync/Async

Caesura's mode setting ("sync" or "async") controls whether recommendation generation blocks the model call. It is independent of whether you use Python's sync OpenAI or async AsyncOpenAI client:

  • mode="async" (default): Observation runs in the background. Recommendations appear on the next turn.
  • mode="sync": Observation runs inline. Recommendations are injected into the current turn.

Both modes work with both the sync and async Python clients.

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

caesura_io_openai-1.0.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

caesura_io_openai-1.0.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file caesura_io_openai-1.0.2.tar.gz.

File metadata

  • Download URL: caesura_io_openai-1.0.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for caesura_io_openai-1.0.2.tar.gz
Algorithm Hash digest
SHA256 4f69f8a31a745bffa2bdfb095ab3621bfdf70f01040d6541ab37be3e2a4624ff
MD5 591b2fc51d9da511c39c0f548c7111a0
BLAKE2b-256 555a33dc680a448a73934cd91f9a898118b0ac4a8ec0343d6fc367d8fc7a54d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for caesura_io_openai-1.0.2.tar.gz:

Publisher: release.yml on caesura-io/sdk-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file caesura_io_openai-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for caesura_io_openai-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 55c56506a270f7479babb2094babaf021e65f696e2c3b9c924d5be0378209765
MD5 f674019c8d6f2d7be41bf99c0b7a0fb4
BLAKE2b-256 f647f98623aedff40961aaa4edc4a0682654672e08f5c1a0e7aee1ca2c6735a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for caesura_io_openai-1.0.2-py3-none-any.whl:

Publisher: release.yml on caesura-io/sdk-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page