Skip to content

fix(openai-compatible): handle thinking content arrays#13704

Open
tobwen wants to merge 1 commit intovercel:mainfrom
tobwen:fix/openai-compatible-thinking-content-arrays
Open

fix(openai-compatible): handle thinking content arrays#13704
tobwen wants to merge 1 commit intovercel:mainfrom
tobwen:fix/openai-compatible-thinking-content-arrays

Conversation

@tobwen
Copy link

@tobwen tobwen commented Mar 20, 2026

Background

Some OpenAI-compatible providers (see #13703) return structured content arrays (including thinking parts) in chat responses/chunks, while the current implementation expected string-only content in key paths. This caused validation failures (expected string, received array) and broke generate/stream flows.

Summary

  • Add support for array-shaped content in OpenAI-compatible chat response/chunk schemas.
  • Normalize known content-part types:
    • text parts -> text output
    • thinking parts -> reasoning output
  • Keep compatibility precedence:
    • reasoning_content > reasoning > reasoning extracted from thinking
  • Keep schema future-proof by allowing unknown array part types without failing validation.
  • Add regression tests for:
    • non-stream content arrays with thinking
    • stream content arrays with thinking
    • unknown content part types in both paths
  • Add patch changeset.

Manual Verification

  • Ran package tests:
    • corepack pnpm --filter @ai-sdk/openai-compatible test:node -- src/chat/openai-compatible-chat-language-model.test.ts
    • Result: all tests passed (including new regression tests)
  • Ran package type-check:
    • corepack pnpm --filter @ai-sdk/openai-compatible type-check
    • Result: passed

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

  • Consider extracting the content normalization helper for reuse if similar parsing logic is needed in other OpenAI-compatible surfaces.

Related Issues

#13703

@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/openai-compatible Issues related to the @ai-sdk/openai-compatible provider labels Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/openai-compatible Issues related to the @ai-sdk/openai-compatible provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant