Skip to content

Commit d3bb18e

Browse files
refactor: streamline OpenAI responses API tracing example in notebook
1 parent 96986a4 commit d3bb18e

File tree

1 file changed

+4
-55
lines changed

1 file changed

+4
-55
lines changed

examples/tracing/openai/openai_responses_api_tracing.ipynb

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -112,66 +112,15 @@
112112
"outputs": [],
113113
"source": [
114114
"# Responses API - new unified interface with enhanced metadata\n",
115-
"if hasattr(client, 'responses'):\n",
116-
" response = client.responses.create(\n",
117-
" model=\"gpt-4o-mini\",\n",
118-
" input=\"What is 3 + 3?\",\n",
119-
" max_output_tokens=50\n",
120-
" )\n",
121-
" \n",
122-
" # Response is automatically traced\n",
123-
" response\n",
124-
"else:\n",
125-
" \"Responses API not available in this OpenAI version\""
126-
]
127-
},
128-
{
129-
"cell_type": "markdown",
130-
"id": "streaming-example",
131-
"metadata": {},
132-
"source": [
133-
"## 5. Streaming example"
134-
]
135-
},
136-
{
137-
"cell_type": "code",
138-
"execution_count": null,
139-
"id": "streaming-code",
140-
"metadata": {},
141-
"outputs": [],
142-
"source": [
143-
"# Streaming works with both APIs\n",
144-
"stream = client.chat.completions.create(\n",
115+
"response = client.responses.create(\n",
145116
" model=\"gpt-4o-mini\",\n",
146-
" messages=[{\"role\": \"user\", \"content\": \"Count from 1 to 3\"}],\n",
147-
" stream=True\n",
117+
" input=\"What is 3 + 3?\",\n",
118+
" max_output_tokens=50\n",
148119
")\n",
149-
"response = ''\n",
150120
"\n",
151-
"# Consume the stream - automatically traced\n",
152-
"for chunk in stream:\n",
153-
" if chunk.choices[0].delta.content:\n",
154-
" response += chunk.choices[0].delta.content\n",
121+
"# Response is automatically traced\n",
155122
"response"
156123
]
157-
},
158-
{
159-
"cell_type": "markdown",
160-
"id": "conclusion",
161-
"metadata": {},
162-
"source": [
163-
"## Summary\n",
164-
"\n",
165-
"That's it! The same `trace_openai()` function now supports:\n",
166-
"\n",
167-
"- ✅ **Chat Completions API** - Full backward compatibility\n",
168-
"- ✅ **Responses API** - New unified interface with enhanced metadata\n",
169-
"- ✅ **Streaming** - Both APIs support streaming\n",
170-
"- ✅ **Function calling** - Tool calls work with both APIs\n",
171-
"- ✅ **Async support** - Use `trace_async_openai()` for async clients\n",
172-
"\n",
173-
"All traces are automatically sent to Openlayer with proper API type differentiation!"
174-
]
175124
}
176125
],
177126
"metadata": {

0 commit comments

Comments
 (0)