Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ruby_llm/providers/anthropic/streaming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ class Anthropic
module Streaming
private

def stream_response(connection, payload, additional_headers = {}, &)
# Avoid Net::HTTP's auto-inflate: Cloudflare's gzip flushes
# infrequently for SSE, batching chunks until each flush.
super(connection, payload, additional_headers.merge('Accept-Encoding' => 'identity'), &)
end

def stream_url
completion_url
end
Expand Down
24 changes: 24 additions & 0 deletions spec/ruby_llm/providers/anthropic/streaming_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe RubyLLM::Providers::Anthropic::Streaming do
include_context 'with configured RubyLLM'

it 'sends Accept-Encoding: identity on streaming requests' do
captured = nil

stub_request(:post, %r{api\.anthropic\.com/v1/messages})
.with { |req| captured = req.headers['Accept-Encoding'] }
.to_return(
status: 200,
body: '',
headers: { 'Content-Type' => 'text/event-stream' }
)

chat = RubyLLM.chat(model: 'claude-haiku-4-5', provider: :anthropic)
chat.ask('hi') { |_chunk| nil }

expect(captured).to eq('identity')
end
end
Loading