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.4.tar.gz (9.0 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.4-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: caesura_io_openai-1.0.4.tar.gz
  • Upload date:
  • Size: 9.0 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.4.tar.gz
Algorithm Hash digest
SHA256 66404274959a3bf55efa3f11c240770da814d52b646506df8eea32c96473b0b0
MD5 596391327c433b5565d91328c093da44
BLAKE2b-256 2a5726450c266a08d1c6bd4c1a4bf24af2c2beb0ec56b2523c9456cf830902b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for caesura_io_openai-1.0.4.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.4-py3-none-any.whl.

File metadata

File hashes

Hashes for caesura_io_openai-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1068e05553b36ee3a2389943449f2db3d50c13c5e75cd9fbfca664aac205ddea
MD5 99211ffd170a1b8fa7f4dd8613eaa6bf
BLAKE2b-256 debbf9fb434a16ca4b7c631f2de4e7b87f8bef4aca026bec59e134c1f69fcd70

See more details on using hashes here.

Provenance

The following attestation bundles were made for caesura_io_openai-1.0.4-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