How habuskid/flightclaim works
Purpose and Entry Points
FlightClaim is an OKX.AI Agent Service Provider that evaluates EU261 flight-delay compensation eligibility and produces a draft claim explanation. Its operational entry point is the Next.js route handler at app/api/flightclaim/route.ts; clients submit a flight number and date via POST /api/flightclaim. Public informational pages are rooted at app/page.tsx, with supporting documentation and policy pages under app/docs/page.tsx and app/how-it-works/page.tsx.
API Orchestration Boundary
app/api/flightclaim/route.ts is the backend composition layer. It is responsible for accepting the marketplace-facing request, enforcing payment and rate-limit gates, retrieving flight facts, invoking eligibility logic, generating the explanatory letter, and returning the structured JSON result. This route is the principal boundary between untrusted client input and internal/domain integrations.
Payment and Access Controls
The request pipeline begins with x402/OKX payment validation and then rate limiting backed by Upstash Redis, as described by the service contract. Payment-specific integration is isolated in lib/okx-payment.ts, allowing the API route to reject unpaid requests with HTTP 402 before spending telemetry or inference capacity. Required OKX credentials, payment destination, and price are environment-configured through .env.example.
Flight Telemetry Acquisition
lib/aviationstack-client.ts encapsulates AviationStack API access for live or historical flight telemetry. The API layer should consume normalized flight data from this client rather than coupling domain logic to the external provider’s payloads. AviationStack credentials, base URL, and monthly usage limit form an external-service and cost-control boundary.
EU261 Decision Engine
lib/regulation-engine.ts contains deterministic EU Regulation 261/2004 eligibility and compensation logic. It combines flight status/timing facts with route distance and applies thresholds such as delay duration and compensation bands. Supporting route-distance calculation resides in lib/distance-calculator.ts, while airport reference data is maintained in lib/data/airports.json. Domain request, telemetry, verdict, and response shapes are centralized in lib/types.ts.
Claim Explanation Generation
After the deterministic verdict is produced, lib/cysic-client.ts calls Cysic inference to draft a human-readable claim letter/explanation grounded in the verdict and telemetry. This is deliberately downstream of the regulation engine: AI augments presentation, not legal eligibility determination. Cysic API credentials and endpoint are independently configured, keeping inference failure/cost concerns separate from core rule evaluation.
Runtime and Delivery Surface
The application runs on Next.js 16 with React 19 and TypeScript. Server behavior is centered on the App Router API handler in app/api/flightclaim/route.ts; the React pages are primarily a documentation/marketing surface rather than the core agent workflow. Shared global styling and application shell are in app/layout.tsx and app/globals.css. External dependencies materially include AviationStack, Cysic, OKX/x402 payment infrastructure, and Upstash Redis.
Main entry points: route.ts Flight claim endpoint · aviationstack-client.ts AviationStack client · .env.example Service configuration · regulation-engine.ts EU261 decision engine
Components 17
Public Surface
- Marketing page
app/page.tsx - Docs page
app/docs/page.tsx - How it works page
app/how-it-works/page.tsx - App shell and styles
app/layout.tsx
Agent API
- Flight claim endpoint · POST /api/flightclaim orchestration boundary.
app/api/flightclaim/route.ts - OKX payment validation · Rejects unpaid requests before telemetry or inference work.
lib/okx-payment.ts - Rate limiting
- AviationStack client · Normalizes provider flight data for the API layer.
lib/aviationstack-client.ts - Cysic claim generator · Drafts an explanation from the verdict and telemetry.
lib/cysic-client.ts - Service configuration · Contains payment, telemetry, and inference credentials and limits.
.env.example
Eligibility Domain
- EU261 decision engine · Determines eligibility and compensation independently of AI.
lib/regulation-engine.ts - Route distance calculator
lib/distance-calculator.ts - Airport reference data
lib/data/airports.json - Domain contracts · Request, telemetry, verdict, and response shapes.
lib/types.ts
External Services
- Upstash Redis
- AviationStack
- Cysic inference
Connections 19
- Marketing page → App shell and styles: renders in
- Docs page → App shell and styles: renders in
- How it works page → App shell and styles: renders in
- Flight claim endpoint → OKX payment validation: validates payment
- Flight claim endpoint → Rate limiting: enforces limit
- Rate limiting → Upstash Redis: uses
- Flight claim endpoint → AviationStack client: retrieves flight facts
- AviationStack client → AviationStack: queries
- Flight claim endpoint → EU261 decision engine: evaluates eligibility
- EU261 decision engine → Route distance calculator: calculates route distance
- Route distance calculator → Airport reference data: reads airports
- Flight claim endpoint → Cysic claim generator: generates explanation
- Cysic claim generator → Cysic inference: invokes
- EU261 decision engine → Domain contracts: produces verdict
- AviationStack client → Domain contracts: normalizes telemetry
- Flight claim endpoint → Domain contracts: returns response
- Service configuration → OKX payment validation: configures
- Service configuration → AviationStack client: configures
- Service configuration → Cysic claim generator: configures