> ## Documentation Index
> Fetch the complete documentation index at: https://docs.factagora.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Causality Graph

> 주어진 URL이나 파일에서 인과 관계를 분석해 구조화된 인과 그래프를 반환

URL 또는 업로드된 파일(PDF, Markdown)에서 인과 관계를 분석합니다. 노드(개념/이벤트)와 방향성을 가진 간선(인과 관계)을 반환하여 원인-결과 체인을 시각화하는 데 사용할 수 있습니다.

## 엔드포인트

| 메서드    | 경로                             | 입력                                |
| ------ | ------------------------------ | --------------------------------- |
| `POST` | `/api/v1/causality-graph`      | `url`을 포함한 JSON 본문                |
| `POST` | `/api/v1/causality-graph/file` | `file`을 포함한 `multipart/form-data` |

***

## POST /api/v1/causality-graph

### 요청 본문

<ParamField body="url" type="string" required>
  인과 관계를 추출할 페이지 또는 문서 URL.
</ParamField>

<ParamField body="language" type="string">
  추출된 노드 및 엣지 label의 언어 (예: `english`, `korean`). 노드 `id`는 그래프 무결성을 위해 영어/ASCII로 유지됩니다. 기본값: 영어.
</ParamField>

<ParamField body="limit" type="number" default="30">
  추출할 노드의 최대 개수. 범위: 1–100. 엣지 개수는 노드 개수에 따라 자연스럽게 제한됩니다.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.factagora.com/api/v1/causality-graph" \
    -H "Authorization: Bearer fag_your_api_key" \
    -H "Content-Type: application/json" \
    -d '{"url": "https://example.com/economic-analysis"}'
  ```
</RequestExample>

***

## POST /api/v1/causality-graph/file

### 요청 본문 (multipart/form-data)

<ParamField body="file" type="file" required>
  인과 관계를 추출할 PDF 또는 Markdown 파일.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.factagora.com/api/v1/causality-graph/file" \
    -H "Authorization: Bearer fag_your_api_key" \
    -F "file=@analysis.pdf"
  ```
</RequestExample>

***

## 응답

<ResponseField name="nodes" type="array">
  그래프 내 개념 또는 이벤트 노드 목록입니다.

  <Expandable title="Node fields">
    <ResponseField name="id" type="string">고유 노드 식별자</ResponseField>
    <ResponseField name="label" type="string">노드의 사람이 읽을 수 있는 라벨</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="edges" type="array">
  노드 간 방향성을 가진 인과 관계 목록입니다.

  <Expandable title="Edge fields">
    <ResponseField name="from" type="string">출발 노드 ID (원인)</ResponseField>
    <ResponseField name="to" type="string">도착 노드 ID (결과)</ResponseField>
    <ResponseField name="label" type="string">관계에 대한 선택적 설명</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="meta" type="object">
  <Expandable title="Meta fields">
    <ResponseField name="total_nodes" type="number">전체 노드 수</ResponseField>
    <ResponseField name="total_edges" type="number">전체 간선 수</ResponseField>
    <ResponseField name="executionTimeMs" type="number">응답 시간(밀리초)</ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json 200 theme={null}
  {
    "nodes": [
      { "id": "n1", "label": "Rising interest rates" },
      { "id": "n2", "label": "Lower consumer spending" },
      { "id": "n3", "label": "Reduced GDP growth" },
      { "id": "n4", "label": "Higher unemployment" }
    ],
    "edges": [
      { "from": "n1", "to": "n2", "label": "causes" },
      { "from": "n2", "to": "n3", "label": "leads to" },
      { "from": "n3", "to": "n4", "label": "leads to" }
    ],
    "meta": {
      "total_nodes": 4,
      "total_edges": 3,
      "executionTimeMs": 640
    }
  }
  ```
</ResponseExample>
