{"uid":"cap_7YhTEZQNsCUAa43eaw1e3","slug":"graph-algorithms-bellman-ford-shortest-paths-f6969ee1","name":"Graph Algorithms: Bellman-Ford Shortest Paths","description":"Bellman-Ford shortest paths with negative weights; reports a negative cycle reachable from the source.","url":"https://graph-algorithms.x402tookit.com/bellman-ford?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); with false any negative edge is itself a negative cycle"}}}},"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"]},"negativeCycle":{}}}}}}},"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_B8ZRW1q1_hvXu3-33qfY7","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 single-source shortest paths using the Bellman-Ford algorithm, supporting negative edge weights and detecting negative cycles reachable from the source.","exampleAgentPrompt":"Run a Bellman-Ford shortest path from node S to node T on this directed edge list: 'S,A,4; S,B,5; A,B,-3; B,T,2' — and let me know if there's a negative cycle reachable from S.","exampleUseCases":[{"title":"Arbitrage detection in currency graph","prompt":"I have a directed graph of currency exchange rates encoded as negative log weights — edges like 'USD,EUR,-0.15; EUR,GBP,0.05; GBP,USD,-0.02' with source USD. Run Bellman-Ford and tell me if there's a negative cycle reachable from USD that would signal an arbitrage opportunity."},{"title":"Cheapest route in road network with tolls and credits","prompt":"Find the shortest path from CityA to CityZ in this road network where some roads have negative weights due to rebates: 'CityA,CityB,3; CityB,CityC,-2; CityA,CityC,6; CityC,CityZ,1'. The graph is directed — give me the path, total distance, and hop count."},{"title":"Debt settlement minimum cost path","prompt":"I have a directed graph of debt obligations between people where some edges are negative (credits): 'Alice,Bob,5; Bob,Carol,-3; Carol,Dave,2; Alice,Dave,10'. Starting from Alice, run Bellman-Ford and find the cheapest way to reach Dave, and flag any negative cycles."}],"resultDescription":"Returns a structured object including: a verdict (e.g. 'negative cycle detected' or 'path found'), a summary string, the shortest path as an ordered list of node names (if a target is given), total distance, hop count, a map of distances from the source to all reachable nodes, edge and node counts, whether the graph is directed, and any reasons or warnings. If a negative cycle reachable from the source is detected, the verdict and reasons fields indicate this clearly.","failureModes":["Source node not present in edge list — returns error indicating source not found","Graph exceeds 200-node or 1000-edge limit — returns error with size constraints","Negative cycle detected reachable from source — returns verdict indicating negative cycle rather than distances","Malformed edge string (wrong format or invalid node names) — returns parse error","Target node specified but unreachable — returns null path and infinite or null distance","Edge weight parsing failure for non-numeric weights — returns validation error"],"whenToPreferThis":"Choose this endpoint over Dijkstra when your graph contains negative edge weights, since Dijkstra does not support them. Prefer this over Floyd-Warshall when you need single-source shortest paths (not all-pairs) or your graph has more than 100 nodes. Use this specifically when you need to detect negative cycles reachable from a given source node, such as arbitrage detection in financial graphs or constraint satisfaction problems. If you only need all-pairs shortest paths on a small graph, Floyd-Warshall may be more appropriate.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-02T12:31:08.473Z","isFirstParty":false,"canonicalSlug":"graph-algorithms-bellman-ford-shortest-paths-f6969ee1"}