Amazon Comprehend Medical

Amazon Comprehend Medical

Amazon Comprehend Medical의 패스스루 엔드포인트를 소개할게요. 임상 텍스트에서 엔티티(entities), PHI(개인 건강 정보), 의료 온톨로지 링크를 감지할 수 있는 기능을 네이티브 AWS 형식 그대로(변환 없이) 호출할 수 있어요.

출처: 문서

본문

연결 대상 호스트는 다음과 같아요.

https://comprehendmedical.{aws_region_name}.amazonaws.com

프록시를 통한 주소는 이렇게 구성돼요.

LITELLM_PROXY_BASE_URL/comprehendmedical

빠른 시작 (Quick Start)

AWS 자격 증명을 환경 변수로 설정해요.

export AWS_ACCESS_KEY_ID=""
export AWS_SECRET_ACCESS_KEY=""
export AWS_REGION_NAME="us-east-1"

그다음 LiteLLM 프록시를 실행해요.

litellm
# RUNNING on http://0.0.0.0:4000

이제 Comprehend Medical 작업을 호출할 수 있어요. DetectEntitiesV2 호출 예시예요.

curl -X POST 'http://0.0.0.0:4000/comprehendmedical/DetectEntitiesV2' \
-H "Authorization: Bearer ***" \
-H 'Content-Type: application/json' \
-d '{"Text": "Patient is taking 40mg of atorvastatin daily for hyperlipidemia."}'

지원되는 작업(Operation)으로는 DetectEntitiesV2, DetectPHI, InferICD10CM, InferRxNorm, InferSNOMEDCT가 있어요. 전체 작업 목록은 Comprehend Medical API 작업 문서를 참고해 주세요.

AWS SDK (boto3)와 함께 사용하기

boto3 클라이언트의 endpoint_urlLITELLM_PROXY_BASE_URL/comprehendmedical로 바꾸면 돼요. 다만 X-Amz-Target 헤더를 사용하는 AWS SDK 호출은 LiteLLM 키를 전달하기 위해 x-litellm-api-key 헤더를 함께 보내야 해요.

import boto3
client = boto3.client(
    "comprehendmedical",
    region_name="us-east-1",
    endpoint_url="http://0.0.0.0:4000/comprehendmedical",
    aws_access_key_id="placeholder",
    aws_secret_access_key="placeholder",
)
client.meta.events.register(
    "before-send.comprehendmedical.*",
    lambda request, **kwargs: request.headers.__setitem__("x-litellm-api-key", "sk-<your-litellm-api-key>"),
)
response = client.detect_phi(Text="John Smith was admitted on 2026-08-01.")
print(response["Entities"])

위 예시처럼 x-litellm-api-key 헤더로 LiteLLM 키를 전달하면 AWS SDK 호출에서도 인증이 처리돼요.

비용 추적 (Cost Tracking)

비용 추적은 요청 본문의 Text 길이에 기반해 처리돼요. DetectEntitiesV2, DetectPHI, InferICD10CM, InferRxNorm, InferSNOMEDCT 작업이 기록되는 형식은 comprehendmedical/{Operation}이고, comprehendmedical 모델 단위로 추적됩니다.

더 알아보기 (Learn more)