Skip to content

Safari User Agent error when sending messages #9256

@dylanmoz

Description

@dylanmoz

Description

In safari, I get this error when sending a message: failed to load resource: request header field User-Agent is not allowed by Access-Control-Allow-Headers.

The user agent header is:

  • In safari: ai-sdk/5.0.53 runtime/browser
  • In chrome: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36

It seems in Chrome the browser overrides the user-agent header to what it wants it to be. However in Safari it lets it be custom, which is the value that vercel ai provides.

I'm curious if this is an issue with just my specific setup with my server/usage. I wonder if https://github.com/vercel/ai-chatbot will run into this issue when it upgrades ai. I think the version that introduced the issue is 5.0.43, but ai-chatbot uses an older version.

My workaround is to delete that header key. I'm already able to do this because I'm overriding the fetch call for useChat:

useChat({ transport: new DefaultChatTransport({ fetch: async (_, init) => { ... } }) })

AI SDK Version

'ai': 5.0.53
'@ai-sdk/react': 2.0.52

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

ai/corecore functions like generateText, streamText, etc. Provider utils, and provider spec.support

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions