Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/reductoai/reducto-python-sdk/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The Reducto class is the main synchronous client for interacting with the Reducto API. It handles authentication, request configuration, and provides access to all API resources.

Constructor

from reducto import Reducto

client = Reducto(
    api_key="your-api-key",
    environment="production",
    timeout=60.0,
    max_retries=2,
)

Parameters

api_key
str
required
Your Reducto API key. If not provided, the client will automatically read from the REDUCTO_API_KEY environment variable.You can obtain your API key from the Reducto dashboard.
environment
Literal['production', 'eu', 'au']
default:"production"
The API environment to use. Available options:
base_url
str | httpx.URL | None
Override the base URL for the API. If provided, this takes precedence over the environment parameter.You can also set this via the REDUCTO_BASE_URL environment variable.
timeout
float | Timeout | None
default:"3600.0"
Request timeout in seconds. Defaults to 1 hour (3600 seconds).For more granular control, pass an httpx.Timeout object:
import httpx
client = Reducto(
    timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0)
)
max_retries
int
default:"2"
Maximum number of retries for failed requests. Defaults to 2.The client automatically retries:
  • Connection errors
  • 408 Request Timeout
  • 409 Conflict
  • 429 Rate Limit
  • 5xx Server errors
Set to 0 to disable retries.
default_headers
Mapping[str, str] | None
Additional headers to include with every request.
client = Reducto(
    default_headers={"X-Custom-Header": "value"}
)
default_query
Mapping[str, object] | None
Default query parameters to include with every request.
http_client
httpx.Client | None
Custom httpx client instance for advanced use cases. Use this to configure:
  • Custom proxies
  • Custom transports
  • Connection pooling
import httpx
from reducto import Reducto, DefaultHttpxClient

client = Reducto(
    http_client=DefaultHttpxClient(
        proxy="http://my.proxy.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    )
)

Basic Usage

With Environment Variable

The recommended approach is to set your API key as an environment variable:
import os
from reducto import Reducto

# Set REDUCTO_API_KEY in your environment or .env file
client = Reducto()

response = client.parse.run(
    input="https://pdfobject.com/pdf/sample.pdf",
)

With Explicit API Key

from reducto import Reducto

client = Reducto(
    api_key="your-api-key",
)

response = client.parse.run(
    input="https://pdfobject.com/pdf/sample.pdf",
)

With EU Environment

from reducto import Reducto

client = Reducto(
    environment="eu",
)

response = client.parse.run(
    input="https://pdfobject.com/pdf/sample.pdf",
)

Client Methods

upload()

Upload a file directly to Reducto for processing. Returns a reducto:// URL that can be used in subsequent API calls.
from pathlib import Path
from reducto import Reducto

client = Reducto()

# Upload a file
upload_response = client.upload(
    file=Path("document.pdf"),
    extension="pdf"  # Optional: specify file extension
)

print(upload_response.url)  # reducto://...

# Use the uploaded file in a parse operation
parse_response = client.parse.run(
    input=upload_response.url,
)
file
FileTypes | str | None
The file to upload. Can be:
  • A Path object
  • Raw bytes
  • A tuple of (filename, contents, media_type)
extension
str | None
Optional file extension hint (e.g., “pdf”, “docx”)

api_version()

Get the current API version.
from reducto import Reducto

client = Reducto()

version = client.api_version()
print(version)

Available Resources

The Reducto client provides access to the following resource namespaces:
  • client.parse - Document parsing operations
  • client.split - Document splitting operations
  • client.extract - Data extraction operations
  • client.edit - Document editing operations
  • client.job - Job management operations
  • client.pipeline - Pipeline operations
  • client.webhook - Webhook configuration

Advanced Features

Context Manager

Use the client as a context manager to ensure proper resource cleanup:
from reducto import Reducto

with Reducto() as client:
    response = client.parse.run(
        input="https://pdfobject.com/pdf/sample.pdf",
    )
    # HTTP client is automatically closed when exiting

Per-Request Configuration

Override client settings for individual requests:
client = Reducto()

# Override timeout for a specific request
response = client.with_options(timeout=5.0).parse.run(
    input="https://pdfobject.com/pdf/sample.pdf",
)

# Override max retries
response = client.with_options(max_retries=5).parse.run(
    input="https://pdfobject.com/pdf/sample.pdf",
)

Raw Response Access

Access raw HTTP response data including headers:
response = client.parse.with_raw_response.run(
    input="https://pdfobject.com/pdf/sample.pdf",
)

print(response.headers.get('X-Request-Id'))
parse_result = response.parse()  # Get the parsed response object

Streaming Response

Stream response data for large payloads:
with client.parse.with_streaming_response.run(
    input="https://pdfobject.com/pdf/sample.pdf",
) as response:
    print(response.headers.get("Content-Type"))
    
    for line in response.iter_lines():
        print(line)

Error Handling

The client raises specific exceptions for different error types:
import reducto
from reducto import Reducto

client = Reducto()

try:
    response = client.parse.run(
        input="https://pdfobject.com/pdf/sample.pdf",
    )
except reducto.APIConnectionError as e:
    print("Network connection error")
    print(e.__cause__)
except reducto.AuthenticationError as e:
    print("Invalid API key")
except reducto.RateLimitError as e:
    print("Rate limit exceeded")
except reducto.APIStatusError as e:
    print(f"API error: {e.status_code}")
    print(e.response)

See Also

Build docs developers (and LLMs) love