Skip to content

Bug: Ollama channel returns OpenAI SSE format instead of Claude format when RelayFormat is Claude #2378

@longkeyy

Description

@longkeyy

Bug Description

When using Claude format requests (/v1/messages) through the Ollama channel (with model alias), the SSE response format is incorrect.

Expected Behavior

Claude SSE format with event: and data: lines:

event: message_start
data: {"type":"message_start","message":{...}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"..."}}

Actual Behavior

OpenAI SSE format (only data: lines):

data: {"id":"...","object":"chat.completion.chunk","created":...,"model":"...","choices":[...]}

Root Cause

The ollamaStreamHandler function in /relay/channel/ollama/stream.go does not check info.RelayFormat. It always returns OpenAI format SSE responses regardless of the request format.

Affected Code

File: /relay/channel/ollama/stream.go
Function: ollamaStreamHandler (lines 66-181)

The function uses helper.StringData() directly instead of checking info.RelayFormat and using the appropriate format handler like openai.HandleStreamFormat().

Similar Issues in Other Channels

The following channels may have the same issue (not checking RelayFormat):

  • cloudflare
  • xai
  • cohere
  • zhipu
  • baidu
  • tencent
  • coze
  • dify

Proposed Fix

Modify ollamaStreamHandler to use openai.HandleStreamFormat() and openai.HandleFinalResponse() which already implement proper format switching based on info.RelayFormat.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions