Get response headers
hooopo opened this issue · 2 comments
hooopo commented
How to get response headers from openai response using ruby-openai?
The rate-limit info which in response headers is useful sometimes
mllocs commented
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:
- https://github.com/alexrudall/ruby-openai?tab=readme-ov-file#verbose-logging
- https://lostisland.github.io/faraday/#/middleware/custom-middleware
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'
endalexrudall commented
Thanks, @mllocs