Skip to content

feat: connect() falls back to CAPISCIO_API_KEY env var#62

Merged
beonde merged 2 commits intomainfrom
feat/connect-env-fallback
May 7, 2026
Merged

feat: connect() falls back to CAPISCIO_API_KEY env var#62
beonde merged 2 commits intomainfrom
feat/connect-env-fallback

Conversation

@beonde
Copy link
Copy Markdown
Member

@beonde beonde commented May 7, 2026

CapiscIO.connect() now reads api_key, agent_id, and server_url from environment variables when not passed explicitly.

Before

# Had to pass api_key explicitly
agent = CapiscIO.connect(api_key="sk_live_...")

# Or use the separate from_env() method
agent = CapiscIO.from_env()

After

export CAPISCIO_API_KEY=sk_live_...

# Zero-argument connect — reads from env automatically
agent = CapiscIO.connect()

# Still works with explicit key
agent = CapiscIO.connect(api_key="sk_live_...")

# from_env() still works for CAPISCIO_AGENT_NAME + CAPISCIO_DEV_MODE
agent = CapiscIO.from_env()

Env vars read by connect():

  • CAPISCIO_API_KEY — API key (falls back when api_key param is None)
  • CAPISCIO_AGENT_ID — Agent ID (falls back when agent_id param is None)
  • CAPISCIO_SERVER_URL — Server URL (falls back when server_url param is None, then production default)

Changes

  • connect(): api_key parameter changed from required str to Optional[str] = None
  • connect(): server_url parameter changed from str = PROD_REGISTRY to Optional[str] = None with env fallback
  • connect(): Added env var resolution at the top of the method body
  • from_env(): Simplified to delegate to connect() — only passes name and dev_mode from env since connect() handles the rest
  • Tests updated to match new behavior

CapiscIO.connect() now reads api_key, agent_id, and server_url
from environment variables when not passed explicitly:

  export CAPISCIO_API_KEY=sk_live_...
  agent = CapiscIO.connect()  # just works

This makes the zero-argument call the simplest path for users
who have already set their env vars. from_env() still exists
for the additional CAPISCIO_AGENT_NAME and CAPISCIO_DEV_MODE
env vars.
Copilot AI review requested due to automatic review settings May 7, 2026 00:58
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

✅ Documentation validation passed!

Unified docs will be deployed from capiscio-docs repo.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

✅ All checks passed! Ready for review.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

✅ SDK server contract tests passed (test_server_integration.py). Cross-product scenarios are validated in capiscio-e2e-tests.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates CapiscIO.connect() to support zero-argument usage by resolving api_key, agent_id, and server_url from environment variables when they aren’t provided explicitly, and simplifies from_env() to delegate to connect().

Changes:

  • Made connect() accept api_key: Optional[str] = None and added env var fallbacks for CAPISCIO_API_KEY, CAPISCIO_AGENT_ID, and CAPISCIO_SERVER_URL.
  • Updated from_env() to only pass name/dev_mode from env and rely on connect() for the rest.
  • Adjusted unit tests to match the new from_env() delegation behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
capiscio_sdk/connect.py Adds env var fallback logic to connect() and simplifies from_env() to delegate to it.
tests/unit/test_connect.py Updates from_env() tests to reflect the new delegation behavior.

Comment thread capiscio_sdk/connect.py Outdated
Comment on lines +323 to +325
agent_id = os.environ.get("CAPISCIO_AGENT_ID")
if server_url is None:
server_url = os.environ.get("CAPISCIO_SERVER_URL", PROD_REGISTRY)
Comment thread capiscio_sdk/connect.py
Comment on lines +314 to +321
if api_key is None:
api_key = os.environ.get("CAPISCIO_API_KEY")
if not api_key:
raise ValueError(
"api_key is required. Pass it directly or set the "
"CAPISCIO_API_KEY environment variable. "
"Get your API key at https://app.capisc.io"
)
Comment on lines 290 to 293
mock_connect.assert_called_once_with(
api_key="sk_test_env",
agent_id="env-agent-id",
name="Env Agent",
server_url="https://env.server.com",
dev_mode=True,
)
Comment on lines 307 to 310
mock_connect.assert_called_once_with(
api_key="sk_test_only",
agent_id=None,
name=None,
server_url=PROD_REGISTRY,
dev_mode=False,
)
…lback tests

- Empty/whitespace CAPISCIO_SERVER_URL now falls back to PROD_REGISTRY
  instead of passing empty string to httpx
- Added 4 unit tests for connect() env var fallback behavior:
  reads from env, raises when missing, handles empty server_url,
  reads custom server_url
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

✅ Documentation validation passed!

Unified docs will be deployed from capiscio-docs repo.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

✅ All checks passed! Ready for review.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

✅ SDK server contract tests passed (test_server_integration.py). Cross-product scenarios are validated in capiscio-e2e-tests.

@beonde beonde merged commit 64722b5 into main May 7, 2026
13 checks passed
@beonde beonde deleted the feat/connect-env-fallback branch May 7, 2026 14:48
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.

2 participants