cd /news/large-language-models/build-receipt-extraction-api-using-a… · home › topics › large-language-models › article
[ARTICLE · art-182385] src=pub.towardsai.net ↗ pub= topic=large-language-models verified=true sentiment=↑ positive

Build Receipt Extraction API using Amazon SageMaker, Amazon ECS, vLLM and Google Gemma 4

A developer built an AI receipt extraction API that uses the open-weight Google Gemma 4 model served through vLLM 0.19.1 on Amazon SageMaker endpoints and Amazon ECS to generate structured output—store name, price and purchase date—from receipts with varying templates and date formats. The build required a SageMaker Endpoint quota increase for g6.2xlarge instances, which AWS accounts default to a quota of 0 for all g-series GPU instances, and the developer chose g6.2xlarge at $1.222 per hour in the Oregon (us-west-2) region over g6.xlarge ($1.1267), g5.xlarge ($1.408), g5.2xlarge ($1.515) and g7.2xlarge ($3.15).

recommendation

Request a SageMaker Endpoint quota increase for g6.2xlarge before deploying, since the default g-series GPU quota is 0; at $1.222/hr it costs $0.1 more than g6.xlarge for double the vCPU and memory.

more in playbook: Inference and self-hosting
by read9 min views2 publishedDec 5, 2026

When extracting store name, price and purchase date from receipts, I face various challenges such as different receipt structures or templates and formats.

Terms used for price may appear as total or grand total while purchase date formats can also be different — day/month/year or month/day/year. Then when extracting through manual entry such as typo during input the data and missed required data.

To fix all the challenges, I built a AI receipt extraction API using Google Gemma 4 — open-source (open-weight) AI model and vLLM — open-source AI inference & serving to generate structured output from every receipt.

SERVICE QUOTAS

AWS accounts get default quotas for every service. For example, in Amazon SageMaker, default quota for all g-series GPU instances (g5, g6, g7) is 0. This means you must submit a quota increase request.

If not requested, provisioning of a new instance is blocked and you receive an error message during endpoint creation process. However, a quota request may be approved, denied or partially approved.

Open Service Quotas to submit a request for a SageMaker Endpoint quota increase. Enter SageMaker then click View quotas.

Enter g6.2xlarge for endpoint, click bullet then click Request increase at account level.

Why g6.2xlarge? It is cheaper than similar instances (g5.2xlarge and g7.2xlarge) and only add $0.1 to get 2 times vCPU/GiB than g6.xlarge.

g6.xlarge — 4 vCPU/16 GiB — $1.1267

g6.2xlarge — 8 vCPU/32 GiB — $1.222

g5.xlarge — 4 vCPU/16 GiB — $1.408

g5.2xlarge — 8 vCPU/32 GiB — $1.515

g7.2xlarge — 8 vCPU/32 GiB — $3.15

This price is based on the Oregon (us-west-2) region. If you want to use another region, you can view SageMaker pricing on this website by select Real-time inference and select your region.

Enter number in Increase quota value. The number must be greater than the current quota. Then click Request.

Wait a few seconds and the request for this instance is automatically approved. This means you can now use SageMaker endpoint.

SAGEMAKER STUDIO

SageMaker Studio is a SageMaker feature that serves as a web-based integrated development environment (IDE). Open Amazon SageMaker then select Set up SageMaker Studio.

Wait a few seconds until SageMaker Studio to become available then click Open Studio that automatically opens a new tab. The SageMaker Studio interface appears as shown in this screenshot below. Click JupyterLab logo in the top-left corner then click Create JupyterLab space.

After the JupyterLab space has been created, click Run space then wait a few seconds until (click) Open JupyterLab button to become available that automatically opens a new tab.

Back to Amazon SageMaker console (not SageMaker Studio), click Domains then select QuickSetupDomain-. In this domain, click App configurations then select Enable Docker on this domain. Wait a few seconds and now you can pull the vLLM image and push it to Amazon ECR.

vLLM IMAGE

Back to JupyterLab, click Terminal then clone this repository in the JupyterLab terminal and all files are now available.

git clone https://github.com/budionosanai/google-gemma-sagemaker-vllm-fastapi-receipt-extraction.gitcd google-gemma-sagemaker-vllm-fastapi-receipt-extraction

