Class: OpenAI::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- OpenAI::Client
- Includes:
- Helpers::LiveWebSocket::ClientExtension, Helpers::Realtime::ClientExtension, Helpers::ResponsesWebSocket::ClientExtension, WebSocket::ClientRequest
- Defined in:
- lib/openai/client.rb,
lib/openai/helpers/client_runtime.rb,
sig/openai/client.rbs,
sig/openai/helpers/websocket.rbs,
sig/openai/helpers/client_runtime.rbs,
sig/openai/helpers/live/websocket.rbs,
sig/openai/helpers/realtime/extensions.rbs,
sig/openai/helpers/realtime/translation.rbs,
sig/openai/helpers/responses_websocket/extensions.rbs
Constant Summary collapse
- DEFAULT_MAX_RETRIES =
Default max number of retries to attempt after a failed retryable request.
2- DEFAULT_TIMEOUT_IN_SECONDS =
Default per-request timeout.
600.0- DEFAULT_INITIAL_RETRY_DELAY =
Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.
0.5- DEFAULT_MAX_RETRY_DELAY =
Default max retry delay in seconds.
8.0- WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER =
"workload-identity-auth"
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
- #admin ⇒ OpenAI::Resources::Admin readonly
- #admin_api_key ⇒ String? readonly
- #api_key ⇒ String? readonly
- #audio ⇒ OpenAI::Resources::Audio readonly
-
#batches ⇒ OpenAI::Resources::Batches
readonly
Create large batches of API requests to run asynchronously.
- #beta ⇒ OpenAI::Resources::Beta readonly
- #chat ⇒ OpenAI::Resources::Chat readonly
-
#completions ⇒ OpenAI::Resources::Completions
readonly
Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
- #containers ⇒ OpenAI::Resources::Containers readonly
- #content_provenance_checks ⇒ OpenAI::Resources::ContentProvenanceChecks readonly
-
#conversations ⇒ OpenAI::Resources::Conversations
readonly
Manage conversations and conversation items.
-
#decisions ⇒ OpenAI::Resources::Decisions
readonly
Generated resource accessors.
-
#embeddings ⇒ OpenAI::Resources::Embeddings
readonly
Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
-
#evals ⇒ OpenAI::Resources::Evals
readonly
Manage and run evals in the OpenAI platform.
-
#files ⇒ OpenAI::Resources::Files
readonly
Files are used to upload documents that can be used with features like Assistants and Fine-tuning.
- #fine_tuning ⇒ OpenAI::Resources::FineTuning readonly
- #graders ⇒ OpenAI::Resources::Graders readonly
-
#images ⇒ OpenAI::Resources::Images
readonly
Given a prompt and/or an input image, the model will generate a new image.
- #live ⇒ OpenAI::Resources::Live readonly
-
#models ⇒ OpenAI::Resources::Models
readonly
List and describe the various models available in the API.
-
#moderations ⇒ OpenAI::Resources::Moderations
readonly
Given text and/or image inputs, classifies if those inputs are potentially harmful.
- #organization ⇒ String? readonly
- #project ⇒ String? readonly
- #realtime ⇒ OpenAI::Resources::Realtime readonly
-
#responses ⇒ OpenAI::Resources::Responses
readonly
Create and manage model responses.
- #safety ⇒ OpenAI::Resources::Safety readonly
- #skills ⇒ OpenAI::Resources::Skills readonly
-
#uploads ⇒ OpenAI::Resources::Uploads
readonly
Use Uploads to upload large files in multiple parts.
- #vector_stores ⇒ OpenAI::Resources::VectorStores readonly
- #webhook_secret ⇒ String? readonly
- #webhooks ⇒ OpenAI::Resources::Webhooks readonly
- #workload_identity_auth ⇒ OpenAI::Auth::WorkloadIdentityAuth? readonly private
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #log_level, #logger, #max_retries, #max_retry_delay, #on_retry, #requester, #timeout
Instance Method Summary collapse
- #adopt_workload_identity_auth!(authenticator) ⇒ void private
-
#initialize(api_key: OpenAI::Internal::OMIT, admin_api_key: OpenAI::Internal::OMIT, workload_identity: nil, organization: OpenAI::Internal::OMIT, project: OpenAI::Internal::OMIT, webhook_secret: OpenAI::Internal::OMIT, provider: nil, base_url: OpenAI::Internal::OMIT, data_residency: nil, default_headers: nil, max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, http_client: nil, logger: nil, log_level: nil, on_retry: nil) ⇒ Client
constructor
Creates and returns a new client for interacting with the API.
- #realtime_connection_request ⇒ OpenAI::Internal::Transport::BaseClient::request_input private
- #with_live_websocket_connection_request {|request, arg1| ... } ⇒ top private
-
#with_options(**overrides) ⇒ self
Returns a new client of the same class with the supplied constructor options overridden.
- #with_realtime_connection_request {|request, arg1| ... } ⇒ top private
- #with_responses_websocket_connection_request {|request, arg1| ... } ⇒ top private
- #with_translation_connection_request {|request, arg1| ... } ⇒ top private
- #with_websocket_connection_request {|request, arg1| ... } ⇒ top private
Methods included from Helpers::Realtime::ClientExtension
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #request, request_body_replayable?, #request_streaming_body, should_retry?, validate!
Methods included from Internal::Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(api_key: OpenAI::Internal::OMIT, admin_api_key: OpenAI::Internal::OMIT, workload_identity: nil, organization: OpenAI::Internal::OMIT, project: OpenAI::Internal::OMIT, webhook_secret: OpenAI::Internal::OMIT, provider: nil, base_url: OpenAI::Internal::OMIT, data_residency: nil, default_headers: nil, max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, http_client: nil, logger: nil, log_level: nil, on_retry: nil) ⇒ Client
Creates and returns a new client for interacting with the API.
"https://api.example.com/v2/". Defaults to ENV["OPENAI_BASE_URL"]
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/openai/client.rb', line 230 def initialize( api_key: OpenAI::Internal::OMIT, admin_api_key: OpenAI::Internal::OMIT, workload_identity: nil, organization: OpenAI::Internal::OMIT, project: OpenAI::Internal::OMIT, webhook_secret: OpenAI::Internal::OMIT, provider: nil, base_url: OpenAI::Internal::OMIT, data_residency: nil, default_headers: nil, max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, http_client: nil, logger: nil, log_level: nil, on_retry: nil ) if Object.instance_method(:is_a?).bind_call(workload_identity, OpenAI::Auth::X509WorkloadIdentity) && !x509_identity?(workload_identity) raise ArgumentError, "X509WorkloadIdentity subclasses are not supported" end x509_identity = x509_identity?(workload_identity) if x509_identity && (configured_transport = workload_identity.transport) if !http_client.nil? && !http_client.equal?(configured_transport) raise ArgumentError, "X.509 workload identity must use its configured X.509 transport" end http_client = configured_transport end if x509_identity && !x509_transport?(http_client) raise ArgumentError, "X.509 workload identity requires an attested X509Transport" end base_url = OpenAI::Internal::ClientOptions.resolve_data_residency( data_residency, base_url: base_url, provider: provider ) if x509_transport?(http_client) && !data_residency.nil? unless http_client.supports_data_residency?(data_residency) raise ArgumentError, "X.509 data residency must match its attested OpenAI mTLS API origin" end base_url = "#{http_client.api_origin}/v1" end provider_runtime = nil unless provider.nil? provider_name = OpenAI::Internal::Provider.name(provider) conflicts = { api_key: api_key, admin_api_key: admin_api_key, workload_identity: workload_identity, base_url: base_url }.filter_map do |name, value| name unless value.equal?(OpenAI::Internal::OMIT) || value.nil? end unless conflicts.empty? formatted = conflicts.map { "`#{_1}`" }.join(", ") = "`provider` cannot be combined with top-level #{formatted}. Move provider " \ "authentication and routing options into `#{provider_name}(...)`." raise ArgumentError, end provider_runtime = OpenAI::Internal::Provider.configure(provider) end api_key = ENV["OPENAI_API_KEY"] if api_key.equal?(OpenAI::Internal::OMIT) && provider_runtime.nil? if admin_api_key.equal?(OpenAI::Internal::OMIT) && provider_runtime.nil? admin_api_key = ENV["OPENAI_ADMIN_KEY"] end if organization.equal?(OpenAI::Internal::OMIT) && provider_runtime.nil? organization = ENV["OPENAI_ORG_ID"] end project = ENV["OPENAI_PROJECT_ID"] if project.equal?(OpenAI::Internal::OMIT) && provider_runtime.nil? webhook_secret = ENV["OPENAI_WEBHOOK_SECRET"] if webhook_secret.equal?(OpenAI::Internal::OMIT) base_url = ENV["OPENAI_BASE_URL"] if base_url.equal?(OpenAI::Internal::OMIT) && provider_runtime.nil? api_key = nil if api_key.equal?(OpenAI::Internal::OMIT) admin_api_key = nil if admin_api_key.equal?(OpenAI::Internal::OMIT) organization = nil if organization.equal?(OpenAI::Internal::OMIT) project = nil if project.equal?(OpenAI::Internal::OMIT) webhook_secret = nil if webhook_secret.equal?(OpenAI::Internal::OMIT) base_url = provider_runtime.base_url if provider_runtime base_url = nil if base_url.equal?(OpenAI::Internal::OMIT) base_url ||= if x509_transport?(http_client) "#{http_client.api_origin}/v1" else "https://api.openai.com/v1" end if x509_identity configured_uri = URI(base_url.to_s) unless configured_uri.is_a?(URI::HTTPS) && configured_uri.userinfo.nil? && configured_uri.port == URI::HTTPS::DEFAULT_PORT && OpenAI::Internal::Util.uri_origin(configured_uri).casecmp?(http_client.api_origin) raise ArgumentError, "X.509 workload identity requires its attested OpenAI mTLS API origin" end end if !api_key.nil? && !workload_identity.nil? raise ArgumentError, "`api_key` and `workload_identity` are mutually exclusive" end if provider_runtime.nil? && api_key.nil? && admin_api_key.nil? && workload_identity.nil? raise( ArgumentError, "Missing credentials. Please pass an `api_key`, `workload_identity`, `admin_api_key`, or set the `OPENAI_API_KEY` or `OPENAI_ADMIN_KEY` environment variable." ) end headers = { "openai-organization" => (@organization = organization&.to_s), "openai-project" => (@project = project&.to_s) } parsed = {} resolved_headers = default_headers.is_a?(OpenAI::Internal::ClientOptions::ResolvedHeaders) custom_headers_env = ENV["OPENAI_CUSTOM_HEADERS"] unless provider_runtime || resolved_headers unless custom_headers_env.nil? custom_headers_env.split("\n").each do |line| colon = line.index(":") unless colon.nil? parsed[line[0...colon].strip] = line[(colon + 1)..].strip end end end client_headers = OpenAI::Internal::Util.normalized_headers(default_headers.to_h) unless provider_runtime.nil? provider_runtime.authentication_headers.each { client_headers.delete(_1) } end headers = OpenAI::Internal::Util.normalized_headers(parsed, headers, client_headers) if workload_identity.nil? @api_key = api_key&.to_s @workload_identity_auth = nil else @api_key = WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER token_exchange = if x509_identity OpenAI::Auth::X509TokenExchange.new(workload_identity, transport: http_client) end @workload_identity_auth = OpenAI::Auth::WorkloadIdentityAuth.new( workload_identity, organization&.to_s, token_exchange_url: if x509_identity "#{OpenAI::Auth::X509Transport::ISSUER_ORIGIN}/oauth/token" else OpenAI::Auth::WorkloadIdentityAuth::DEFAULT_TOKEN_EXCHANGE_URL end, token_exchange: token_exchange ) end @admin_api_key = admin_api_key&.to_s @webhook_secret = webhook_secret&.to_s @provider_runtime = provider_runtime super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, headers: headers, http_client: http_client, logger: logger, log_level: log_level, on_retry: on_retry ) @copy_options = OpenAI::Internal::ClientOptions.capture( api_key: api_key, admin_api_key: @admin_api_key, workload_identity: workload_identity, organization: @organization, project: @project, webhook_secret: @webhook_secret, provider: provider, base_url: provider.nil? ? self.base_url.to_s : nil, default_headers: OpenAI::Internal::Util.normalized_headers(parsed, client_headers), max_retries: self.max_retries(), timeout: self.timeout(), initial_retry_delay: self.initial_retry_delay(), max_retry_delay: self.max_retry_delay(), http_client: requester, logger: self.logger(), log_level: self.log_level(), on_retry: self.on_retry() ) # Initialize generated resources. @decisions = OpenAI::Resources::Decisions.new(client: self) @completions = OpenAI::Resources::Completions.new(client: self) @chat = OpenAI::Resources::Chat.new(client: self) @embeddings = OpenAI::Resources::Embeddings.new(client: self) @files = OpenAI::Resources::Files.new(client: self) @images = OpenAI::Resources::Images.new(client: self) @content_provenance_checks = OpenAI::Resources::ContentProvenanceChecks.new(client: self) @audio = OpenAI::Resources::Audio.new(client: self) @moderations = OpenAI::Resources::Moderations.new(client: self) @models = OpenAI::Resources::Models.new(client: self) @fine_tuning = OpenAI::Resources::FineTuning.new(client: self) @graders = OpenAI::Resources::Graders.new(client: self) @vector_stores = OpenAI::Resources::VectorStores.new(client: self) @safety = OpenAI::Resources::Safety.new(client: self) @webhooks = OpenAI::Resources::Webhooks.new(client: self) @beta = OpenAI::Resources::Beta.new(client: self) @batches = OpenAI::Resources::Batches.new(client: self) @uploads = OpenAI::Resources::Uploads.new(client: self) @admin = OpenAI::Resources::Admin.new(client: self) @responses = OpenAI::Resources::Responses.new(client: self) @live = OpenAI::Resources::Live.new(client: self) @realtime = OpenAI::Resources::Realtime.new(client: self) @conversations = OpenAI::Resources::Conversations.new(client: self) @evals = OpenAI::Resources::Evals.new(client: self) @containers = OpenAI::Resources::Containers.new(client: self) @skills = OpenAI::Resources::Skills.new(client: self) end |
Instance Attribute Details
#admin ⇒ OpenAI::Resources::Admin (readonly)
112 113 114 |
# File 'lib/openai/client.rb', line 112 def admin @admin end |
#admin_api_key ⇒ String? (readonly)
29 30 31 |
# File 'lib/openai/client.rb', line 29 def admin_api_key @admin_api_key end |
#api_key ⇒ String? (readonly)
26 27 28 |
# File 'lib/openai/client.rb', line 26 def api_key @api_key end |
#audio ⇒ OpenAI::Resources::Audio (readonly)
74 75 76 |
# File 'lib/openai/client.rb', line 74 def audio @audio end |
#batches ⇒ OpenAI::Resources::Batches (readonly)
Create large batches of API requests to run asynchronously.
105 106 107 |
# File 'lib/openai/client.rb', line 105 def batches @batches end |
#beta ⇒ OpenAI::Resources::Beta (readonly)
101 102 103 |
# File 'lib/openai/client.rb', line 101 def beta @beta end |
#chat ⇒ OpenAI::Resources::Chat (readonly)
54 55 56 |
# File 'lib/openai/client.rb', line 54 def chat @chat end |
#completions ⇒ OpenAI::Resources::Completions (readonly)
Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
51 52 53 |
# File 'lib/openai/client.rb', line 51 def completions @completions end |
#containers ⇒ OpenAI::Resources::Containers (readonly)
133 134 135 |
# File 'lib/openai/client.rb', line 133 def containers @containers end |
#content_provenance_checks ⇒ OpenAI::Resources::ContentProvenanceChecks (readonly)
71 72 73 |
# File 'lib/openai/client.rb', line 71 def content_provenance_checks @content_provenance_checks end |
#conversations ⇒ OpenAI::Resources::Conversations (readonly)
Manage conversations and conversation items.
126 127 128 |
# File 'lib/openai/client.rb', line 126 def conversations @conversations end |
#decisions ⇒ OpenAI::Resources::Decisions (readonly)
Generated resource accessors.
46 47 48 |
# File 'lib/openai/client.rb', line 46 def decisions @decisions end |
#embeddings ⇒ OpenAI::Resources::Embeddings (readonly)
Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
59 60 61 |
# File 'lib/openai/client.rb', line 59 def @embeddings end |
#evals ⇒ OpenAI::Resources::Evals (readonly)
Manage and run evals in the OpenAI platform.
130 131 132 |
# File 'lib/openai/client.rb', line 130 def evals @evals end |
#files ⇒ OpenAI::Resources::Files (readonly)
Files are used to upload documents that can be used with features like Assistants and Fine-tuning.
64 65 66 |
# File 'lib/openai/client.rb', line 64 def files @files end |
#fine_tuning ⇒ OpenAI::Resources::FineTuning (readonly)
86 87 88 |
# File 'lib/openai/client.rb', line 86 def fine_tuning @fine_tuning end |
#graders ⇒ OpenAI::Resources::Graders (readonly)
89 90 91 |
# File 'lib/openai/client.rb', line 89 def graders @graders end |
#images ⇒ OpenAI::Resources::Images (readonly)
Given a prompt and/or an input image, the model will generate a new image.
68 69 70 |
# File 'lib/openai/client.rb', line 68 def images @images end |
#live ⇒ OpenAI::Resources::Live (readonly)
119 120 121 |
# File 'lib/openai/client.rb', line 119 def live @live end |
#models ⇒ OpenAI::Resources::Models (readonly)
List and describe the various models available in the API.
83 84 85 |
# File 'lib/openai/client.rb', line 83 def models @models end |
#moderations ⇒ OpenAI::Resources::Moderations (readonly)
Given text and/or image inputs, classifies if those inputs are potentially harmful.
79 80 81 |
# File 'lib/openai/client.rb', line 79 def moderations @moderations end |
#organization ⇒ String? (readonly)
32 33 34 |
# File 'lib/openai/client.rb', line 32 def organization @organization end |
#project ⇒ String? (readonly)
35 36 37 |
# File 'lib/openai/client.rb', line 35 def project @project end |
#realtime ⇒ OpenAI::Resources::Realtime (readonly)
122 123 124 |
# File 'lib/openai/client.rb', line 122 def realtime @realtime end |
#responses ⇒ OpenAI::Resources::Responses (readonly)
Create and manage model responses.
116 117 118 |
# File 'lib/openai/client.rb', line 116 def responses @responses end |
#safety ⇒ OpenAI::Resources::Safety (readonly)
95 96 97 |
# File 'lib/openai/client.rb', line 95 def safety @safety end |
#skills ⇒ OpenAI::Resources::Skills (readonly)
136 137 138 |
# File 'lib/openai/client.rb', line 136 def skills @skills end |
#uploads ⇒ OpenAI::Resources::Uploads (readonly)
Use Uploads to upload large files in multiple parts.
109 110 111 |
# File 'lib/openai/client.rb', line 109 def uploads @uploads end |
#vector_stores ⇒ OpenAI::Resources::VectorStores (readonly)
92 93 94 |
# File 'lib/openai/client.rb', line 92 def vector_stores @vector_stores end |
#webhook_secret ⇒ String? (readonly)
38 39 40 |
# File 'lib/openai/client.rb', line 38 def webhook_secret @webhook_secret end |
#webhooks ⇒ OpenAI::Resources::Webhooks (readonly)
98 99 100 |
# File 'lib/openai/client.rb', line 98 def webhooks @webhooks end |
#workload_identity_auth ⇒ OpenAI::Auth::WorkloadIdentityAuth? (readonly)
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.
42 43 44 |
# File 'lib/openai/client.rb', line 42 def workload_identity_auth @workload_identity_auth end |
Instance Method Details
#adopt_workload_identity_auth!(authenticator) ⇒ 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.
390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/openai/helpers/client_runtime.rb', line 390 def adopt_workload_identity_auth!(authenticator) identity = @copy_options.fetch(:workload_identity) unless x509_identity?(identity) && x509_transport?(@requester) && OpenAI::Auth::X509Transport.exact_instance?(authenticator, OpenAI::Auth::WorkloadIdentityAuth) && authenticator.bound_to?(identity, transport: @requester) raise ArgumentError, "X.509 authenticator must match its workload identity and attested transport" end @workload_identity_auth = authenticator end |
#realtime_connection_request ⇒ OpenAI::Internal::Transport::BaseClient::request_input
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.
4 5 6 7 8 9 |
# File 'sig/openai/helpers/realtime/extensions.rbs', line 4
def realtime_connection_request: (
path: String,
query: ::Hash[String, String],
?websocket_base_url: String?,
?options: OpenAI::request_opts?
) -> OpenAI::Internal::Transport::BaseClient::request_input
|
#with_live_websocket_connection_request {|request, arg1| ... } ⇒ top
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.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'sig/openai/helpers/live/websocket.rbs', line 4
def with_live_websocket_connection_request: (
?path: String | ::Array[String],
?query: ::Hash[String, String],
?websocket_base_url: String?,
?options: OpenAI::request_opts?
) {
(
OpenAI::Internal::Transport::BaseClient::request_input request,
^-> void mark_handshake_completed
) -> top
} -> top
|
#with_options(**overrides) ⇒ self
Returns a new client of the same class with the supplied constructor options overridden. Other settings and the HTTP transport are inherited. The original client is unchanged. Header overrides are merged; nil removes an individual header, and default_headers: nil clears all custom default headers. Subclasses with incompatible constructors or a private .new must override this method if they need to support copying.
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/openai/helpers/client_runtime.rb', line 340 def (**overrides) if overrides.key?(:workload_identity) && !overrides.key?(:http_client) selected_identity = overrides.fetch(:workload_identity) if x509_identity?(selected_identity) && (configured_transport = selected_identity.transport) overrides = overrides.merge(http_client: configured_transport) end end previous_transport = @copy_options.fetch(:http_client) transport = overrides.fetch(:http_client, previous_transport) if overrides[:data_residency] && x509_transport?(transport) residency = overrides.fetch(:data_residency) = OpenAI::Internal::ClientOptions.copy(@copy_options, overrides.except(:data_residency)) .delete(:base_url) unless overrides.key?(:base_url) return copy_with_workload_identity_auth(.merge(data_residency: residency)) end = OpenAI::Internal::ClientOptions.copy(@copy_options, overrides) adopted_identity = x509_identity?(.fetch(:workload_identity)) && !x509_identity?(@copy_options.fetch(:workload_identity)) previous_origin = previous_transport.api_origin if x509_transport?(previous_transport) selected_origin = transport.api_origin if x509_transport?(transport) if adopted_identity && selected_origin inherited_origin = OpenAI::Internal::Util.uri_origin(URI(.fetch(:base_url).to_s)) adopted_identity = !inherited_origin.casecmp?(selected_origin) end if (adopted_identity || previous_origin != selected_origin) && !overrides.key?(:base_url) && !overrides[:data_residency] .delete(:base_url) end copy_with_workload_identity_auth() end |
#with_realtime_connection_request {|request, arg1| ... } ⇒ top
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.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'sig/openai/helpers/realtime/extensions.rbs', line 12
def with_realtime_connection_request: (
path: String,
query: ::Hash[String, String],
?websocket_base_url: String?,
?options: OpenAI::request_opts?
) {
(
OpenAI::Internal::Transport::BaseClient::request_input request,
^-> void mark_handshake_completed
) -> top
} -> top
|
#with_responses_websocket_connection_request {|request, arg1| ... } ⇒ top
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.
4 5 6 7 8 9 10 11 12 |
# File 'sig/openai/helpers/responses_websocket/extensions.rbs', line 4
def with_responses_websocket_connection_request: (
?websocket_base_url: String?,
?options: OpenAI::request_opts?
) {
(
OpenAI::Internal::Transport::BaseClient::request_input request,
^-> void mark_handshake_completed
) -> top
} -> top
|
#with_translation_connection_request {|request, arg1| ... } ⇒ top
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.
4 5 6 7 8 9 10 11 12 13 |
# File 'sig/openai/helpers/realtime/translation.rbs', line 4
def with_translation_connection_request: (
model: String,
?websocket_base_url: String?,
?options: OpenAI::request_opts?
) {
(
OpenAI::Internal::Transport::BaseClient::request_input request,
^-> void mark_handshake_completed
) -> top
} -> top
|
#with_websocket_connection_request {|request, arg1| ... } ⇒ top
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.
4 5 6 7 8 9 10 11 12 13 |
# File 'sig/openai/helpers/websocket.rbs', line 4
def with_websocket_connection_request: (
request: OpenAI::Internal::Transport::BaseClient::request_components,
?websocket_base_url: String?,
?options: OpenAI::request_opts?
) {
(
OpenAI::Internal::Transport::BaseClient::request_input request,
^-> void mark_handshake_completed
) -> top
} -> top
|