| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…-sdk/anthropic providers When using a custom provider with api.npm = '@ai-sdk/anthropic' and a custom baseURL (e.g. relay/proxy), two bugs cause empty or malformed requests: Bug 1: normalizeMessages only filtered empty text/reasoning parts but let tool-result blocks with empty string or empty array content pass through. The Anthropic API (and any relay) rejects these with 'content field is empty'. Fix: map tool-result parts before filtering, replacing empty content with a '(empty)' placeholder string. Bug 2: applyCaching used model.providerID === 'anthropic' to decide whether to attach cache control at message level vs content part level. Custom providers (providerID != 'anthropic') using @ai-sdk/anthropic always got content-level options which the SDK ignores, so caching never worked and extra fields were sent to the relay. Fix: use model.api.npm === '@ai-sdk/anthropic' for the check instead. Fixes anomalyco#6473 Fixes anomalyco#14642
|
The following comment was made by an LLM, it may be inaccurate: I found a related PR: Related PR Found:
This PR (#17363) appears to be a more comprehensive fix that combines:
The current PR fixes both issues #6473 and #14642, and may supersede or complement PR #14643. |
Sorry, something went wrong.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Sorry, something went wrong.
|
lgtm |
Sorry, something went wrong.
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Issue for this PR
Fixes #6473
Fixes #14642
Type of change
What does this PR do?
When using a custom provider to use anthropic models two bugs cause empty or malformed requests:
Bug 1: normalizeMessages only filtered empty text/reasoning parts but let tool-result blocks with empty string or empty array content pass. Relay APIs may rejects these with 'content field is empty' but official anthropic api could filter these out somehow. Fix: map tool-result parts before filtering, replacing empty content with a '(empty)' placeholder string.
Bug 2: applyCaching used model.providerID === 'anthropic' to decide whether to attach cache control at message level vs content part level. Custom providers (providerID != 'anthropic') using @ai-sdk/anthropic always got content-level options which the SDK ignores, so cache never worked and extra fields were sent to the relay.
Fix: use model.api.npm === '@ai-sdk/anthropic' for the check instead.
How did you verify your code works?
Added test suite custom provider with @ai-sdk/anthropic (relay/proxy) covering:
Screenshots / recordings
N/A — no UI changes.
Checklist