Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@f-trycua
Copy link
Collaborator

Summary

Adds automatic environment variable support for CUA_API_KEY, eliminating the need to explicitly pass the API key to Computer and CloudProvider constructors when the environment variable is set.

Changes

  • CloudProvider: Made api_key parameter optional with automatic fallback to CUA_API_KEY environment variable
  • Computer: Added automatic fallback to CUA_API_KEY environment variable when api_key is not provided
  • Documentation: Updated all Python examples to show simplified usage pattern
  • Examples: Updated cloud_api_examples.py to demonstrate the cleaner API

Benefits

  • Cleaner API: No need to manually read environment variables in user code
  • Better developer experience: Follows common patterns used by other SDKs (OpenAI, Anthropic, etc.)
  • Backward compatible: Explicit api_key parameter still works and takes precedence

Usage

Before:

cua_api_key = os.environ.get("CUA_API_KEY")
computer = Computer(
    os_type="windows",
    provider_type="cloud",
    name="s-windows-jxvu65a1",
    api_key=cua_api_key
)

After:

# Just set the environment variable
# export CUA_API_KEY="sk_cua-api01_..."

computer = Computer(
    os_type="windows",
    provider_type="cloud",
    name="s-windows-jxvu65a1",
)

Test plan

  • Verify Computer reads from CUA_API_KEY when api_key parameter is not provided
  • Verify explicit api_key parameter takes precedence over environment variable
  • Verify appropriate error message when neither parameter nor environment variable is set
  • Test with existing cloud sandbox examples

🤖 Generated with Claude Code

…nd 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 <[email protected]>
@vercel
Copy link

vercel bot commented Nov 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs Ready Ready Preview Comment Nov 19, 2025 6:37pm

@f-trycua f-trycua merged commit 849d476 into main Nov 19, 2025
10 of 11 checks passed
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
libs/python/computer/computer/computer.py 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants