Skip to content

fix(providers/openai): emit source parts for Responses API streaming annotations#10

Open
kylecarbs wants to merge 1 commit intomainfrom
fix/openai-responses-api-source-annotations
Open

fix(providers/openai): emit source parts for Responses API streaming annotations#10
kylecarbs wants to merge 1 commit intomainfrom
fix/openai-responses-api-source-annotations

Conversation

@kylecarbs
Copy link
Copy Markdown
Member

Problem

The OpenAI Responses API streaming path was missing a handler for response.output_text.annotation.added events. This meant that url_citation and file_citation annotations—which carry source URLs and titles for web search results—were silently dropped during streaming.

The non-streaming Generate path and the Chat Completions API streaming path both handled annotations correctly; only the Responses API Stream path was affected. This caused downstream consumers (e.g. chatd in coder/coder) to receive tool-call, tool-result, reasoning, and text parts but zero source parts when using OpenAI web search.

Intended upstream target: charmbracelet/fantasy (opened here on fork due to permissions; please merge upstream.)

Fix

Add a case "response.output_text.annotation.added" to the streaming event switch in responses_language_model.go that:

  • Parses the annotation from the event (any type in the SDK, deserializes as map[string]interface{})
  • For url_citation: yields a StreamPartTypeSource with SourceTypeURL, URL, and title
  • For file_citation: yields a StreamPartTypeSource with SourceTypeDocument and the filename as title

This matches the existing behavior in:

  • The Responses API Generate path (lines 770-796)
  • The Chat Completions API streaming path (parseAnnotationsFromDelta)
  • The Anthropic provider streaming path

Test

Updated TestResponsesStream_WebSearchResponse to:

  • Include response.output_text.annotation.added events in the mock stream (matching real API behavior observed in recorded test data)
  • Assert that two StreamPartTypeSource parts are emitted with correct URL, title, source type, and non-empty IDs

…annotations

The Responses API streaming path was missing a handler for
"response.output_text.annotation.added" events. This meant that
url_citation and file_citation annotations—which carry source
URLs and titles for web search results—were silently dropped
during streaming.

The non-streaming Generate path and the Chat Completions API
streaming path both handled annotations correctly; only the
Responses API Stream path was affected.

Add a case for "response.output_text.annotation.added" that
parses the annotation map and yields StreamPartTypeSource parts
for url_citation and file_citation types, matching the behavior
of the existing Generate path and the Anthropic provider.

Update TestResponsesStream_WebSearchResponse to include
annotation.added events in the mock stream and assert that
source parts are emitted with the correct URL, title, and type.
@kylecarbs kylecarbs force-pushed the fix/openai-responses-api-source-annotations branch from ef923d6 to 5bc340a Compare March 25, 2026 11:50
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.

1 participant