Skip to content

OpenAI

Telem.wrap(client) — and AsyncTelem.wrap(client) for openai.AsyncOpenAI — patches an OpenAI client in place and hands back the same object, with chat.completions.create now equipped with Telem search. One wrapped client is one agent conversation.

Terminal window
pip install "telem-sdk[openai]"

openai is an optional extra: the wrap module is fully duck-typed and only imports the real openai package to produce a clearer error when the object you pass in isn’t shaped like an OpenAI client.

  • A telem_search tool the model can call, backed by the same search() every other SDK surface uses.
  • Conversation recording — every request and reply is captured and published as client.telem_messages after each call.
  • Trajectory v5 metadata — every search the wrap runs carries the flat message history plus session/fingerprint/node identity, tagged HARNESS_ID = "openai", so it threads into the same trajectory graph as every other Telem-integrated harness.
Option Behavior
conversation_id Auto-minted per wrap() call. Pass your own (a thread id, a request-scoped chat id) when the conversation should outlive a single wrapped client — e.g. a web server wrapping a fresh client per request.
context_window_id Omitted: the wrap anchors on the first message, so trimming or summarizing the history starts a new generation on its own.
parent= Freezes the parent wrapped client’s conversation snapshot into this client’s ancestors, at wrap() time — wrap the child at the moment you delegate to it, not at startup, or the snapshot will predate anything the parent actually said.
from openai import OpenAI
from telem import Telem
telem = Telem() # reads TELEM_API_KEY / TELEM_BASE_URL from the environment
client = OpenAI() # reads OPENAI_API_KEY from the environment
telem.wrap(client) # patches client.chat.completions.create in place
completion = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What's new in trajectory v5?"}],
)
print(completion.choices[0].message.content)
print(completion.telem_responses) # list[SearchResponse] telem ran answering this turn
print(client.telem_messages) # the recorded conversation so far

Async is the same shape with AsyncTelem and openai.AsyncOpenAI:

import asyncio
from openai import AsyncOpenAI
from telem import AsyncTelem
async def main():
telem = AsyncTelem()
client = AsyncOpenAI()
telem.wrap(client)
completion = await client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What's new in trajectory v5?"}],
)
print(completion.choices[0].message.content)
asyncio.run(main())

Both examples need a real OPENAI_API_KEY and make a live model call.

A stream=True call bypasses Telem entirely — no telem_search tool, no session tracking, no reply recording — and the wrap emits a UserWarning every time it happens.