Skip to content

fix(openai): capture web search options and streaming citation annotations - #233

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
braintrustdata:mainfrom
atharvamhaske:fix/openai-web-search-tracing
Sep 14, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 1 commit into
braintrustdata:mainfrom
atharvamhaske:fix/openai-web-search-tracing

Conversation

@atharvamhaske

@atharvamhaske Atharva Mhaske (atharvamhaske) commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • web_search_options and prediction were missing from Chat Completions request metadata. Both are now captured.
  • Streaming responses were dropping URL citation annotations. They're now aggregated into the final message alongside content and tool_calls.

Verification

Confirmed against real API calls, not just SDK types, using a funded key.

  • openai-go v1.12.0's ChatCompletionNewParams.WebSearchOptions/Prediction fields are real.
  • A real streaming call to gpt-5-search-api with web_search_options set shows delta.annotations on the wire. It arrives whole in one chunk alongside finish_reason, not incrementally like content.
  • openai-go's typed ChatCompletionChunkChoiceDelta struct, and the Python/Node equivalents, don't declare an annotations field at all. The SDK types lag the real API. This tracer parses raw JSON directly instead of the typed struct, so that lag doesn't block the fix.
  • The originally cited gpt-4o-search-preview/gpt-4o-mini-search-preview models are now deprecated. Used gpt-5-search-api for the real test call instead.

Changes

  • trace/contrib/openai/chatcompletions.go: added web_search_options/prediction to the metadata field list. postprocessStreamingResults now accumulates delta.annotations across chunks into the final message.
  • trace/contrib/openai/chatcompletions_test.go: a unit test on StartSpan for the metadata fields (no network needed, since web_search_options/prediction require specific model support to call live), plus a real VCR-recorded streaming test against gpt-5-search-api confirming annotations survive aggregation.
  • examples/internal/openai-v1/main.go: new chat-web-search-streaming example.

Notes

make ci clean locally.

Closes #127

…ming citation annotations

Signed-off-by: atharvamhaske <atharvamhaske76@gmail.com>
@atharvamhaske

Copy link
Copy Markdown
Contributor Author

Abhijeet Prasad (@AbhiPrasad) ready for review, just small gap fix

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 2a695b2 into braintrustdata:main Sep 14, 2026
8 checks passed
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.

[bot] OpenAI Chat Completions tracer does not capture web_search_options or aggregate streaming URL citation annotations

2 participants