Class: OpenAI::ResponseMetadata
- Inherits:
-
Object
- Object
- OpenAI::ResponseMetadata
- Defined in:
- lib/openai/http_client.rb,
sig/openai/http_client.rbs
Overview
Metadata from the HTTP response backing a top-level SDK value.
Instance Attribute Summary collapse
-
#body ⇒ String?
readonly
The exact response body when
include_raw_body: truewas requested. -
#headers ⇒ Hash{String=>String}
readonly
Immutable response headers with lowercase String keys.
-
#request_id ⇒ String?
readonly
The request ID returned in the
x-request-idresponse header. -
#status ⇒ Integer
readonly
The HTTP response status code.
Instance Method Summary collapse
-
#encode_with(coder) ⇒ void
private
Keep retained response bodies out of Psych object serialization.
- #init_with(coder) ⇒ void private
-
#initialize(status:, headers:, body: nil) ⇒ ResponseMetadata
constructor
private
A new instance of ResponseMetadata.
-
#inspect ⇒ String
Inspect metadata without exposing sensitive response headers.
-
#marshal_dump ⇒ Array(Integer, Hash{String=>String})
private
Keep retained response bodies out of Marshal object serialization.
- #marshal_load(values) ⇒ void private
Constructor Details
#initialize(status:, headers:, body: nil) ⇒ ResponseMetadata
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ResponseMetadata.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/openai/http_client.rb', line 34 def initialize(status:, headers:, body: nil) @status = Integer(status) @headers = headers .to_h do |name, value| [name.to_s.downcase.freeze, value.to_s.dup.freeze] end .freeze @request_id = @headers["x-request-id"] @body = body.nil? || body.frozen? ? body : body.dup.freeze freeze end |
Instance Attribute Details
#body ⇒ String? (readonly)
The exact response body when include_raw_body: true was requested.
Bodies are never retained by default or for streaming responses.
27 28 29 |
# File 'lib/openai/http_client.rb', line 27 def body @body end |
#headers ⇒ Hash{String=>String} (readonly)
Immutable response headers with lowercase String keys.
16 17 18 |
# File 'lib/openai/http_client.rb', line 16 def headers @headers end |
#request_id ⇒ String? (readonly)
The request ID returned in the x-request-id response header.
21 22 23 |
# File 'lib/openai/http_client.rb', line 21 def request_id @request_id end |
#status ⇒ Integer (readonly)
The HTTP response status code.
11 12 13 |
# File 'lib/openai/http_client.rb', line 11 def status @status end |
Instance Method Details
#encode_with(coder) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Keep retained response bodies out of Psych object serialization.
56 57 58 59 |
# File 'lib/openai/http_client.rb', line 56 def encode_with(coder) coder["status"] = @status coder["headers"] = @headers end |
#init_with(coder) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
64 65 66 |
# File 'lib/openai/http_client.rb', line 64 def init_with(coder) initialize(status: coder["status"], headers: coder["headers"]) end |
#inspect ⇒ String
Inspect metadata without exposing sensitive response headers.
49 |
# File 'lib/openai/http_client.rb', line 49 def inspect = "#<#{self.class} status=#{@status} request_id=#{@request_id.inspect}>" |
#marshal_dump ⇒ Array(Integer, Hash{String=>String})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Keep retained response bodies out of Marshal object serialization.
72 |
# File 'lib/openai/http_client.rb', line 72 def marshal_dump = [@status, @headers] |
#marshal_load(values) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
77 78 79 80 |
# File 'lib/openai/http_client.rb', line 77 def marshal_load(values) status, headers = values initialize(status: status, headers: headers) end |