Class: OpenAI::RequestOptions

Inherits:
Internal::Type::BaseModel show all
Defined in:
lib/openai/request_options.rb

Overview

Specify HTTP behaviour to use for a specific request. These options supplement or override those provided at the client level.

When making a request, you can pass an actual RequestOptions instance, or simply pass a Hash with symbol keys matching the attributes on this class.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Internal::Type::BaseModel

==, #==, #[], coerce, #deconstruct_keys, #deep_to_h, dump, fields, hash, #hash, inherited, inspect, #inspect, known_fields, optional, recursively_to_h, required, #to_h, #to_json, #to_s, to_sorbet_type, #to_yaml

Methods included from Internal::Type::Converter

#coerce, coerce, #dump, dump, #inspect, inspect, type_info

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(values = {}) ⇒ Object

Returns a new instance of RequestOptions.

Parameters:

  • values (Hash{Symbol=>Object}) (defaults to: {})


73
74
75
# File 'lib/openai/request_options.rb', line 73

define_sorbet_constant!(:OrHash) do
  T.type_alias { T.any(OpenAI::RequestOptions, OpenAI::Internal::AnyHash) }
end

Instance Attribute Details

#extra_bodyObject?

Extra data to send with the request. These are deep merged into any data generated as part of the normal request.

Returns:

  • (Object, nil)


54
# File 'lib/openai/request_options.rb', line 54

optional :extra_body, OpenAI::Internal::Type::HashOf[OpenAI::Internal::Type::Unknown]

#extra_headersHash{String=>String, nil}?

Extra headers to send with the request. These are ‘.merged`’d into any `extra_headers` given at the client level.

Returns:

  • (Hash{String=>String, nil}, nil)


47
# File 'lib/openai/request_options.rb', line 47

optional :extra_headers, OpenAI::Internal::Type::HashOf[String, nil?: true]

#extra_queryHash{String=>Array<String>, String, nil}?

Extra query params to send with the request. These are ‘.merge`’d into any `query` given at the client level.

Returns:

  • (Hash{String=>Array<String>, String, nil}, nil)


40
# File 'lib/openai/request_options.rb', line 40

optional :extra_query, OpenAI::Internal::Type::HashOf[OpenAI::Internal::Type::ArrayOf[String]]

#idempotency_keyString?

Idempotency key to send with request and all associated retries. Will only be sent for write requests.

Returns:

  • (String, nil)


33
# File 'lib/openai/request_options.rb', line 33

optional :idempotency_key, String

#max_retriesInteger?

Maximum number of retries to attempt after a failed initial request.

Returns:

  • (Integer, nil)


60
# File 'lib/openai/request_options.rb', line 60

optional :max_retries, Integer

#timeoutFloat?

Request timeout in seconds.

Returns:

  • (Float, nil)


66
# File 'lib/openai/request_options.rb', line 66

optional :timeout, Float

Class Method Details

.validate!(opts) ⇒ Object

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.

Parameters:

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/openai/request_options.rb', line 15

def self.validate!(opts)
  case opts
  in OpenAI::RequestOptions | Hash
    opts.to_h.each_key do |k|
      unless fields.include?(k)
        raise ArgumentError.new("Request `opts` keys must be one of #{fields.keys}, got #{k.inspect}")
      end
    end
  else
    raise ArgumentError.new("Request `opts` must be a Hash or RequestOptions, got #{opts.inspect}")
  end
end