Class: OpenAI::Client

Inherits:
Internal::Transport::BaseClient show all
Includes:
Helpers::Realtime::ClientExtension, Helpers::ResponsesWebSocket::ClientExtension
Defined in:
lib/openai/client.rb,
sig/openai/client.rbs,
sig/openai/helpers/realtime/extensions.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.

Returns:

  • (2)
2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

Returns:

  • (Float)
600.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

Returns:

  • (Float)
0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

Returns:

  • (Float)
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

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

Methods included from Helpers::Realtime::ClientExtension

#request

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, request_body_replayable?, 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"]

Parameters:

  • api_key (String, nil) (defaults to: OpenAI::Internal::OMIT)

    Defaults to ENV["OPENAI_API_KEY"]. Mutually exclusive with workload_identity.

  • admin_api_key (String, nil) (defaults to: OpenAI::Internal::OMIT)

    Defaults to ENV["OPENAI_ADMIN_KEY"]

  • workload_identity (OpenAI::Auth::WorkloadIdentity, OpenAI::Auth::X509WorkloadIdentity, nil) (defaults to: nil)

    OAuth2 workload identity configuration for token exchange authentication. Mutually exclusive with api_key.

  • organization (String, nil) (defaults to: OpenAI::Internal::OMIT)

    Defaults to ENV["OPENAI_ORG_ID"].

  • project (String, nil) (defaults to: OpenAI::Internal::OMIT)

    Defaults to ENV["OPENAI_PROJECT_ID"].

  • webhook_secret (String, nil) (defaults to: OpenAI::Internal::OMIT)

    Defaults to ENV["OPENAI_WEBHOOK_SECRET"]

  • provider (OpenAI::Provider, nil) (defaults to: nil)

    Configure a supported third-party provider. Provider authentication and routing cannot be combined with top-level api_key, admin_api_key, workload_identity, or base_url.

  • base_url (String, nil) (defaults to: OpenAI::Internal::OMIT)

    Override the default base URL for the API, e.g.,

  • data_residency (Symbol, String, nil) (defaults to: nil)

    Select global, us, eu, or ae. Mutually exclusive with an explicit base_url or provider. This selects an endpoint; project and model eligibility still apply.

  • default_headers (Hash{String=>String, nil}, nil) (defaults to: nil)

    Extra headers to send with every request. Explicit values override ENV["OPENAI_CUSTOM_HEADERS"].

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float, nil) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)
  • http_client (#execute, nil) (defaults to: nil)

    The HTTP client used to execute SDK requests. Defaults to NetHTTPClient.

  • logger (#debug, #info, #warn, #error, nil) (defaults to: nil)

    Logger for SDK request diagnostics.

  • log_level (Symbol, String, nil) (defaults to: nil)

    SDK request log level. Defaults to ENV["OPENAI_LOG"], :info when logger is provided, and :off otherwise.

  • on_retry (Proc, nil) (defaults to: nil)

    Callback invoked immediately before an API retry delay.



605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
# File 'lib/openai/client.rb', line 605

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(", ")
      message = "`provider` cannot be combined with top-level #{formatted}. Move provider " \
        "authentication and routing options into `#{provider_name}(...)`."
      raise ArgumentError, message
    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()
  )

  @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)
  @videos = OpenAI::Resources::Videos.new(client: self)
end

Instance Attribute Details

#adminOpenAI::Resources::Admin (readonly)



107
108
109
# File 'lib/openai/client.rb', line 107

def admin
  @admin
end

#admin_api_keyString? (readonly)

Returns:

  • (String, nil)


28
29
30
# File 'lib/openai/client.rb', line 28

def admin_api_key
  @admin_api_key
end

#api_keyString? (readonly)

Returns:

  • (String, nil)


25
26
27
# File 'lib/openai/client.rb', line 25

def api_key
  @api_key
end

#audioOpenAI::Resources::Audio (readonly)



69
70
71
# File 'lib/openai/client.rb', line 69

def audio
  @audio
end

#batchesOpenAI::Resources::Batches (readonly)

Create large batches of API requests to run asynchronously.



100
101
102
# File 'lib/openai/client.rb', line 100

def batches
  @batches
end

#betaOpenAI::Resources::Beta (readonly)



96
97
98
# File 'lib/openai/client.rb', line 96

def beta
  @beta
end

#chatOpenAI::Resources::Chat (readonly)



49
50
51
# File 'lib/openai/client.rb', line 49

def chat
  @chat
end

#completionsOpenAI::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.



46
47
48
# File 'lib/openai/client.rb', line 46

def completions
  @completions
end

#containersOpenAI::Resources::Containers (readonly)



128
129
130
# File 'lib/openai/client.rb', line 128

def containers
  @containers
end

#content_provenance_checksOpenAI::Resources::ContentProvenanceChecks (readonly)



66
67
68
# File 'lib/openai/client.rb', line 66

def content_provenance_checks
  @content_provenance_checks
end

#conversationsOpenAI::Resources::Conversations (readonly)

Manage conversations and conversation items.



121
122
123
# File 'lib/openai/client.rb', line 121

def conversations
  @conversations
