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.
Install
Section titled “Install”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.
What it adds
Section titled “What it adds”- A
telem_searchtool the model can call, backed by the samesearch()every other SDK surface uses. - Conversation recording — every request and reply is captured and
published as
client.telem_messagesafter 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.
Identity
Section titled “Identity”| 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 OpenAIfrom telem import Telem
telem = Telem() # reads TELEM_API_KEY / TELEM_BASE_URL from the environmentclient = OpenAI() # reads OPENAI_API_KEY from the environmenttelem.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 turnprint(client.telem_messages) # the recorded conversation so farAsync is the same shape with AsyncTelem and openai.AsyncOpenAI:
import asynciofrom openai import AsyncOpenAIfrom 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.
Streaming isn’t supported yet
Section titled “Streaming isn’t supported yet”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.