Run this shell script in the vllm folder to pull and push the vLLM image to private ECR repository. This process takes a few minutes.

cd vllmchmod +x vllm-to-ecr.sh./vllm-to-ecr.sh

In this shell script, I am using the vLLM version 0.19.1-gpu-py312-cu129-ubuntu22.04-sagemaker-v1.0 — date pushed 7 months ago.

If you want to use the vLLM latest version, you can view vLLM on this website by select Image tags and sort them by Date pushed to finding the latest version then copy Image URI and replace SOURCE_IMAGE config with Image URI.

Open Amazon ECR then click Repositories under Private registry. vLLM image in the vllm-gemma-4 repository is now available. This means you can deploy vLLM image to SageMaker endpoint.

SAGEMAKER ENDPOINT

Run this command to install Terraform — infrastructure-as-code tool that means automatically provisioning of cloud resources through code of just a few lines.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"brew install gccbrew tap hashicorp/tapbrew install hashicorp/tap/terraformterraform --version

View all Terraform files in the terraform/sagemaker folder.

Run this Terraform command in the terraform/sagemaker folder to deploy Google Gemma 4 model on vLLM image to SageMaker endpoint.

cd ..cd terraformcd sagemakerterraform initterraform planterraform apply --auto-approve

Open Amazon SageMaker console (not SageMaker Studio), click Deployments & inference then select Endpoints. Wait a few minutes until SageMaker endpoint status becomes inservice. This means the SageMaker endpoint is ready to be used to serve requests.

RECEIPT EXTRACTION API IMAGE

View all files in the app folder. Execute this command to create a private ECR repository named receipt-extraction-gemma-4.

cd ..cd appaws ecr create-repository \    --repository-name "receipt-extraction-gemma-4" \    --image-scanning-configuration scanOnPush=false \    --image-tag-mutability MUTABLE \    --region "us-west-2" 2>/dev/null || echo "Repository already exists, skipping creation."

However, when want to build and push receipt extraction API image to the private ECR repository, an error message appears as shown in this screenshot below.

To fix this error, execute this command in the app folder to install SageMaker Docker Build — a CLI tool for building Docker images in SageMaker Studio using AWS CodeBuild.

pip install sagemaker-studio-image-build

Back to Amazon SageMaker console (not SageMaker Studio), click Domains then select QuickSetupDomain-. In this domain, click User profiles then select default- then click copy execution role for AWS IAM step as shown in this screenshot below.

Open AWS IAM to add permission policy for accessing AWS services. Click Roles under Access Management, then enter and select the name of execution role like this.

AmazonSageMaker-ExecutionRole-...

SageMaker Docker Build requires permissions policies to execute Docker image creation process using AWS CodeBuild and push the image to ECR such as:

Then permissions policies to create container orchestration using Amazon ECS based on AWS Fargate such as:

To add the permissions policies above, click Add permissions then select Attach policies. Copy every permission policy above, check boxes then click Add permissions and display Policy was successfully attached to role.

Click Trust relationships then select Edit trust policy. Replace JSON in Edit trust policy statement page with this JSON below then click Update policy.

{   "Version": "2012-10-17",   "Statement": [    {       "Effect": "Allow",       "Principal": {          "Service": "sagemaker.amazonaws.com"       },       "Action": "sts:AssumeRole"    },    {      "Effect": "Allow",      "Principal": {          "Service": "codebuild.amazonaws.com"      },      "Action": "sts:AssumeRole"     }   ]}

Back to JupyterLab, run this command in the app folder to build and push receipt extraction API image to the private ECR repository. This process takes a few minutes.

sm-docker build . --repository receipt-extraction-gemma-4:latest

Open Amazon ECR then click Repositories under Private registry. Receipt extraction API image in the receipt-extraction-gemma-4 repository is now available. This means you can deploy this API image to AWS Fargate on Amazon Elastic Container Service (ECS).

Amazon ECS is a container orchestration service used to build and run container-based applications using virtual machines (Amazon EC2) or serverless containers (AWS Fargate).

AMAZON ECS EXPRESS MODE

Amazon ECS Express Mode offers faster deployment with minimal configuration. This mode requires only an ECR image URI, an IAM execution role and an IAM infrastructure role while manages all infrastructure using AWS Fargate-based service.