end

#embeddingsOpenAI::Resources::Embeddings (readonly)

Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.



54
55
56
# File 'lib/openai/client.rb', line 54

def embeddings
  @embeddings
end

#evalsOpenAI::Resources::Evals (readonly)

Manage and run evals in the OpenAI platform.



125
126
127
# File 'lib/openai/client.rb', line 125

def evals
  @evals
end

#filesOpenAI::Resources::Files (readonly)

Files are used to upload documents that can be used with features like Assistants and Fine-tuning.



59
60
61
# File 'lib/openai/client.rb', line 59

def files
  @files
end

#fine_tuningOpenAI::Resources::FineTuning (readonly)



81
82
83
# File 'lib/openai/client.rb', line 81

def fine_tuning
  @fine_tuning
end

#gradersOpenAI::Resources::Graders (readonly)



84
85
86
# File 'lib/openai/client.rb', line 84

def graders
  @graders
end

#imagesOpenAI::Resources::Images (readonly)

Given a prompt and/or an input image, the model will generate a new image.



63
64
65
# File 'lib/openai/client.rb', line 63

def images
  @images
end

#liveOpenAI::Resources::Live (readonly)



114
115
116
# File 'lib/openai/client.rb', line 114

def live
  @live
end

#modelsOpenAI::Resources::Models (readonly)

List and describe the various models available in the API.



78
79
80
# File 'lib/openai/client.rb', line 78

def models
  @models
end

#moderationsOpenAI::Resources::Moderations (readonly)

Given text and/or image inputs, classifies if those inputs are potentially harmful.



74
75
76
# File 'lib/openai/client.rb', line 74

def moderations
  @moderations
end

#organizationString? (readonly)

Returns:

  • (String, nil)


31
32
33
# File 'lib/openai/client.rb', line 31

def organization
  @organization
end

#projectString? (readonly)

Returns:

  • (String, nil)


34
35
36
# File 'lib/openai/client.rb', line 34

def project
  @project
end

#realtimeOpenAI::Resources::Realtime (readonly)



117
118
119
# File 'lib/openai/client.rb', line 117

def realtime
  @realtime
end

#responsesOpenAI::Resources::Responses (readonly)

Create and manage model responses.



111
112
113
# File 'lib/openai/client.rb', line 111

def responses
  @responses
end

#safetyOpenAI::Resources::Safety (readonly)



90
91
92
# File 'lib/openai/client.rb', line 90

def safety
  @safety
end

#skillsOpenAI::Resources::Skills (readonly)



131
132
133
# File 'lib/openai/client.rb', line 131

def skills
  @skills
end

#uploadsOpenAI::Resources::Uploads (readonly)

Use Uploads to upload large files in multiple parts.



104
105
106
# File 'lib/openai/client.rb', line 104

def uploads
  @uploads
end

#vector_storesOpenAI::Resources::VectorStores (readonly)



87
88
89
# File 'lib/openai/client.rb', line 87

def vector_stores
  @vector_stores
end

#videosOpenAI::Resources::Videos (readonly)



134
135
136
# File 'lib/openai/client.rb', line 134

def videos
  @videos
end

#webhook_secretString? (readonly)

Returns:

  • (String, nil)


37
38
39
# File 'lib/openai/client.rb', line 37

def webhook_secret
  @webhook_secret
end

#webhooksOpenAI::Resources::Webhooks (readonly)



93
94
95
# File 'lib/openai/client.rb', line 93

def webhooks
  @webhooks
end

#workload_identity_authOpenAI::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.



41
42
43
# File 'lib/openai/client.rb', line 41

def workload_identity_auth
  @workload_identity_auth
end

Instance Method Details

#adopt_workload_identity_auth!(authenticator) ⇒ 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.



545
546
547
548
549
550
551
552
553
554
555
# File 'lib/openai/client.rb', line 545

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_requestObject

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
# File 'sig/openai/helpers/realtime/extensions.rbs', line 4

def realtime_connection_request: (

#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.

Examples:

Select a regional endpoint for a call

client.with_options(base_url: "https://eu.api.openai.com/v1").responses.create(...)

Parameters:

  • overrides (Hash{Symbol=>Object})

    Options accepted by #initialize.

Returns:

  • (self)


495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/openai/client.rb', line 495

def with_options(**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)
    options = OpenAI::Internal::ClientOptions.copy(@copy_options, overrides.except(:data_residency))
    options.delete(:base_url) unless overrides.key?(:base_url)
    return copy_with_workload_identity_auth(options.merge(data_residency: residency))
  end

  options = OpenAI::Internal::ClientOptions.copy(@copy_options, overrides)
  adopted_identity = x509_identity?(options.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(options.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]
    options.delete(:base_url)
  end

  copy_with_workload_identity_auth(options)
end

#with_realtime_connection_requestObject

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
# File 'sig/openai/helpers/realtime/extensions.rbs', line 12

def with_realtime_connection_request: (

#with_responses_websocket_connection_requestObject

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
# File 'sig/openai/helpers/responses_websocket/extensions.rbs', line 4

def with_responses_websocket_connection_request: (