> ## 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

> Analyze cause-and-effect relationships from a given URL or file, and return a structured causality graph.

Analyze cause-and-effect relationships from a URL or uploaded file (PDF, Markdown). Returns nodes (concepts/events) and directed edges (causal relationships) that can be used to visualize cause-and-effect chains.

## Endpoints

| Method | Path                           | Input                             |
| ------ | ------------------------------ | --------------------------------- |
| `POST` | `/api/v1/causality-graph`      | JSON body with `url`              |
| `POST` | `/api/v1/causality-graph/file` | `multipart/form-data` with `file` |

***

## POST /api/v1/causality-graph

### Request Body

<ParamField body="url" type="string" required>
  URL of the page or document to extract causal relationships from.
</ParamField>

<ParamField body="language" type="string">
  Language for the extracted node and edge labels (e.g. `english`, `korean`). Node `id` values remain in English/ASCII for graph integrity. Defaults to English.
</ParamField>

<ParamField body="limit" type="number" default="30">
  Maximum number of nodes to extract. Range: 1–100. Edge count is naturally bounded by node count.
</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

### Request Body (multipart/form-data)

<ParamField body="file" type="file" required>
  PDF or Markdown file to extract causal relationships from.
</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>

***

## Response

<ResponseField name="nodes" type="array">
  List of concept or event nodes in the graph.

  <Expandable title="Node fields">
    <ResponseField name="id" type="string">Unique node identifier</ResponseField>
    <ResponseField name="label" type="string">Human-readable label for the node</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="edges" type="array">
  List of directed causal relationships between nodes.

  <Expandable title="Edge fields">
    <ResponseField name="from" type="string">Source node ID (cause)</ResponseField>
    <ResponseField name="to" type="string">Target node ID (effect)</ResponseField>
    <ResponseField name="label" type="string">Optional description of the relationship</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="meta" type="object">
  <Expandable title="Meta fields">
    <ResponseField name="total_nodes" type="number">Total number of nodes</ResponseField>
    <ResponseField name="total_edges" type="number">Total number of edges</ResponseField>
    <ResponseField name="executionTimeMs" type="number">Response time in milliseconds</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>
