[GH-ISSUE #4001] CORS configuration error blocking authorization in Ollama's OpenAI compatible endpoint #48990

Closed
opened 2026-04-28 10:33:40 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @mnixry on GitHub (Apr 28, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4001

Originally assigned to: @BruceMacD on GitHub.

What is the issue?

Related: #3571

Ollama's implementation of an OpenAI-compatible endpoint faces a CORS (Cross-Origin Resource Sharing) configuration issue. The preflight OPTIONS response currently includes the headers

HTTP/1.1 204 No Content
Access-Control-Allow-Headers: Origin,Content-Length,Content-Type
Access-Control-Allow-Methods: GET,POST,PUT,PATCH,DELETE,HEAD,OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 43200
Date: Sun, 28 Apr 2024 10:41:22 GMT

However, this setup is insufficient for compatibility with OpenAI's authentication requirements, which utilize the Authorization header.

When attempting POST requests, browsers enforce security policies that block the request due to the absence of the Authorization header in the Access-Control-Allow-Headers. This results in the error: missing token 'authorization' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel.

To resolve this issue, the CORS configuration in the Gin middleware should be updated to include Authorization in the Access-Control-Allow-Headers:

114c932a8e/server/routes.go (L972-L993)

OS

Linux

GPU

AMD

CPU

AMD

Ollama version

0.1.32

Originally created by @mnixry on GitHub (Apr 28, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4001 Originally assigned to: @BruceMacD on GitHub. ### What is the issue? Related: #3571 Ollama's implementation of an OpenAI-compatible endpoint faces a CORS (Cross-Origin Resource Sharing) configuration issue. The preflight OPTIONS response currently includes the headers ```http HTTP/1.1 204 No Content Access-Control-Allow-Headers: Origin,Content-Length,Content-Type Access-Control-Allow-Methods: GET,POST,PUT,PATCH,DELETE,HEAD,OPTIONS Access-Control-Allow-Origin: * Access-Control-Max-Age: 43200 Date: Sun, 28 Apr 2024 10:41:22 GMT ```` However, this setup is insufficient for compatibility with OpenAI's authentication requirements, which utilize the `Authorization` header. When attempting POST requests, browsers enforce security policies that block the request due to the absence of the Authorization header in the Access-Control-Allow-Headers. This results in the error: `missing token 'authorization' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel.` To resolve this issue, the CORS configuration in the Gin middleware should be updated to include Authorization in the Access-Control-Allow-Headers: https://github.com/ollama/ollama/blob/114c932a8e872846fc714353c65d041feb886027/server/routes.go#L972-L993 ### OS Linux ### GPU AMD ### CPU AMD ### Ollama version 0.1.32
GiteaMirror added the bug label 2026-04-28 10:33:40 -05:00
Author
Owner

@BruceMacD commented on GitHub (May 1, 2024):

Hi @mnixry, thanks for bringing this up. It looks to be pretty common with OpenAI clients. I've opened a pull request that should fix. I'll let you know when it gets merged.

The branch is brucemacd/auth-cors if you'd like to test it out.

<!-- gh-comment-id:2089086348 --> @BruceMacD commented on GitHub (May 1, 2024): Hi @mnixry, thanks for bringing this up. It looks to be pretty common with OpenAI clients. I've opened a pull request that should fix. I'll let you know when it gets merged. The branch is `brucemacd/auth-cors` if you'd like to test it out.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#48990