---
title: "Graphs"
description: "REST endpoints for graphs. Bearer-auth required."
section: "API"
group: "REST"
order: 38
---

## POST /api/graph-definitions

Create graph definition

**Request body**

```json
{
  "workspaceId": "string",
  "name": "string",
  "slug": "string",
  "description?": "string"
}
```

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "name": "string",
  "slug": "string",
  "description": "string",
  "nodeDefinitions?": ["<...>"],
  "edgeDefinitions?": ["<...>"],
  "graphCount?": "number",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## PATCH /api/graph-definitions/{id}

Update graph definition

**Path parameters**

- `id` (required): The graph definition's prefixed ID (e.g. `gdf_...`).

**Request body**

```json
{
  "name?": "string",
  "description?": "string"
}
```

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "name": "string",
  "slug": "string",
  "description": "string",
  "nodeDefinitions?": ["<...>"],
  "edgeDefinitions?": ["<...>"],
  "graphCount?": "number",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## POST /api/graph-definitions/{id}/extract

Extract a graph from text content

**Path parameters**

- `id` (required): The graph definition's prefixed ID (e.g. `gdf_...`).

**Request body**

```json
{
  "content": "string",
  "name?": "string",
  "sourceId?": "string",
  "sourceType?": "file | run | manual",
  "persist?": "boolean"
}
```

**Response**

```json
{
  "nodes": [
    {
      "nodeDefinitionId": "string",
      "schemaName?": "string",
      "label": "string",
      "properties?": "any"
    }
  ],
  "edges": [
    {
      "edgeDefinitionId": "string",
      "sourceLabel": "string",
      "targetLabel": "string"
    }
  ],
  "definitionId": "string",
  "graphId?": "string"
}
```

## POST /api/graph-definitions/{id}/graphs

Create graph instance

**Path parameters**

- `id` (required): The graph definition's prefixed ID (e.g. `gdf_...`).

**Request body**

```json
{
  "name": "string",
  "sourceId?": "string",
  "sourceType?": "file | run | manual",
  "nodes?": [
    {
      "nodeDefinitionId": "<...>",
      "label": "<...>",
      "properties?": "<...>"
    }
  ],
  "edges?": [
    {
      "edgeDefinitionId": "<...>",
      "sourceLabel": "<...>",
      "targetLabel": "<...>",
      "label": "<...>",
      "properties?": "<...>"
    }
  ]
}
```

**Response**

```json
{
  "id": "string",
  "graphDefinitionId": "string",
  "name": "string",
  "sourceId": "string",
  "sourceType": "file | run | manual | ",
  "nodeCount?": "number",
  "edgeCount?": "number",
  "createdBy": "string",
  "createdAt": "string"
}
```

## POST /api/graph-edge-definitions

Add edge definition

Add an edge type to a graph definition. The parent graph definition is identified by `graphDefinitionId` in the body.

**Request body**

```json
{
  "graphDefinitionId": "string",
  "fromSchemaId": "string",
  "toSchemaId": "string",
  "schemaId?": "string",
  "description?": "string"
}
```

**Response**

