Public API v1.0

GeenTu Law Chat API

보험 손해사정 판례·법령 AI 챗봇을 외부 사이트에서 인증 없이 바로 호출하세요. 법제처 OpenAPI 실시간 연동으로 환각 없는 답변을 제공합니다.

API 개요

GeenTu Law Chat API의 주요 특징과 사용 정보

🔓

인증 불필요

API Key 없이 URL 호출만으로 바로 사용 가능. CORS 전체 허용으로 모든 도메인에서 접근 가능합니다.

⚖️

법제처 실시간 연동

법제처 OpenAPI를 통해 실시간 법령·판례 데이터를 수집하여 AI 답변에 활용. 환각(Hallucination)을 방지합니다.

SSE + JSON 이중 지원

실시간 스트리밍(SSE)과 단건 JSON 응답을 모두 지원. 사용 환경에 맞게 선택 가능합니다.

💬

멀티턴 대화

session_id를 통해 이전 대화 맥락을 유지하며 연속 질문이 가능합니다. 최대 30턴 히스토리 관리.

ℹ️ 본 API는 정보 제공 목적이며 법률 자문이 아닙니다. 개별 사안의 적용은 전문가(손해사정사·변호사)의 판단이 필요합니다.

엔드포인트 요약

Method Endpoint 설명 응답 형식
POST /api/chat 채팅 (SSE 스트리밍) text/event-stream
POST /api/chat-sync 채팅 (JSON 단건 응답) application/json
POST /api/reset 세션 초기화 application/json
GET /api/health 상태 확인 application/json
⚠️ Rate Limit: IP당 분당 최대 10회 요청. 초과 시 429 응답 반환. 남용 방지를 위한 기본 제한입니다.

API 문서

각 엔드포인트의 상세 사양

POST /api/chat

보험 손해사정 관련 질문에 대한 AI 답변을 SSE(Server-Sent Events) 스트리밍으로 반환합니다. 실시간 타이핑 효과 구현에 적합합니다.

Request Body
필드타입필수설명
messagestring사용자 질문 내용
session_idstring세션 ID (멀티턴 대화용, 기본값: "default")
Response (SSE Stream)
SSE Events
// 답변 텍스트가 조각 단위로 스트리밍됩니다
data: {"type":"content","content":"## [1] 쟁점 정리\n"}
data: {"type":"content","content":"후유장해 보험금 청구에서..."}
// ... 계속 스트리밍 ...

// 완료 시 토큰 사용량 포함
data: {"type":"done","usage":{"prompt":1200,"completion":800,"total":2000}}

// 에러 발생 시
data: {"type":"error","error":"에러 메시지"}
POST /api/chat-sync

SSE 파싱이 어려운 환경(모바일 앱, 서버 to 서버)을 위한 단건 JSON 응답 채팅 엔드포인트입니다. 전체 답변이 완료된 후 한 번에 반환합니다.

Request Body
필드타입필수설명
messagestring사용자 질문 내용
session_idstring세션 ID (기본값: "default")
Response (JSON)
JSON
{
  "status": "ok",
  "reply": "## [1] 쟁점 정리\n고지의무 위반 시...",
  "usage": {
    "prompt": 1200,
    "completion": 800,
    "total": 2000
  },
  "session_id": "my_session_123",
  "grounding_sources": [
    "법제처 법령검색 API",
    "법제처 판례검색 API"
  ]
}
POST /api/reset

지정한 세션의 대화 히스토리를 초기화합니다.

Request / Response
JSON
// Request
{ "session_id": "my_session_123" }

// Response
{ "status": "ok", "message": "세션 'my_session_123'이 초기화되었습니다." }
GET /api/health

API 서비스 상태를 확인합니다. 모니터링 및 헬스체크에 사용하세요.

Response
JSON
{
  "status": "ok",
  "service": "GeenTu Law Chat API",
  "version": "1.0.0",
  "timestamp": "2026-07-13T20:00:00.000Z",
  "endpoints": [...]
}

에러 응답

HTTP 상태코드설명
400-message 필드 누락
405-허용되지 않는 HTTP Method
429RATE_LIMIT_EXCEEDED분당 요청 한도 초과
500-서버 내부 오류

코드 샘플

다양한 언어와 환경에서 API를 호출하는 예제

1. 채팅 — SSE 스트리밍 (/api/chat)

JavaScript (Fetch API)
const API_URL = 'https://api.greentu.io/api/chat';

async function sendChat(message, sessionId = 'default') {
  const response = await fetch(API_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ message, session_id: sessionId })
  });

  const reader = response.body.getReader();
  const decoder = new TextDecoder();
  let fullReply = '';

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;

    const chunk = decoder.decode(value, { stream: true });
    for (const line of chunk.split('\n')) {
      if (!line.startsWith('data: ')) continue;
      const data = JSON.parse(line.slice(6));

      if (data.type === 'content') {
        fullReply += data.content;
        console.log(data.content); // 실시간 출력
      } else if (data.type === 'done') {
        console.log('토큰 사용량:', data.usage);
      } else if (data.type === 'error') {
        console.error('에러:', data.error);
      }
    }
  }

  return fullReply;
}

