mirror of
https://github.com/trycua/computer.git
synced 2026-01-02 03:20:22 -06:00
Add automatic CUA_API_KEY environment variable support for Computer and CloudProvider
Previously, users had to explicitly read the CUA_API_KEY environment variable and pass it to the Computer/CloudProvider constructor. This change makes the API key parameter optional and automatically reads from the CUA_API_KEY environment variable if not provided. Changes: - CloudProvider.__init__: Made api_key parameter optional, reads from CUA_API_KEY env var - Computer.__init__: Added fallback to CUA_API_KEY env var for api_key parameter - Updated documentation examples to show simplified usage without explicit api_key - Updated cloud_api_examples.py to demonstrate the new simpler pattern This provides a cleaner API while maintaining backward compatibility with explicit api_key parameter passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -98,13 +98,17 @@ class Computer:
|
||||
host: Host to use for VM provider connections (e.g. "localhost", "host.docker.internal")
|
||||
storage: Optional path for persistent VM storage (Lumier provider)
|
||||
ephemeral: Whether to use ephemeral storage
|
||||
api_key: Optional API key for cloud providers
|
||||
api_key: Optional API key for cloud providers (defaults to CUA_API_KEY environment variable)
|
||||
experiments: Optional list of experimental features to enable (e.g. ["app-use"])
|
||||
"""
|
||||
|
||||
self.logger = Logger("computer", verbosity)
|
||||
self.logger.info("Initializing Computer...")
|
||||
|
||||
# Fall back to environment variable for api_key if not provided
|
||||
if api_key is None:
|
||||
api_key = os.environ.get("CUA_API_KEY")
|
||||
|
||||
if not image:
|
||||
if os_type == "macos":
|
||||
image = "macos-sequoia-cua:latest"
|
||||
|
||||
@@ -31,18 +31,21 @@ class CloudProvider(BaseVMProvider):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
api_key: str,
|
||||
api_key: Optional[str] = None,
|
||||
verbose: bool = False,
|
||||
api_base: Optional[str] = None,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Args:
|
||||
api_key: API key for authentication
|
||||
api_key: API key for authentication (defaults to CUA_API_KEY environment variable)
|
||||
name: Name of the VM
|
||||
verbose: Enable verbose logging
|
||||
"""
|
||||
assert api_key, "api_key required for CloudProvider"
|
||||
# Fall back to environment variable if api_key not provided
|
||||
if api_key is None:
|
||||
api_key = os.getenv("CUA_API_KEY")
|
||||
assert api_key, "api_key required for CloudProvider (provide via parameter or CUA_API_KEY environment variable)"
|
||||
self.api_key = api_key
|
||||
self.verbose = verbose
|
||||
self.api_base = (api_base or DEFAULT_API_BASE).rstrip("/")
|
||||
|
||||
Reference in New Issue
Block a user