API 개요
Potato의 HTTP API 레퍼런스 — 어노테이터 관리, 내보내기 실행, 진행 통계 조회, 외부 파이프라인 연동을 위한 관리자 엔드포인트를 다룹니다.
Potato는 맞춤 프런트엔드, 자동화 스크립트, 외부 시스템과의 연동을 위한 HTTP API 엔드포인트를 제공합니다.
개요
기본 URL
http://localhost:8000
인증
대부분의 엔드포인트는 로그인 엔드포인트를 통해 설정되고 쿠키로 유지되는 활성 세션을 필요로 합니다.
프로그래밍 방식 접근의 경우:
- 브라우저의 세션 쿠키를 사용합니다
- 자동 사용자 생성을 지원하는 디버그 모드를 사용합니다
- 로그인 흐름을 프로그래밍 방식으로 구현합니다
응답 형식
모든 API 엔드포인트는 JSON 응답을 반환합니다. 오류 응답에는 error 필드가 포함됩니다.
세션 관리
로그인
POST /auth
Content-Type: application/x-www-form-urlencoded
username=your_username&password=your_password세션 확인
GET /api/current_instance응답:
{
"instance_id": "item_001",
"current_index": 0,
"total_instances": 100
}로그아웃
POST /logout어노테이션 엔드포인트
현재 인스턴스 가져오기
GET /api/current_instance사용자의 현재 어노테이션 인스턴스에 대한 정보를 반환합니다.
인스턴스 콘텐츠 가져오기
GET /api/spans/{instance_id}텍스트 콘텐츠와 기존 span 어노테이션을 반환합니다.
응답:
{
"instance_id": "item_001",
"text": "The quick brown fox jumps over the lazy dog.",
"spans": [
{
"id": "span_123",
"schema": "entities",
"label": "ANIMAL",
"start": 16,
"end": 19,
"text": "fox",
"color": "#ff6b6b"
}
]
}어노테이션 가져오기
GET /get_annotations?instance_id={instance_id}특정 인스턴스의 모든 어노테이션을 반환합니다.
어노테이션 제출
POST /updateinstance
Content-Type: application/json
{
"instance_id": "item_001",
"annotations": {
"sentiment:positive": "1"
},
"span_annotations": [
{
"schema": "entities",
"name": "PERSON",
"start": 0,
"end": 5,
"value": "true"
}
]
}응답(성공):
{
"status": "success",
"processing_time_ms": 15
}응답(품질 관리 포함):
{
"status": "success",
"qc_result": {
"type": "gold_standard",
"correct": false,
"gold_label": {"sentiment": "positive"}
}
}인스턴스로 이동
POST /go_to
Content-Type: application/json
{"go_to": "item_005"}또는 동작으로 지정:
{"action": "next_instance"}스키마 정보
어노테이션 스키마 가져오기
GET /api/schemas레이블 색상 가져오기
GET /api/colors키워드 강조 가져오기
GET /api/keyword_highlights/{instance_id}관리자 API 엔드포인트
관리자 엔드포인트는 관리자 권한이 필요합니다.
상태 점검
GET /admin/health대시보드 개요
GET /admin/api/overview응답:
{
"total_items": 1000,
"total_annotations": 5000,
"total_users": 25,
"completion_rate": 0.45
}어노테이터 가져오기
GET /admin/api/annotators인스턴스 가져오기
GET /admin/api/instances?status=completed&limit=100구성 가져오기
GET /admin/api/config구성 업데이트
POST /admin/api/config
Content-Type: application/json
{"setting_name": "value"}품질 관리 API
품질 관리 지표
GET /admin/api/quality_control주의력 점검과 골드 스탠다드 통계를 반환합니다.
일치도 지표
GET /admin/api/agreement스키마별 Krippendorff 알파를 반환합니다.
AI 어시스턴트 API
AI 제안 가져오기
GET /get_ai_suggestion?instance_id={instance_id}AI 어시스턴트 도움말 가져오기
GET /api/ai_assistant?instance_id={instance_id}&schema={schema_name}모델 학습 API
v2.14.0의 새 기능
model_training.enabled: true이면 Potato는 학습 작업 26개를 등록하며, OpenAPI 명세에 모두 나옵니다. 관리자 경로는 /admin/training 아래에 있고 관리자 권한이 필요하며, 관리자 세션이나 X-API-Key 헤더로 접근합니다. 브라우저에서 보내는 POST와 DELETE 요청은 같은 출처에서 와야 합니다.
| 경로 | 용도 |
|---|---|
GET /admin/training | Training 페이지 |
GET /admin/training/api/trainers | 모든 트레이너와, 트레이너가 다루는 스키마 종류와 미디어, 트레이너의 라이선스, 설치 여부 |
GET /admin/training/api/schemas | 연구의 스키마와 각 스키마에 맞는 트레이너 |
GET /admin/training/api/status | 진행 중이거나 마지막인 실행과 진행률, 지표, 경고, 되쓰기 보고서, 대기열 |
GET /admin/training/api/runs | 실행 기록(?limit=, 기본값 50) |
POST /admin/training/api/runs | 실행 시작 |
POST /admin/training/api/runs/<run_id>/cancel | 진행 중인 실행이나 대기 중인 실행 취소 |
DELETE /admin/training/api/runs/<run_id>/predictions | 실행의 사전 레이블 회수 |
트레이너 하나와 스키마 목록으로 실행을 시작합니다.
curl -X POST -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
http://localhost:8000/admin/training/api/runs \
-d '{"trainer": "sklearn-text", "schemas": ["sentiment"]}'실행이 시작되면 응답은 200이고, 다른 실행 뒤에서 대기하면 queued: true와 함께 202입니다. 거부된 시작은 400, 409, 429를 반환하며 이유는 error에 있습니다. 원격 학습 에이전트는 /api/training 아래의 두 번째 경로 집합을 쓰며 Authorization: Bearer <token>으로 인증합니다. 모델 학습 설정에 모든 경로가 요청 본문과 상태 코드와 함께 나와 있습니다.
예시: 전체 어노테이션 흐름
import requests
BASE_URL = "http://localhost:8000"
session = requests.Session()
# 1. Login
session.post(f"{BASE_URL}/auth", data={
"username": "annotator1",
"password": "password123"
})
# 2. Get current instance
response = session.get(f"{BASE_URL}/api/current_instance")
instance_id = response.json()["instance_id"]
# 3. Get instance content
response = session.get(f"{BASE_URL}/api/spans/{instance_id}")
print(f"Text: {response.json()['text']}")
# 4. Submit annotation
session.post(f"{BASE_URL}/updateinstance", json={
"instance_id": instance_id,
"annotations": {"sentiment:positive": "1"}
})
# 5. Navigate to next instance
session.post(f"{BASE_URL}/go_to", json={"action": "next_instance"})예시: 관리자 모니터링
import requests
BASE_URL = "http://localhost:8000"
# Get overview
overview = requests.get(f"{BASE_URL}/admin/api/overview").json()
print(f"Progress: {overview['completion_rate']*100:.1f}%")
# Get agreement metrics
agreement = requests.get(f"{BASE_URL}/admin/api/agreement").json()
print(f"Agreement: alpha = {agreement['overall']['average_krippendorff_alpha']:.3f}")오류 응답
모든 엔드포인트는 오류 응답을 반환할 수 있습니다:
{"error": "Description of the error"}일반적인 HTTP 상태 코드:
400- 잘못된 요청(유효하지 않은 매개변수)401- 인증되지 않음(세션 없음)403- 접근 금지(권한 부족)404- 찾을 수 없음500- 내부 서버 오류
더 읽어보기
구현 세부 사항은 원본 문서를 참조하세요.