I added an IAM task role to invoke the SageMaker endpoint. If this role is not attached, the task will fail.

I use a custom VPC to have control over the networking side. If this custom VPC is not used, ECS Express Mode will automatically use the default VPC.

View all Terraform files in the terraform/ecs folder. Run this Terraform command in the terraform/ecs folder to deploy receipt extraction API image to ECS Express Mode service.

cd ..cd terraformcd ecsterraform initterraform planterraform apply --auto-approve

Open Amazon ECS then click Clusters. Wait a few minutes until ECS Express Mode service become available as shown in this screenshot below. You can see the number of container instances is 0 EC2 that means this service using AWS Fargate (not through EC2) then click cluster name.

The receipt-extraction-gemma-4 service resources appears as shown in this screenshot below. The application URL is now available. Click target group and load balancer to view details.

A target group is considered healthy as long as it has at least one healthy target. A healthy target group means that the group can receiving traffic directed by a load balancer.

A load balancer receives requests from clients and forwards requests to a target group that is healthy.

This ECS Express Mode service are use receipt extraction API contaner image. Open VPC console then click Your VPC to make sure that your custom VPC is available.

Open https://re-...on.aws/health in your browser to make sure the API is healthy and return 200 OK.

Open https://re-...on.aws/docs in your browser to test the /predict API. Upload some sample photos from the photos folder then wait a few seconds to get the structured output.

Run this Terraform command in the terraform/ecs folder to delete the ECS Express Mode service resources.

terraform destroy --auto-approve

terraform destroy — delete cloud (AWS) resources based your Terraform files. If you do not include -auto-approve, you must enter yes every want to apply your Terraform files.

AMAZON ECS STANDARD MODE

Amazon ECS Standard Mode offers full control over deployment including VPC networking, load balancer, auto-scaling and more. In this mode, task definition and service must be created manually.

A task definition requires an IAM execution role, an IAM task role and an ECR image URI while a service requires that task definition, a launch type (FARGATE or EC2), a load balancer and a VPC networking.

View all Terraform files in the terraform/ecs-custom folder. Run this Terraform command in the terraform/ecs-custom folder to deploy receipt extraction API image to ECS standard mode service.

cd ..cd terraformcd ecs-customterraform initterraform planterraform apply --auto-approve

Open Amazon ECS then click Clusters. Wait a few minutes until ECS standard mode service become available.

You can see the number of container instances is 0 EC2 that means this service using AWS Fargate (not through EC2). Click cluster name then click service name as shown in this screenshot below.

In the health section, you can view load balancer target health include target group and load balancer. Click target group and load balancer to view details.

Open http://fastapi-alb-...elb.amazonaws.com/health in your browser to make sure the API is healthy and return 200 OK.

Open http://fastapi-alb-...elb.amazonaws.com/docs in your browser to test the /predict API. Upload some sample photos from the photos folder then wait a few seconds to get the structured output.

Run this Terraform command in the terraform/ecs-custom folder to delete ECS Standard Mode service resources.

terraform destroy --auto-approve

Run this Terraform command in the terraform/sagemaker folder to delete SageMaker endpoint resources.

terraform destroy --auto-approve

Run this command to delete the vLLM image and the receipt extraction API image from the private ECR repository.

aws ecr delete-repository --repository-name receipt-extraction-gemma-4 --force --region us-west-2aws ecr delete-repository --repository-name vllm-gemma-4 --force --region us-west-2

In SageMaker Studio JupyterLab, click Stop space and delete your SageMaker Studio domain.

Resources:

  1. Amazon SageMaker documentation

  2. Google Gemma 4 on vLLM documentation

  3. Google Gemma 4 model documentation

  4. Terraform for SageMaker endpoint documentation

  5. Amazon ECS documentation

  6. Terraform for ECS Express mode documentation

Thank you,

Budi.

Build Receipt Extraction API using Amazon SageMaker, Amazon ECS, vLLM and Google Gemma 4 was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

── more in #large-language-models 4 stories · sorted by recency
── more on @google gemma 4 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/build-receipt-extrac…] indexed:0 read:9min 2026-12-05 · —