OpenAPI lifecycle guard and MCP sidecar for policy-driven API orchestration.
OpenAPI lifecycle guard and an MCP sidecar for policy-driven API orchestration. The project describes APIs with OpenAPI, then uses x-openapi-flow to turn those definitions into executable workflows for developers and AI agents, aiming to run workflows without bespoke client or orchestration code.
π οΈ Key Features
OpenAPI-driven workflow execution
x-openapi-flow for orchestration logic
Policy-driven API orchestration
Lifecycle guard via an MCP sidecar
π Use Cases
Execute API workflows defined in openapi.x.json
Automate API orchestration for developers
Support AI agents with executable workflow definitions
β‘ Developer Benefits
Avoid custom clients and orchestration logic
Define workflows declaratively using OpenAPI extensions
β οΈ Limitations
Server details beyond orchestration and lifecycle guarding are not provided
Tooling scope and configuration options are not described in the available excerpt
OpenAPI describes APIs. x-openapi-flow turns them into executable workflows β for developers and AI agents.
Define your API workflows in openapi.x.json and execute them without writing custom clients or orchestration logic
npm total downloads
π 2,100+ downloads in the first 3 weeks!
β‘ Get started in seconds
code
npx x-openapi-flow init --suggest-transitions
This generates an openapi.x.json file where you can declaratively define how your API should be executed β not just described.
See your API lifecycle come alive from your OpenAPI spec, with one simple command
Validate, document, and generate flow-aware SDKs automatically.
What is this?
x-openapi-flow extends your OpenAPI specification with a workflow layer.
openapi.json β describes your API
openapi.x.json β describes how to use it (flows)
Instead of writing imperative code to orchestrate API calls, you define workflows declaratively and run them anywhere.
x-openapi-flow adds a declarative state machine to your OpenAPI spec.
Model resource lifecycles, enforce valid transitions, and generate flow-aware artifacts for documentation, SDKs, and automation.
π Example
Define stateful workflows and lifecycle transitions directly inside your OpenAPI operations:
json
{"operationId":"createOrder","x-openapi-flow":{"version":"1.0","id":"create-order","current_state":"created","description":"Creates an order and starts the lifecycle","transitions":[{"transition_id":"order-created-to-paid","trigger_type":"synchronous","condition":"Payment is confirmed","decision_rule":"payOrder:response.200.body.payment_status == 'approved'","target_state":"paid","next_operation_id":"payOrder","operation_role":"mutate","prerequisite_operation_ids":["createOrder"],"evidence_refs":["payOrder:response.200.body.payment_status"],"propagated_field_refs":["createOrder:response.201.body.order_id"],"failure_paths":[{"reason":"Payment denied","target_state":"payment_failed","next_operation_id":"getOrder"}]}]}}
This flow defines an order lifecycle directly inside your OpenAPI:
Starts in the created state
Transitions to paid when payment is confirmed
Supports both synchronous and polling-based transitions
Propagates data between operations automatically
Can include explicit decision/evidence and failure-path metadata for AI-guided orchestration
Instead of manually orchestrating API calls, the workflow is fully described alongside your API specification.
Why This Exists
Building APIs is cheap. Building complex, multi-step APIs that teams actually use correctly is hard.
Teams face recurring problems:
π Manual documentation is brittle β OpenAPI specs are static, often out of sync with real workflows
π€ AI agents can hallucinate β LLMs and code-generating agents may produce invalid calls if workflows are unclear or undocumented
π€― Workflows are confusing β multi-step operations are hard to track for humans and AI agents
β οΈ Invalid calls slip through β developers make mistakes because lifecycle rules arenβt enforced
β±οΈ Integration slows down β SDKs, Postman collections, and docs need constant manual updates
π‘οΈ Hard to prevent errors in production β without explicit lifecycle rules, invalid operations can reach live systems, causing outages or inconsistencies
x-openapi-flow exists to solve these pains: it makes lifecycles explicit, validates transitions automatically, and generates flow-aware docs and SDKs β so teams move faster, make fewer mistakes, and ship confident integrations.
What This Enables
Turn your OpenAPI spec into a single source of truth for API behavior:
Export a dense, non-prose flow contract for coding agents (export-llm-flows) β or call it directly as an MCP tool β so an agent like Claude Code knows the exact call order, decision rules, and field refs to implement an integration, without re-deriving them from human docs
Quick Start (without OpenAPI file)
Start in 2 Minutes (Online Playground)
Prefer no local setup? Open the minimal runtime-guard demo directly in your browser:
This visualization makes your API workflow explicit, easy to communicate, and ready for documentation or demos.
Generate Flow-Aware SDKs
Create a TypeScript or Python SDK that respects your APIβs lifecycle and transition rules, following best practices seen in leading companies like Stripe and Adyen:
Orchestrator by model: each resource exposes methods that enforce valid transitions
Chainable API calls: perform sequences naturally and safely
{"error":{"code":"INVALID_STATE_TRANSITION","message":"Blocked invalid transition for operation 'capturePayment'. Current state 'CREATED' cannot transition to this operation.","operation_id":"capturePayment","current_state":"CREATED","allowed_from_states":["AUTHORIZED"],"resource_id":"pay_123"}}
All adapters implement getCurrentState, setState, deleteState and forGuard() β a convenience method that returns the exact shape expected by the guard options.
Observability Hooks (Metrics/Audit)
You can instrument runtime decisions with onDecision to feed Prometheus, logs, or tracing.
x-openapi-flow is ideal for teams and organizations that want clear, enforceable API workflows:
API-first organizations β maintain a single source of truth for API behavior
Teams building AI agents β provide AI-friendly contracts and enforce correct API usage, so agents can safely call endpoints in the right order without guessing or violating workflow rules
API platform teams β ensure consistent lifecycle rules across endpoints
Companies with complex API workflows β reduce errors and ambiguity in multi-step processes
SDK teams β generate flow-aware SDKs that guide developers
Why x-openapi-flow?
See how x-openapi-flow extends OpenAPI to make your API workflows explicit, enforceable, and actionable:
Capability
OpenAPI
x-openapi-flow
Endpoint contracts
β Yes
β Yes (fully compatible, extended)
Lifecycle states
β No
β Yes β define states for each resource
Transition validation
β No
β Yes β catch invalid calls before runtime
Flow diagrams
β No
β Yes β generate visual lifecycle graphs
Usage guidance (next valid actions)
Limited/manual
β Built-in via lifecycle metadata β guides developers and AI agents
How does it compare to OpenAPI Workflows (Arazzo) and AsyncAPI?
Dimension
x-openapi-flow
OpenAPI Workflows (Arazzo)
AsyncAPI
Primary focus
Resource lifecycle states & runtime enforcement
Multi-step API workflows (orchestration scripts)
Event-driven / async messaging APIs
Lifecycle states
β Explicit states per resource
β No state model
β No state model
Runtime enforcement
β Express/Fastify/Hono middleware (409 on invalid transitions)
In short: use x-openapi-flow when you need enforceable, stateful API lifecycles that go beyond documentation into runtime safety, SDK generation, and AI-ready contracts. Use Arazzo for scripting multi-step HTTP journeys. Use AsyncAPI for documenting event/message-driven systems.
Integration Demos
Explore how x-openapi-flow integrates with popular API tools, making lifecycles and flows explicit for documentation and testing.
Swagger UI β Visualize Flows in Your Docs
bash
cd example/swagger-ui
npm install
npm run apply
npm start
Lifecycle panel shows valid states and transitions
Detailed view of transitions per operation
Redoc β Flow-Aware Documentation
bash
cd example/redoc
npm install
npm run apply
npm run generate
Auto-generated lifecycle diagrams make documentation clear and consistent
Postman β Organized API Collections
bash
cd example/postman
npm install
npm run apply
npm run generate
cd example/insomnia
npm install
npm run apply
npm run generate
Requests are pre-organized according to lifecycle transitions
CLI Reference β Common Commands
Use x-openapi-flow from the command line to manage, validate, visualize, and generate SDKs/docs for your API workflows.
General
bash
npx x-openapi-flow help [command] # show help for a specific command
npx x-openapi-flow --help# general help
npx x-openapi-flow version # show version
npx x-openapi-flow doctor [--config path] # check setup and config
npx x-openapi-flow completion [bash|zsh] # enable shell autocompletion
npx x-openapi-flow quickstart [--dir path] [--runtime express|fastify] [--force] # scaffold runnable onboarding project
This package wraps the official runtime-guard helpers and exposes a NestJS-first API.
Release automation for this package uses dedicated tags in the format nestjs-v<version>
(example: nestjs-v0.1.1) so it does not conflict with x-openapi-flow tags.
Version History β CHANGELOG.md
Review the full version history and past updates
Release Notes β GitHub Release v1.7.0
See detailed notes for the latest release, including new features and fixes
Documentation Language Policy
To ensure clarity and accessibility for the global developer community, all project documentation should be written in English. This helps contributors, users, and AI agents understand and use x-openapi-flow consistently.