{"uid":"cap_B9EjWyDnxdy38gRxg5F1v","slug":"graph-algorithms-dijkstra-shortest-path-7bc795ed","name":"Graph Algorithms: Dijkstra Shortest Path","description":"Dijkstra shortest path and distances from a source on a weighted edge list; negative weights point to /bellman-ford.","url":"https://graph-algorithms.x402tookit.com/shortest-path?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"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","source"],"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, _ . : + -"},"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"},"source":{"type":"string","description":"Start node name; must appear in edges"},"target":{"type":"string","description":"Optional end node; if given the path to it is returned"},"directed":{"type":"boolean","description":"true (default) edges one way; false treats each edge as two-way"}}}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","properties":{"asOf":{"type":["null","string"]},"hops":{"type":["null","number"]},"path":{"type":["array","null"],"items":{"type":"string"}},"source":{"type":["null","string"]},"target":{"type":["null","string"]},"reasons":{"type":["array","null"],"items":{"type":"string"}},"summary":{"type":["null","string"]},"verdict":{"type":["null","string"]},"degraded":{"type":["boolean","null"]},"directed":{"type":["boolean","null"]},"distance":{"type":["null","number"]},"distances":{"type":["null","object"],"properties":{"s":{"type":["null","number"]},"t":{"type":["null","number"]},"x":{"type":["null","number"]},"y":{"type":["null","number"]},"z":{"type":["null","number"]}}},"edgeCount":{"type":["null","number"]},"nodeCount":{"type":["null","number"]},"startNode":{"type":["null","string"]},"disclaimer":{"type":["null","string"]},"notChecked":{"type":["array","null"],"items":{"type":"string"}},"unreachable":{"type":["array","null"]},"reachableCount":{"type":["null","number"]}}}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.02","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.02/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_TzwVqFhw0lUN_e99vycEv","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.02","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Computes Dijkstra shortest path and distances from a source node on a weighted edge list, returning the optimal path and distances to all reachable nodes.","exampleAgentPrompt":"Find the shortest path from node 'A' to node 'F' in this directed weighted graph: A,B,4; A,C,2; B,D,3; C,D,1; D,F,5; C,E,8; E,F,2.","exampleUseCases":[{"title":"Network routing cost optimization","prompt":"I have a network topology with these weighted links: server1,router1,10; router1,router2,5; router2,server2,3; server1,router2,20 — find the cheapest path from server1 to server2."},{"title":"Dependency resolution ordering","prompt":"Given these package dependencies with install costs: core,utils,2; core,logging,1; utils,http,3; logging,http,1; http,app,4 — what's the lowest-cost dependency chain from core to app?"},{"title":"Game map pathfinding","prompt":"I have a game map with these tile connections and movement costs: start,forest,3; start,road,1; road,bridge,2; forest,bridge,4; bridge,castle,1; road,village,5; village,castle,2 — find the shortest path from start to castle."}],"resultDescription":"Returns the shortest path as an ordered list of node names, the total distance, hop count, source and target nodes, and a distances object mapping every reachable node to its distance from the source. Also includes graph metadata like node count and edge count.","failureModes":["Source node not found in edge list — returns error requiring source to appear in edges","Graph exceeds 200 nodes or 1000 edges — returns rejection with size limit error","Edge list malformed or unparseable — returns parse error","Negative edge weights present — endpoint redirects or advises use of /bellman-ford instead","Target node unreachable from source — returns null distance and path","Edge list exceeds 60000 character limit — returns error"],"whenToPreferThis":"Use this endpoint when you need single-source shortest paths or point-to-point routing on a graph with non-negative edge weights. It is faster than Floyd-Warshall for sparse graphs or when only one source is needed, and correct for all non-negative weight scenarios. Switch to Bellman-Ford (sibling endpoint) if negative weights are present, or Floyd-Warshall if all-pairs distances are needed.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-02T12:31:13.557Z","isFirstParty":false,"canonicalSlug":"graph-algorithms-dijkstra-shortest-path-7bc795ed"}