Skip to content

Add ReductoSageMaker, a client for an r-1 endpoint on SageMaker - #124

Merged
alvin-r merged 1 commit into
mainfrom
alvin/sagemaker-client
Oct 28, 2026
Merged

alvin-r merged 1 commit into
mainfrom
alvin/sagemaker-client

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds ReductoSageMaker and AsyncReductoSageMaker. They parse documents through a customer's own r-1 endpoint on Amazon SageMaker (the r-1 model package from AWS Marketplace). The client renders each page on the customer's machine and sends one page per request to the endpoint. Documents do not go to Reducto.

# pip install "reductoai[sagemaker]"
from reducto import ReductoSageMaker

client = ReductoSageMaker(endpoint_name="my-r1-endpoint", aws_region="us-east-2")
response = client.parse.run(input="contract.pdf", settings={"page_range": {"start": 1, "end": 20}})

What is in it

  • Inputs: PDF (with document_password), PNG, JPEG, TIFF (multi-frame), WebP, GIF, BMP. HEIC needs the heic extra.
  • Output: the same ParseResponse as the hosted API, with one chunk per page.
  • Options: only settings.page_range and settings.document_password. Every other option, and extract, split, edit, pipeline, and upload, raise UnsupportedOnProviderError, which points to the hosted Reducto API.
  • Pages: the client renders each page to fit the endpoint's documented default image size (3,145,728 pixels), up to 300 DPI. It sends PNG, and JPEG only when a page is over the 6 MB InvokeEndpoint limit.
  • Retries: 429 and 5xx other than 504, two times with jitter. No retry on 504, timeouts, or other 4xx.
  • Failed pages: if any page fails, parse.run raises PageParseError after the other pages finish. The error lists the failed pages, holds the pages that succeeded, and gives the page_range to retry them.
  • Concurrency: max_concurrency limits the pages in flight for each client. The async client has the same API.
  • Dependencies: only in the new sagemaker and heic extras (also on the reducto alias package). import reducto loads none of them.

Layout

  • reducto/lib/_page_parse/: private, provider-neutral code (documents, render, runner, response, a small PageTransport protocol, and a client base).
  • reducto/lib/sagemaker/: the AWS parts only (session, invoke_endpoint transport, public classes).
  • examples/sagemaker/: docs and an example. The root README does not change.

Another provider needs only a transport and a small client on the same base.

Tests

  • ./scripts/lint: ruff, pyright, and mypy pass.
  • ./scripts/test: passes on pydantic v2 and v1. The new tests use botocore stubs and a local HTTP server, with no network.
  • Checked against a live r-1 endpoint on SageMaker: PDFs, scans, rotated pages, password PDFs, multi-frame TIFF, HEIC, page_range, async cancel, shared-client concurrency, and the failed-page path.

🤖 Generated with Claude Code

Link to Devin session: https://app.devin.ai/sessions/e9ecfef02d294823abcbc9008adefce8
Open in Devin Desktop: https://app.devin.ai/desktop/session/e9ecfef02d294823abcbc9008adefce8?variant=devin
Requested by: @alvin-r


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

- ReductoSageMaker and AsyncReductoSageMaker parse a PDF or an image
  through an r-1 endpoint on Amazon SageMaker, one page per request,
  and return a ParseResponse with one chunk per page.
- Install with: pip install "reductoai[sagemaker]". HEIC images need
  the heic extra. import reducto loads no extra dependency.
- The client renders each page to fit the endpoint's documented default
  image size (3,145,728 pixels), up to 300 DPI, and sends PNG (JPEG
  only when a page is over the 6 MB InvokeEndpoint limit).
- Retries: 429 and 5xx other than 504, two times with jitter.
- If any page fails, parse.run raises PageParseError. The error lists
  the failed pages, holds the pages that succeeded, and gives the
  page_range to retry the failed pages.
- Only settings.page_range and settings.document_password are
  supported. Other options, and extract, split, edit, pipeline, and
  upload, raise UnsupportedOnProviderError: use the hosted Reducto API.
- max_concurrency limits the pages in flight for each client.
- The provider-neutral code is in reducto.lib._page_parse, so another
  provider needs only a transport and a small client.
- Docs and an example are in examples/sagemaker/.
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Original prompt from Alvin

Open a pull request in reductoai/reducto-python-sdk. Do not change any code, do not push any commit, and do not touch any other repository.

  • Head branch: alvin/sagemaker-client (already pushed). Base branch: main.
  • Title: Add ReductoSageMaker, a client for an r-1 endpoint on SageMaker
  • Body: use the text between the BODY markers exactly, with no additions.
  • Request a review from the GitHub user hewliyang.

BODY-START
#``# Summary

This PR adds ReductoSageMaker and AsyncReductoSageMaker. They parse documents through a customer's own r-1 endpoint on Amazon SageMaker (the r-1 model package from AWS Marketplace). The client renders each page on the customer's machine and sends one page per request to the endpoint. Documents do not go to Reducto.

`#` pip install "reductoai[sagemaker]"
from reducto import ReductoSageMaker

client = ReductoSageMaker(endpoint_name="my-r1-endpoint", aws_region="us-east-2")
response = client.parse.run(input="contract.pdf", settings={"page_range": {"start": 1, "end": 20}})

#``# What is in it

  • Inputs: PDF (with document_password), PNG, JPEG, TIFF (multi-frame), WebP, GIF, BMP. HEIC needs the heic extra.
  • Output: the same ParseResponse as the hosted API, with one chunk per page.
  • Options: only settings.page_range and settings.document_password. Every other option, and extract, split, edit, pipeline, and upload, raise UnsupportedOnProviderError, which points to the hosted Reducto API.
  • Pages: the client renders each page to fit the endpoint's documented default image size (3,145,728 pixels), up to 300 DPI. It sends PNG, and JPEG only when a page is over the 6 MB InvokeEndpoint limit.
  • Retries: 429 and 5xx other than 504, two times with jitter. No retry on 504, timeouts, or other 4xx.
  • Failed pages: if any page fails, parse.run raises PageParseError after the other pages finish. The error lists the failed pages, holds the pages that succeeded, and gives the page_range to... (1235 chars truncated...)

@hewliyang hewliyang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice work

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Devin is currently unreachable - the session may have died.

View session

@alvin-r

alvin-r commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

nice work

thanks bro

@alvin-r
alvin-r merged commit 0e92c31 into main Oct 28, 2026
8 checks passed
@hewliyang hewliyang mentioned this pull request Nov 4, 2026
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