```json
{
  "id": "string",
  "graphDefinitionId": "string",
  "fromSchemaId": "string",
  "toSchemaId": "string",
  "schemaId": "string",
  "description": "string",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## PATCH /api/graph-edge-definitions/{id}

Update edge definition

**Path parameters**

- `id` (required): The edge definition's prefixed ID (e.g. `grpedg_...`).

**Request body**

```json
{
  "schemaId?": "string",
  "description?": "string"
}
```

**Response**

```json
{
  "id": "string",
  "graphDefinitionId": "string",
  "fromSchemaId": "string",
  "toSchemaId": "string",
  "schemaId": "string",
  "description": "string",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## DELETE /api/graph-edge-definitions/{id}

Remove edge definition

**Path parameters**

- `id` (required): The edge definition's prefixed ID (e.g. `grpedg_...`).

**Response**

```json
{
  "success": "boolean"
}
```

## POST /api/graph-node-definitions

Add node definition

Add a node type to a graph definition. The parent graph definition is identified by `graphDefinitionId` in the body.

**Request body**

```json
{
  "graphDefinitionId": "string",
  "schemaId": "string",
  "description?": "string"
}
```

**Response**

```json
{
  "id": "string",
  "graphDefinitionId": "string",
  "schemaId": "string",
  "description": "string",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## PATCH /api/graph-node-definitions/{id}

Update node definition

**Path parameters**

- `id` (required): The node definition's prefixed ID (e.g. `grpnod_...`).

**Request body**

```json
{
  "description?": "string"
}
```

**Response**

```json
{
  "id": "string",
  "graphDefinitionId": "string",
  "schemaId": "string",
  "description": "string",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## DELETE /api/graph-node-definitions/{id}

Remove node definition

**Path parameters**

- `id` (required): The node definition's prefixed ID (e.g. `grpnod_...`).

**Response**

```json
{
  "success": "boolean"
}
```

## GET /api/graphs

List graph instances.

**Query parameters**

- `limit` (optional): Page size (1–100, default 100).
- `after` (optional): Keyset cursor — return the page after this row (next page).
- `before` (optional): Keyset cursor — return the page before this row (prev page).
- `ids` (optional): Comma-separated list of IDs. Narrows results to these IDs within the caller's accessible scope (does not bypass access checks).
- `filter` (optional): Nested filter expression (`<Entity>Filter`): AND/OR/NOT + per-field comparison operators + relation traversal. JSON-encoded on the query string.
- `orderBy` (optional): Multi-key sort (`<Entity>OrderBy[]`): array of `{ field: direction }` applied in order. Directions: asc/desc plus the four explicit nulls variants. JSON-encoded on the query string.
- `graph_definition_id` (optional): Filter graphs to a specific graph definition.
- `workspace_id` (optional): Filter graphs to definitions in this workspace. Without it, returns graphs across every workspace the caller can see.
- `include_deleted` (optional): Soft-deleted graph visibility. `false` (default) — active rows only. `true` — active plus soft-deleted. `only` — soft-deleted only (trash view).
- `source_type` (optional): Shorthand: filter where `sourceType` equals this value.
- `created_by` (optional): Shorthand: filter where `createdBy` equals this value.

**Response**

```json
{
  "data": [
    {
      "id": "<...>",
      "graphDefinitionId": "<...>",
      "name": "<...>",
      "sourceId": "<...>",
      "sourceType": "<...>",
      "nodeCount?": "<...>",
      "edgeCount?": "<...>",
      "createdBy": "<...>",
      "createdAt": "<...>"
    }
  ],
  "pageInfo": {
    "total": "number",
    "hasNextPage": "boolean",
    "hasPreviousPage": "boolean",
    "startCursor": "string",
    "endCursor": "string"
  }
}
```

## GET /api/graphs/{id}

Get a graph instance by ID.

**Path parameters**

- `id` (required): Graph instance to retrieve.

**Response**

```json
{
  "id": "string",
  "graphDefinitionId": "string",
  "name": "string",
  "sourceId": "string",
  "sourceType": "file | run | manual | ",
  "nodeCount?": "number",
  "edgeCount?": "number",
  "createdBy": "string",
  "createdAt": "string"
}
```

## DELETE /api/graphs/{id}

Soft-delete a graph instance.

**Path parameters**

- `id` (required): Graph instance to soft-delete.

**Response**

```json
{
  "success": "boolean"
}
```

## GET /api/graphs/{id}/data

Get graph with all nodes and edges

**Path parameters**

- `id` (required): The graph's prefixed ID (e.g. `gph_...`).

**Response**

```json
{
  "id": "string",
  "graphDefinitionId": "string",
  "name": "string",
  "sourceId": "string",
  "sourceType": "file | run | manual | ",
  "nodeCount?": "number",
  "edgeCount?": "number",
  "createdBy": "string",
  "createdAt": "string",
  "nodes": [
    {
      "id": "<...>",
      "graphId": "<...>",
      "nodeDefinitionId": "<...>",
      "properties?": "<...>",
      "label": "<...>",
      "createdAt": "<...>"
    }
  ],
  "edges": [
    {
      "id": "<...>",
      "graphId": "<...>",
      "edgeDefinitionId": "<...>",
      "sourceNodeId": "<...>",
      "targetNodeId": "<...>",
      "label": "<...>",
      "properties?": "<...>",
      "createdAt": "<...>"
    }
  ]
}
```

## DELETE /api/graphs/{id}/purge

Permanently delete a soft-deleted graph instance.

**Path parameters**

- `id` (required): Soft-deleted graph instance to permanently delete.

**Response**

```json
{
  "success": "boolean"
}
```

## POST /api/graphs/{id}/restore

Restore a soft-deleted graph instance.

**Path parameters**

- `id` (required): Soft-deleted graph instance to restore.

**Response**

```json
{
  "id": "string",
  "graphDefinitionId": "string",
  "name": "string",
  "sourceId": "string",
  "sourceType": "file | run | manual | ",
  "nodeCount?": "number",
  "edgeCount?": "number",
  "createdBy": "string",
  "createdAt": "string"
}
```
