Skip to content

Conversation

@AryanBagade
Copy link
Contributor

Summary

Fixes #711
Improves AI SDK error handling in tracing to capture comprehensive error details including responseBody, statusCode, responseHeaders, and cause fields. Previously, only the error name was captured via String(error), which lost critical debugging information.

Changes

  • Updated error handling in aiSdk.ts (3 locations):

    • Non-streaming error handler (lines 780-824)
    • Streaming error handler (lines 1007-1044)
    • Now manually constructs error objects to preserve all
      available fields
  • Added comprehensive unit tests in aiSdk.test.ts:

    • Test for non-streaming error handling with tracing enabled
    • Test for streaming error handling with tracing enabled
    • Both tests verify that error fields like responseBody and statusCode are preserved
  • Created changeset for version management

Technical Details

When tracing is enabled, errors are now captured as:

{
  name: error.name,
  message: error.message,
  responseBody: error.responseBody,    // ← New!
  responseHeaders: error.responseHeaders, // ← New!
  statusCode: error.statusCode,        // ← New!
  cause: error.cause                   // ← New!
}

This provides developers with complete error context for debugging AI SDK errors, including:

  • Rate limit error details and retry information
  • API-specific error codes and messages
  • Request IDs for support tickets
  • HTTP status codes

Safety: Error details are only captured when tracing is explicitly enabled by the user.

   SDK error messages in tracing
  Fixes openai#711
When AI SDK providers return errors, the tracing system now captures comprehensive error details including responseBody, statusCode, responseHeaders, and cause fields. Previously, only the error name and message were captured via String(error), which lost critical debugging information.
@changeset-bot
Copy link

changeset-bot bot commented Dec 8, 2025

🦋 Changeset detected

Latest commit: cc420d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@openai/agents-extensions Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@seratch seratch added this to the 0.3.x milestone Dec 9, 2025
@seratch seratch changed the title fix(agents-extensions): improve AI SDK error messages in tracing fix(agents-extensions): ##711 improve AI SDK error details in tracing Dec 9, 2025
@seratch seratch merged commit 2a77585 into openai:main Dec 9, 2025
4 checks passed
@AryanBagade AryanBagade deleted the fix/issue-711-comprehensive-ai-sdk-error-messages branch December 9, 2025 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The AI SDK requires more comprehensive error messages

2 participants