mirror of
https://github.com/trycua/computer.git
synced 2026-04-28 19:23:23 -05: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:
@@ -9,14 +9,13 @@ from computer.providers.cloud.provider import CloudProvider
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
api_key = os.getenv("CUA_API_KEY")
|
||||
if not api_key:
|
||||
raise RuntimeError("CUA_API_KEY environment variable is not set")
|
||||
# CloudProvider will automatically read CUA_API_KEY from environment if not provided
|
||||
# You can still pass api_key explicitly if needed: CloudProvider(api_key="your_key")
|
||||
api_base = os.getenv("CUA_API_BASE")
|
||||
if api_base:
|
||||
print(f"Using API base: {api_base}")
|
||||
|
||||
provider = CloudProvider(api_key=api_key, verbose=True)
|
||||
provider = CloudProvider(verbose=True)
|
||||
async with provider:
|
||||
|
||||
# List all VMs
|
||||
|
||||
Reference in New Issue
Block a user