Skip to content

Support OpenAI Responses API content parts#1981

Open
RitwijParmar wants to merge 3 commits into
pydantic:mainfrom
RitwijParmar:codex/logfire-openai-responses-content-parts
Open

Support OpenAI Responses API content parts#1981
RitwijParmar wants to merge 3 commits into
pydantic:mainfrom
RitwijParmar:codex/logfire-openai-responses-content-parts

Conversation

@RitwijParmar

Copy link
Copy Markdown

Fixes #1901.

This fills in the Responses API content-part gap in the OpenAI instrumentation:

  • input_text now maps to a text part/event instead of falling through as unknown
  • input_image handles the Responses API's flat image_url string as well as file_id and inline file data
  • input_file maps URL and file-id references to document URI parts, and inline file_data to a document blob part
  • the legacy events path now records useful content for these same parts instead of gen_ai.unknown

I kept unknown/future part types on the existing generic fallback, so this should be narrowly scoped to the documented Responses API part types.

Tests run:

  • uv run pytest tests/otel_integrations/test_openai.py -q -k "input_to_events or convert_responses_inputs"
  • uv run ruff check logfire/_internal/integrations/llm_providers/openai.py tests/otel_integrations/test_openai.py
  • uv run ruff format --check --diff logfire/_internal/integrations/llm_providers/openai.py tests/otel_integrations/test_openai.py
  • uv run pyright logfire/_internal/integrations/llm_providers/openai.py tests/otel_integrations/test_openai.py

AI disclosure: I used AI assistance while editing and reviewing this patch, then ran the tests and checks above locally.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: Ritwij Aryan Parmar <ritwij.aryan.parmar@gmail.com>
@RitwijParmar RitwijParmar force-pushed the codex/logfire-openai-responses-content-parts branch from 8249198 to fec0bc1 Compare May 28, 2026 17:44
Comment thread tests/otel_integrations/test_openai.py Outdated
Comment thread tests/otel_integrations/test_openai.py Outdated
Comment thread logfire/_internal/integrations/llm_providers/openai.py Outdated
Comment thread logfire/_internal/integrations/llm_providers/openai.py Outdated
Comment thread logfire/_internal/integrations/llm_providers/openai.py Outdated
@RitwijParmar

Copy link
Copy Markdown
Author

Updated this.

File IDs now use the semconv file part instead of an openai://file/... URI, and known image/file Responses parts no longer fall through to gen_ai.unknown on the events path.

Focused checks pass:

  • uv run pytest tests/otel_integrations/test_openai.py -k "responses_api_content_parts or multimodal_content_parts" -q
  • uv run ruff check logfire/_internal/integrations/llm_providers/openai.py logfire/_internal/integrations/llm_providers/semconv.py tests/otel_integrations/test_openai.py
  • uv run ruff format --check logfire/_internal/integrations/llm_providers/openai.py logfire/_internal/integrations/llm_providers/semconv.py tests/otel_integrations/test_openai.py

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c712c3cb-91c0-403b-a1a1-d24c4fe88a60

📥 Commits

Reviewing files that changed from the base of the PR and between 0524aa2 and 508b299.

📒 Files selected for processing (3)
  • logfire/_internal/integrations/llm_providers/openai.py
  • logfire/_internal/integrations/llm_providers/semconv.py
  • tests/otel_integrations/test_openai.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • pydantic/pydantic (auto-detected)
  • pydantic/pydantic-ai (auto-detected)
🚧 Files skipped from review as they are similar to previous changes (3)
  • logfire/_internal/integrations/llm_providers/semconv.py
  • logfire/_internal/integrations/llm_providers/openai.py
  • tests/otel_integrations/test_openai.py

📝 Walkthrough

Walkthrough

FilePart is added as a new TypedDict to the semconv type system with a type='file' discriminator, required file_id, and optional media_type and modality, and is included in the MessagePart union. _convert_content_part is rewritten to map Responses API types (input_text, input_image, input_file, input_audio) alongside existing Chat Completions types to appropriate semconv parts (TextPart, UriPart, BlobPart, FilePart), with unknown types returning a normalized dict. The input_to_events legacy path delegates per-item handling to a new _content_part_to_event helper. Two new tests cover both conversion paths.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for OpenAI Responses API content parts to the instrumentation.
Description check ✅ Passed The description is directly related to the changeset, explaining which Responses API content types are now supported and how the implementation addresses the gap.
Linked Issues check ✅ Passed The code changes fully address issue #1901: input_text now maps to text parts, input_image handles flat URL/file_id/file_data formats, input_file maps to document URI/blob parts, and legacy events path records useful content instead of unknown.
Out of Scope Changes check ✅ Passed All changes are narrowly scoped to supporting the three Responses API content types identified in #1901, with helper functions and type definitions appropriately limited to this feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@alexmojaki

Copy link
Copy Markdown
Collaborator

Please fix coverage

@RitwijParmar RitwijParmar force-pushed the codex/logfire-openai-responses-content-parts branch from 0524aa2 to 508b299 Compare June 19, 2026 16:47
@RitwijParmar

Copy link
Copy Markdown
Author

Fixed coverage. CI and Codecov are green now.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

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.

OpenAI Responses API content types input_text/input_image/input_file not recognized by instrument_openai

2 participants