Skip to content

Conversation

viniciusdsmello
Copy link
Contributor

# Pull Request

## Summary

This PR adds comprehensive tracing support for OpenAI's new Responses API (`client.responses.create`) while maintaining full backward compatibility with the existing Chat Completions API (`client.chat.completions.create`).

## Changes

- [x] Updated `trace_openai` and `trace_async_openai` to dynamically detect and patch the `responses.create` endpoint.
- [x] Implemented new handler functions for both streaming and non-streaming Responses API calls (sync and async).
- [x] Added helper functions for Responses API-specific parameter mapping, output parsing, streaming chunk extraction, and usage data extraction.
- [x] Modified `add_to_trace` to differentiate between Chat Completions and Responses API calls for improved trace naming and metadata.
- [x] Created a comprehensive example (`examples/tracing/openai/responses_api_example.py`) demonstrating usage for both APIs, including streaming and function calling.

## Context

OpenAI's Responses API unifies multiple capabilities (chat, text, tool use, JSON mode) into a single interface, providing improved metadata structure and traceability. This update extends Openlayer's tracing logic to support this new, more aligned endpoint, ensuring that users can leverage the latest OpenAI features with full observability without breaking existing integrations.

## Testing

- [x] Unit tests (comprehensive test suites verifying backward compatibility and new Responses API features for both sync and async clients)
- [x] Manual testing (verified functionality using the new example script)
- [ ] Postman CI/CD
- [ ] Other (please specify)

Open in Cursor Open in Web

Integrates tracing for the new OpenAI Responses API, maintaining backward compatibility with the Chat Completions API. This includes support for both synchronous and asynchronous clients, streaming, and function calling.

Co-authored-by: vinicius <vinicius@openlayer.com>
Copy link

cursor bot commented Oct 14, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants