Skip to content

Conversation

@omkute10
Copy link

@omkute10 omkute10 commented Nov 8, 2025

Description

This PR adds timeout support for both synchronous and asynchronous stream operations in the Hyperspell Python SDK. The changes ensure that long-running streams don't hang indefinitely by allowing users to set a maximum duration for stream operations.

Key Changes:

  • Added timeout parameter to Stream and AsyncStream constructors
  • Implemented timeout logic for both sync and async stream iterations
  • Added proper error handling for timeout scenarios
  • Improved resource cleanup in context managers
  • Added comprehensive docstrings and type hints

Usage Example:

# Synchronous stream with 30-second timeout
with client.resources.completions.create(
    messages=[...],
    stream=True,
    timeout=30.0  # Timeout in seconds
) as stream:
    for chunk in stream:
        print(chunk)

# Asynchronous stream with 60-second timeout
async with await client.resources.completions.acreate(
    messages=[...],
    stream=True,
    timeout=60.0  # Timeout in seconds
) as stream:
    async for chunk in stream:
        print(chunk)

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.

1 participant