Skip to main content

Amazon Comprehend Medical pass-through

The /comprehendmedical/{operation} route forwards a Comprehend Medical operation, such as DetectEntitiesV2, DetectPHI or InferICD10CM, to AWS. The body goes unchanged to the AWS JSON API and the gateway signs it with SigV4 using its own AWS credentials, so callers need no AWS access. A second route at /comprehendmedical accepts requests from the AWS SDK, which names the operation in the X-Amz-Target header, so an SDK only needs its endpoint URL pointed at the gateway. Every call is checked against the virtual key and recorded with its cost.

A real-world scenario​

A clinical documentation team extracts medications and conditions from visit notes with Comprehend Medical. The notes pipeline runs on a vendor platform that cannot hold IAM credentials safely. It now calls /comprehendmedical/DetectEntitiesV2 on the gateway with a virtual key. The gateway's role signs the calls, the pipeline holds no AWS secret, and compliance can list every call by key on the Logs page.

Before you start​

The gateway needs AWS credentials and a region. Any AWS credential source works, including IAM roles and container credentials.

VariablePurpose
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEYStatic credentials, when no role is available.
AWS_REGION_NAMEThe region of the Comprehend Medical endpoint, such as us-east-1. AWS_REGION and AWS_DEFAULT_REGION are also read.

Steps​

  1. Run the gateway with AWS credentials and set AWS_REGION_NAME. There is no provider entry to add on the Models + Endpoints page for this route.

  2. Issue a virtual key on /ui/api-keys with + Create New Key, then Create Key.

  3. Call an operation through the gateway.

    curl -X POST http://localhost:4000/comprehendmedical/DetectEntitiesV2 \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"Text": "Patient takes 20mg lisinopril daily for hypertension."}'
  4. With the AWS SDK, set the Comprehend Medical endpoint URL to http://localhost:4000/comprehendmedical and send the virtual key as the Authorization bearer token.

  5. Open /ui/logs and click the newest row to see the request, the key and its cost.

Expected result​

AWS's own response, with its status code and headers.

{
"Entities": [{"Id": 0, "Text": "lisinopril", "Category": "MEDICATION", "Type": "GENERIC_NAME", "Score": 0.99, "BeginOffset": 20, "EndOffset": 30}],
"ModelVersion": "2.0.0"
}

The spend log row carries the key, team and user and the cost worked out from the bundled Comprehend Medical prices for the operation and the text length.

Errors​

StatusMessageWhat it means and how to fix it
401Authentication Error, Invalid proxy server token passedThe virtual key is missing, wrong, expired or blocked.
403Key/team denied access to passthrough route /comprehendmedical/...The key or team lists the route in denied_passthrough_routes. The message goes on with Matched <pattern> in denied_passthrough_routes, naming the pattern to remove from the key or team.
400AWS region not found. Set AWS_REGION_NAME in the proxy environment.No region is set. Set AWS_REGION_NAME.
400Request body must be a JSON object or 'stream' is not a Comprehend Medical request memberThe body is not a JSON object, or it carries a stream field. Send the operation's fields only.
400Expected an X-Amz-Target header of the form ComprehendMedical_20181030.<Operation>An SDK call to /comprehendmedical arrived without the target header. Use the AWS SDK or the /comprehendmedical/{operation} form.
Any otherAWS's own error bodyAWS refused the request. The message is returned unchanged.

Pass-through endpoints lists every built-in route. Amazon Transcribe pass-through and Bedrock pass-through use the same AWS credentials.