Class: OpenAI::RequestOptions

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

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

Attributes inherited from Internal::Type::BaseModel

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Internal::Type::BaseModel

==, #==, #[], #_request_id, #_set_last_response, coerce, #deconstruct_keys, #deep_to_h, dump, #encode_with, 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, coerce_with_error, dump, #dump, #inspect, inspect, meta_info, new_coerce_state, 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: {})


95
96
97
# File 'lib/openai/request_options.rb', line 95

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.

Parameters:

  • value (top, nil)

Returns:

  • (Object, nil)


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

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.

Parameters:

  • value (::Hash[String, String?], nil)

Returns:

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


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

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.

Parameters:

  • value (::Hash[String, (::Array[String] | String)?], nil)

Returns:

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


50
51
52
53
# File 'lib/openai/request_options.rb', line 50

optional(
  :extra_query,
  OpenAI::Internal::Type::HashOf[{union: ExtraQueryValue}, nil?: true]
)

#idempotency_keyString?

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

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


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

optional :idempotency_key, String

#include_raw_bodyBoolean?

Retain the exact successful HTTP response body on the returned model, page, or direct binary StringIO response through last_response.body. Body retention is disabled by default and cannot be enabled for streaming responses.

Parameters:

Returns:



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

optional :include_raw_body, OpenAI::Internal::Type::Boolean

#max_retriesInteger?

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

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)


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

optional :max_retries, Integer

#timeoutFloat?

Request timeout in seconds.

Parameters:

  • value (Float, nil)

Returns:

  • (Float, nil)


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

optional :timeout, Float

Class Method Details

.validate!(opts) ⇒ 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.

Parameters:

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/openai/request_options.rb', line 25

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