From 31b8c6a214dbfd7f1c711869572301ef7bf41b58 Mon Sep 17 00:00:00 2001 From: Sos Pogosyan <55689991+ZeeeUs@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:33:07 +0300 Subject: [PATCH] fix(api): correct Content-Type header for /api/chat and /api/generate when using cloud models (#13279) --------- Co-authored-by: Pogosyan Sos Co-authored-by: Patrick Devine --- server/routes.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server/routes.go b/server/routes.go index 16df3f4f..e5e6dd5a 100644 --- a/server/routes.go +++ b/server/routes.go @@ -262,6 +262,12 @@ func (s *Server) GenerateHandler(c *gin.Context) { slog.Warn("embedded messages in the model not supported with '/api/generate'; try '/api/chat' instead") } + contentType := "application/x-ndjson" + if req.Stream != nil && !*req.Stream { + contentType = "application/json; charset=utf-8" + } + c.Header("Content-Type", contentType) + fn := func(resp api.GenerateResponse) error { resp.Model = origModel resp.RemoteModel = m.Config.RemoteModel @@ -303,12 +309,6 @@ func (s *Server) GenerateHandler(c *gin.Context) { return } - contentType := "application/json; charset=utf-8" - if req.Stream != nil && *req.Stream { - contentType = "application/x-ndjson" - } - c.Header("Content-Type", contentType) - return } @@ -1939,6 +1939,12 @@ func (s *Server) ChatHandler(c *gin.Context) { } } + contentType := "application/x-ndjson" + if req.Stream != nil && !*req.Stream { + contentType = "application/json; charset=utf-8" + } + c.Header("Content-Type", contentType) + fn := func(resp api.ChatResponse) error { resp.Model = origModel resp.RemoteModel = m.Config.RemoteModel @@ -1980,12 +1986,6 @@ func (s *Server) ChatHandler(c *gin.Context) { return } - contentType := "application/json; charset=utf-8" - if req.Stream != nil && *req.Stream { - contentType = "application/x-ndjson" - } - c.Header("Content-Type", contentType) - return }