Skip to content

Commit 578615a

Browse files
vercel-ai-sdk[bot]gr2mclaude
authored
Backport: fix(ai): remove custom User-Agent header from chat transport (#13338)
This is an automated backport of #13330 to the release-v6.0 branch. FYI @gr2m ## Related Issues Fixes #9256 Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3627ceb commit 578615a

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': patch
3+
---
4+
5+
Remove custom User-Agent header from HttpChatTransport to fix CORS preflight failures in Safari and Firefox

packages/ai/src/ui/http-chat-transport.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ describe('HttpChatTransport', () => {
148148
expect(server.calls[0].requestHeaders['x-test-header']).toBe(
149149
'test-value',
150150
);
151-
expect(server.calls[0].requestUserAgent).toContain('ai-sdk/');
152151
});
153152

154153
it('should include headers in the request when a function is provided', async () => {
@@ -179,7 +178,6 @@ describe('HttpChatTransport', () => {
179178
expect(server.calls[0].requestHeaders['x-test-header']).toBe(
180179
'test-value-fn',
181180
);
182-
expect(server.calls[0].requestUserAgent).toContain('ai-sdk/');
183181
});
184182
});
185183
});

packages/ai/src/ui/http-chat-transport.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ import {
33
Resolvable,
44
normalizeHeaders,
55
resolve,
6-
withUserAgentSuffix,
7-
getRuntimeEnvironmentUserAgent,
86
} from '@ai-sdk/provider-utils';
97
import { UIMessageChunk } from '../ui-message-stream/ui-message-chunks';
108
import { ChatTransport } from './chat-transport';
119
import { UIMessage } from './ui-messages';
12-
import { VERSION } from '../version';
1310

1411
export type PrepareSendMessagesRequest<UI_MESSAGE extends UIMessage> = (
1512
options: {
@@ -193,14 +190,10 @@ export abstract class HttpChatTransport<UI_MESSAGE extends UIMessage>
193190

194191
const response = await fetch(api, {
195192
method: 'POST',
196-
headers: withUserAgentSuffix(
197-
{
198-
'Content-Type': 'application/json',
199-
...headers,
200-
},
201-
`ai-sdk/${VERSION}`,
202-
getRuntimeEnvironmentUserAgent(),
203-
),
193+
headers: {
194+
'Content-Type': 'application/json',
195+
...headers,
196+
},
204197
body: JSON.stringify(body),
205198
credentials,
206199
signal: abortSignal,
@@ -252,11 +245,7 @@ export abstract class HttpChatTransport<UI_MESSAGE extends UIMessage>
252245

253246
const response = await fetch(api, {
254247
method: 'GET',
255-
headers: withUserAgentSuffix(
256-
headers,
257-
`ai-sdk/${VERSION}`,
258-
getRuntimeEnvironmentUserAgent(),
259-
),
248+
headers,
260249
credentials,
261250
});
262251

0 commit comments

Comments
 (0)