alexrudall/ruby-openai

Get response headers

hooopo opened this issue · 2 comments

How to get response headers from openai response using ruby-openai?

The rate-limit info which in response headers is useful sometimes

I have a similar problem, when using the Helicone proxy, you receive the helicone-id attribute as a response header.

UPDATE:

I managed to access the response headers using a Faraday Middleware, references:

Example:

class MyMiddleware < Faraday::Middleware
  def on_request(env)
    # puts env[:request_headers]
  end

  def on_complete(env)
    # puts env[:response_headers]
    # puts options[:foo]
  end
end

...

client = OpenAI::Client.new do |f|
  f.use MyMiddleware, foo: 'bar'
end

Thanks, @mllocs