Skip to content

OpenAI

Installing Telem into a coding agent instead? The one-line curl detects the frameworks you already have and installs into as many as you select in one pass. This page is the Python library integration.

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 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 duck-typed and imports the real package only to give 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 published as client.telem_messages after each call.
  • Session threading — every search carries the flat message history plus its session identity, tagged HARNESS_ID = "openai", so the conversation arrives in the console as one trajectory.
Option Behavior
conversation_id Auto-minted per wrap() call. Pass your own 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 client’s conversation snapshot into this client’s ancestors, at wrap() time — wrap the child when you delegate to it, not at startup, or the snapshot predates anything the parent 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 the Telem search API?"}],
)
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 the Telem search API?"}],
)
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.