Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-openrouter): set errorType from error_type on response.failed #2268

Mergedpcbeingused33(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/2268/headmerged by AlemTuzlak View on GitHub

pcbeingused33(GitHub profile, opens in a new tab)commented

🎯 Changes

Fixes #2267

OpenRouter ends a failed Responses stream with response.failed, which carries response.error_type next to response.error. Both response.failed branches in the Responses adapter (chatStream and structuredOutputStream) built RUN_ERROR from response.error.code only, so the error type was lost. code is coarse (server_error covers overloads, timeouts and auth failures).

Both branches now set errorType, which chat() moves to metadata.tanstack.errorType. The SDK parses the field as response.errorType; the unknown-event fallback now maps error_type to it too. The value goes through toRunErrorDetails, so the same 128-character limit as other adapters applies.

  • Unit: four cases (both methods, parsed and fallback events) fail on main and pass here.
  • E2E: openrouter-responses-error-type-wire feeds the SSE from the issue through the real SDK parser.
  • Docs: one sentence in docs/chat/stream-events.md.

Verified locally: @tanstack/ai-openrouter tests (423 passed) and tsc, @tanstack/ai-e2e tsc, the new Playwright spec. The full pnpm run test:pr was not run.

This change was prepared with AI assistance.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • OpenRouter Responses errors now preserve the provider’s error type in chat and structured-output streams. When a provider reports an issue such as overload, that type is included in the reported error alongside the server-error code.
  • Documentation
    • Updated the stream-events documentation to describe the error type included with OpenRouter Responses errors.
    1. Pushedba93032

    2. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit ba930324c81c7c185a8efdaaab400f63314e451c

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 51sView ↗
      nx run-many --targets=test:coverage --projects=...✅ Succeeded<1sView ↗
      nx run-many --targets=build --exclude=examples/...✅ Succeeded12sView ↗

      💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


      ☁️ Nx Cloud last updated this comment at 2026-11-30 09:32:10 UTC

    3. AlemTuzlak approved these changes

    4. AlemTuzlak merged this3b09c46

    5. AlemTuzlak closed this

Sign in to join this conversation.