# Graph Algorithms – Topological Sort (Kahn with Parallel Layers)

> Graph Algorithms – Topological Sort (Kahn with Parallel Layers) is a paid API for AI agents from graph-algorithms.x402tookit.com, paid per call via x402, $0.02/call, status unknown (last checked 2026-11-02).

Computes a topological ordering of a directed graph using Kahn's algorithm, grouping nodes into parallel execution layers; if a cycle exists, returns the cycle's nodes instead.

## Facts

- Endpoint: GET https://graph-algorithms.x402tookit.com/topological-sort?utm_source=zero.xyz
- Price: $0.02/call
- Payment: x402
- Status: unknown
- Last checked: 2026-11-02
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/graph-algorithms-topological-sort-kahn-with-parallel-layers-25056efd
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_QWdlsLccWL-NuOiwsNgYD

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability graph-algorithms-topological-sort-kahn-with-parallel-layers-25056efd
```

Example prompt: I have these task dependencies — 'compile,link; link,test; build,compile; build,package' — can you give me a topological order and tell me which tasks can run in parallel?

## When to prefer this

Use this endpoint when you need to determine a valid execution order for nodes in a directed acyclic graph, especially when you also want to know which nodes can be processed in parallel (layers). It also doubles as a cycle detector for directed graphs — if a topological order cannot be computed, the cycle is reported. Prefer this over Tarjan/SCC endpoints when your primary goal is ordering rather than component membership, and over Floyd-Warshall or Dijkstra when you don't need shortest paths but just dependency ordering.

## Known failure modes

- Cycle detected — returns cycle node list instead of topological order
- Graph exceeds 200 nodes or 1000 edges — request rejected
- Edge string malformed or unparseable — parsing error returned
- Node names exceed 32 characters or contain invalid characters — rejected
- Query string exceeds 60000 characters — request rejected
- Network timeout or service unavailable — HTTP 5xx error
- Payment not completed — HTTP 402 response requiring USDC payment

## How this service works

Topological order of a directed graph (Kahn) with parallel layers; on a cycle returns the cycle's nodes.

## Output

Returns a flat topological order array of node names, a layers array grouping nodes that can execute in parallel (each layer is an array of node names), node count, edge count, critical path length, and an asOf timestamp. If the graph contains a cycle, returns the cycle's nodes instead of an order, along with a summary and reasons explaining the cycle detection.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "method"
   ],
   "properties": {
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "GET"
     ],
     "type": "string"
    },
    "queryParams": {
     "type": "object",
     "required": [
      "edges"
     ],
     "properties": {
      "edges": {
       "type": "string",
       "description": "Edges separated by ; or newline, each 'from,to' or 'from,to,weight' (default weight 1), or a JSON array of [from,to,weight]; up to 200 nodes, 1000 edges, 60000 characters; node names 1-32 characters of letters, digits, _ . : + -. Each edge 'a,b' means a must come before b (weights ignored)"
      },
      "nodes": {
       "type": "string",
       "description": "Optional extra node names (comma or space separated) so isolated nodes are counted; the total still counts toward the 200-node cap"
      }
     }
    }
   },
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "required": [
    "type"
   ],
   "properties": {
    "type": {
     "type": "string"
    },
    "example": {
     "type": "object",
     "properties": {
      "asOf": {
       "type": [
        "null",
        "string"
       ]
      },
      "cycle": {},
      "order": {
       "type": [
        "array",
        "null"
       ],
       "items": {
        "type": "string"
       }
      },
      "layers": {
       "type": [
        "array",
        "null"
       ],
       "items": {
        "type": "array",
        "items": {
         "type": "string"
        }
       }
      },
      "source": {
       "type": [
        "null",
        "string"
       ]
      },
      "reasons": {
       "type": [
        "array",
        "null"
       ],
       "items": {
        "type": "string"
       }
      },
      "summary": {
       "type": [
        "null",
        "string"
       ]
      },
      "verdict": {
       "type": [
        "null",
        "string"
       ]
      },
      "degraded": {
       "type": [
        "boolean",
        "null"
       ]
      },
      "edgeCount": {
       "type": [
        "null",
        "number"
       ]
      },
      "nodeCount": {
       "type": [
        "null",
        "number"
       ]
      },
      "disclaimer": {
       "type": [
        "null",
        "string"
       ]
      },
      "notCh
… (truncated)
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/graph-algorithms-topological-sort-kahn-with-parallel-layers-25056efd/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from graph-algorithms.x402tookit.com](https://www.zero.xyz/host/graph-algorithms.x402tookit.com/llms.txt)
