Audio upload & download

    The raw /audio/upload-url and /audio/download-url endpoints return presigned S3 URLs so you can transfer bytes directly without tunneling them through the Nopaque API. The SDKs wrap both steps in a single upload and download call.

    Upload

    Returns an AudioFile once the upload succeeds. The helper handles presign → PUT to S3 → fetch metadata in one call.

    python
    from nopaque import Nopaque
    
    client = Nopaque()
    
    # Path string - SDK reads the file, presigns, PUTs to S3, returns metadata
    audio = client.audio.upload(file="welcome.wav")
    
    # Or any of these - all work
    audio = client.audio.upload(file=b"raw bytes", content_type="audio/wav", name="clip.wav")
    audio = client.audio.upload(file=open("welcome.wav", "rb"))

    Download

    Returns bytes by default, or writes to a path if you pass to.

    python
    # Return bytes
    data = client.audio.download("aud_abc123")
    
    # Write directly to a path
    client.audio.download("aud_abc123", to="/tmp/prompt.wav")

    Raw two-step flow

    If you need to hand the presigned URL to another system (CI, service-to-service transfer, browser upload widget), call the presign methods directly.

    python
    # Step 1: get a presigned URL from the Nopaque API
    presign = client.audio.create_upload_url(file_name="welcome.wav", content_type="audio/wav")
    print(presign.upload_url, presign.audio_id)
    
    # Step 2: PUT the bytes to S3 directly (your code)
    # ... e.g. using requests / httpx / fetch against presign.upload_url
    
    # Step 3: fetch the metadata once the upload completes
    audio = client.audio.get(presign.audio_id)

    Error handling

    Failures on the Nopaque API call (presign) surface as NopaqueAPIError subclasses as documented in Errors. Failures on the direct S3 PUT/GET surface as APIConnectionError with the S3 status code and response body attached for debugging.