Class: Stagehand::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- Stagehand::Client
- Includes:
- Local::ClientPatch
- Defined in:
- lib/stagehand/client.rb
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.
60.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
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
-
#browserbase_api_key ⇒ String
readonly
Your [Browserbase API Key](www.browserbase.com/settings).
-
#browserbase_project_id ⇒ String
readonly
Deprecated.
-
#model_api_key ⇒ String
readonly
Your LLM provider API key (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.).
- #sessions ⇒ Stagehand::Resources::Sessions readonly
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary collapse
-
#initialize(browserbase_api_key: ENV["BROWSERBASE_API_KEY"], browserbase_project_id: nil, model_api_key: ENV["MODEL_API_KEY"], server: "remote", base_url: ENV["STAGEHAND_API_URL"] || ENV["STAGEHAND_BASE_URL"], 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) ⇒ Client
constructor
Creates and returns a new client for interacting with the API.
Methods included from Local::ClientPatch
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #request, #send_request, 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(browserbase_api_key: ENV["BROWSERBASE_API_KEY"], browserbase_project_id: nil, model_api_key: ENV["MODEL_API_KEY"], server: "remote", base_url: ENV["STAGEHAND_API_URL"] || ENV["STAGEHAND_BASE_URL"], 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) ⇒ Client
Creates and returns a new client for interacting with the API.
‘ENV`
this value is accepted for backwards compatibility and ignored.
Defaults to ‘ENV`
‘“api.example.com/v2/”`. Defaults to `ENV`, then `ENV`
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/stagehand/client.rb', line 86 def initialize( browserbase_api_key: ENV["BROWSERBASE_API_KEY"], browserbase_project_id: nil, model_api_key: ENV["MODEL_API_KEY"], server: "remote", base_url: ENV["STAGEHAND_API_URL"] || ENV["STAGEHAND_BASE_URL"], 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 ) @server = server base_url ||= "https://api.stagehand.browserbase.com" if browserbase_api_key.nil? raise ArgumentError, "browserbase_api_key is required, and can be set via environ: \"BROWSERBASE_API_KEY\"" end if model_api_key.nil? raise ArgumentError, "model_api_key is required, and can be set via environ: \"MODEL_API_KEY\"" end headers = {} custom_headers_env = ENV["STAGEHAND_CUSTOM_HEADERS"] unless custom_headers_env.nil? parsed = {} 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 headers = parsed.merge(headers) end @browserbase_api_key = browserbase_api_key.to_s @browserbase_project_id = browserbase_project_id.to_s @model_api_key = model_api_key.to_s 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 ) @sessions = Stagehand::Resources::Sessions.new(client: self) end |
Instance Attribute Details
#browserbase_api_key ⇒ String (readonly)
Your [Browserbase API Key](www.browserbase.com/settings)
20 21 22 |
# File 'lib/stagehand/client.rb', line 20 def browserbase_api_key @browserbase_api_key end |
#browserbase_project_id ⇒ String (readonly)
Deprecated. Browserbase API keys are now project-scoped, so this value is accepted for backwards compatibility and ignored.
25 26 27 |
# File 'lib/stagehand/client.rb', line 25 def browserbase_project_id @browserbase_project_id end |
#model_api_key ⇒ String (readonly)
Your LLM provider API key (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.)
29 30 31 |
# File 'lib/stagehand/client.rb', line 29 def model_api_key @model_api_key end |
#sessions ⇒ Stagehand::Resources::Sessions (readonly)
32 33 34 |
# File 'lib/stagehand/client.rb', line 32 def sessions @sessions end |