// 사용 예시
sendChat('후유장해 보험금 청구 기준이 궁금합니다');
Python (requests + sseclient)
import requests
import json

API_URL = "https://api.greentu.io/api/chat"

def send_chat(message, session_id="default"):
    response = requests.post(
        API_URL,
        json={"message": message, "session_id": session_id},
        stream=True
    )

    full_reply = ""
    for line in response.iter_lines(decode_unicode=True):
        if not line or not line.startswith("data: "):
            continue
        data = json.loads(line[6:])

        if data["type"] == "content":
            full_reply += data["content"]
            print(data["content"], end="", flush=True)
        elif data["type"] == "done":
            print(f"\n\n토큰 사용량: {data['usage']}")
        elif data["type"] == "error":
            print(f"\n에러: {data['error']}")

    return full_reply

# 사용 예시
send_chat("고지의무 위반 시 보험사 해지권 제척기간은?")
cURL
curl -X POST https://api.greentu.io/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "후유장해 보험금 청구 기준", "session_id": "test_001"}'

2. 채팅 — JSON 단건 응답 (/api/chat-sync)

JavaScript
const response = await fetch('https://api.greentu.io/api/chat-sync', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    message: '자동차보험 손해사정 기준이 궁금합니다',
    session_id: 'my_session'
  })
});

const data = await response.json();
console.log(data.reply);           // AI 답변 전문
console.log(data.usage);           // 토큰 사용량
console.log(data.grounding_sources); // 활용 데이터 소스
Python
import requests

response = requests.post(
    "https://api.greentu.io/api/chat-sync",
    json={
        "message": "자동차보험 손해사정 기준이 궁금합니다",
        "session_id": "my_session"
    }
)

data = response.json()
print(data["reply"])             # AI 답변 전문
print(data["usage"])             # 토큰 사용량
print(data["grounding_sources"]) # 활용 데이터 소스
cURL
curl -X POST https://api.greentu.io/api/chat-sync \
  -H "Content-Type: application/json" \
  -d '{"message": "자동차보험 손해사정 기준", "session_id": "test_001"}'

3. 외부 사이트에 채팅 위젯 삽입하기

아래 코드를 복사하여 HTML 페이지 어디든 삽입하면, GeenTu 보험금 판례 도우미 채팅 위젯이 동작합니다.
HTML (완전한 삽입 위젯)
<!-- GeenTu Law Chat Widget -->
<div id="greentu-chat" style="max-width:600px;margin:20px auto;font-family:sans-serif">
  <div id="chat-messages" style="height:400px;overflow-y:auto;border:1px solid #e5e7eb;
    border-radius:12px;padding:16px;background:#f9fafb;margin-bottom:12px"></div>
  <form id="chat-form" style="display:flex;gap:8px">
    <input id="chat-input" type="text" placeholder="보험 분쟁 사안을 질문하세요..."
      style="flex:1;padding:12px;border:1px solid #d1d5db;border-radius:8px;font-size:14px">
    <button type="submit" style="padding:12px 24px;background:#3b82f6;color:#fff;
      border:none;border-radius:8px;font-weight:600;cursor:pointer">전송</button>
  </form>
</div>
<script>
(function() {
  const API = 'https://api.greentu.io/api/chat';
  const SID = 'widget_' + Date.now();
  const msgs = document.getElementById('chat-messages');
  const form = document.getElementById('chat-form');
  const input = document.getElementById('chat-input');

  form.addEventListener('submit', async (e) => {
    e.preventDefault();
    const q = input.value.trim();
    if (!q) return;
    addMsg('user', q);
    input.value = '';

    const res = await fetch(API, {
      method: 'POST',
      headers: {'Content-Type':'application/json'},
      body: JSON.stringify({message: q, session_id: SID})
    });

    const reader = res.body.getReader();
    const dec = new TextDecoder();
    const el = addMsg('bot', '');
    let reply = '';

    while(true) {
      const {done, value} = await reader.read();
      if(done) break;
      for(const line of dec.decode(value).split('\n')) {
        if(!line.startsWith('data: ')) continue;
        try {
          const d = JSON.parse(line.slice(6));
          if(d.type==='content') { reply+=d.content; el.textContent=reply; }
        } catch(e){}
      }
    }
  });

  function addMsg(role, text) {
    const d = document.createElement('div');
    d.style.cssText = `margin:8px 0;padding:10px 14px;border-radius:10px;max-width:85%;
      ${role==='user'?'margin-left:auto;background:#3b82f6;color:#fff'
      :'background:#e5e7eb;color:#1f2937'};white-space:pre-wrap;font-size:14px`;
    d.textContent = text;
    msgs.appendChild(d);
    msgs.scrollTop = msgs.scrollHeight;
    return d;
  }
})();
</script>

API 테스트 콘솔

브라우저에서 직접 API를 호출하여 응답을 확인하세요

Session: -
// 엔드포인트를 선택하고 메시지를 입력 후 전송하세요.
// SSE 스트리밍은 실시간으로 응답이 표시됩니다.

📝 마크다운 렌더링 미리보기